• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

go-sql-driver / mysql / 23700483573
83%
master: 83%

Build:
Build:
LAST BUILD BRANCH: private-query-tracer
DEFAULT BRANCH: master
Ran 01 Apr 2026 08:10AM UTC
Jobs 32
Files 20
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

29 Mar 2026 02:55AM UTC coverage: 82.633% (+0.1%) from 82.508%
23700483573

Pull #1753

github

ljluestc
# feat: add QueryTracer interface for SQL statement tracing (#1716)

## Summary

Add a `QueryTracer` interface that allows users to trace SQL query execution for logging, metrics, or distributed tracing. This feature is inspired by the pgx driver's tracelog implementation.

## Motivation

Applications often need visibility into database query execution for:

- **Debugging**: Log slow queries and identify bottlenecks
- **Metrics**: Track query execution times, error rates, and throughput
- **Distributed Tracing**: Integrate with observability tools (OpenTelemetry, Jaeger, etc.) using context propagation
- **Compliance**: Audit logging for data access

## Implementation

### New Interface (tracer.go)

Defines the `QueryTracer` interface with two methods:

```go
type QueryTracer interface {
    TraceQueryStart(ctx context.Context, query string, args []driver.NamedValue) context.Context
    TraceQueryEnd(ctx context.Context, err error, duration time.Duration)
}
```

- `TraceQueryStart` is called before query execution with the query string and arguments, returning a context for span propagation
- `TraceQueryEnd` is called after query completion with the error and wall-clock duration

The `mysqlConn.traceQuery()` helper wraps query execution with automatic tracing. When no tracer is configured, overhead is a single nil check per query.

### Configuration (dsn.go)

- Added `tracer QueryTracer` field to `Config` struct
- Added `WithTracer(tracer QueryTracer)` functional option

### Instrumented Paths (connection.go, statement.go)

- `ExecContext`
- `QueryContext`
- `PrepareContext`
- `mysqlStmt.ExecContext`
- `mysqlStmt.QueryContext`

## Usage Example

```go
package main

import (
    "context"
    "database/sql"
    "fmt"
    "github.com/go-sql-driver/mysql"
)

type DebugTracer struct{}

func (t *DebugTracer) TraceQueryStart(ctx context.Context, query string, args []driver.NamedValue) context.Context {
    fmt.Printf("[QUERY START] %s | args: %v\n", query, ... (continued)
Pull Request #1753: feat: add QueryTracer interface for SQL statement tracing (#1716)

31 of 31 new or added lines in 3 files covered. (100.0%)

3345 of 4048 relevant lines covered (82.63%)

2384163.2 hits per line

Jobs
ID Job ID Ran Files Coverage
1 Linux-Go-1.24-DB-mariadb-11.4 - 23700483573.1 01 Apr 2026 08:10AM UTC 19
82.1
GitHub Action Run
2 Windows-Go-1.24-DB-mariadb-10.6 - 23700483573.2 01 Apr 2026 08:13AM UTC 19
81.69
GitHub Action Run
3 Windows-Go-1.24-DB-9.0 - 23700483573.3 01 Apr 2026 08:14AM UTC 19
81.72
GitHub Action Run
4 Linux-Go-1.24-DB-8.4 - 23700483573.4 01 Apr 2026 08:10AM UTC 19
82.15
GitHub Action Run
5 Linux-Go-1.24-DB-mariadb-10.6 - 23700483573.5 01 Apr 2026 08:11AM UTC 19
82.2
GitHub Action Run
6 Linux-Go-1.24-DB-mariadb-10.11 - 23700483573.6 01 Apr 2026 08:10AM UTC 19
82.25
GitHub Action Run
7 Linux-Go-1.22-DB-9.0 - 23700483573.7 01 Apr 2026 08:10AM UTC 19
82.08
GitHub Action Run
8 macOS-Go-1.24-DB-mariadb-11.2 - 23700483573.8 01 Apr 2026 08:10AM UTC 19
81.88
GitHub Action Run
9 Windows-Go-1.24-DB-mariadb-10.11 - 23700483573.9 01 Apr 2026 08:14AM UTC 19
81.79
GitHub Action Run
10 Windows-Go-1.24-DB-mariadb-11.4 - 23700483573.10 01 Apr 2026 08:11AM UTC 19
81.69
GitHub Action Run
11 Linux-Go-1.24-DB-8.0 - 23700483573.11 01 Apr 2026 08:10AM UTC 19
82.15
GitHub Action Run
12 Linux-Go-1.24-DB-5.7 - 23700483573.12 01 Apr 2026 08:10AM UTC 19
82.0
GitHub Action Run
13 macOS-Go-1.24-DB-8.4 - 23700483573.13 01 Apr 2026 08:10AM UTC 19
81.9
GitHub Action Run
14 macOS-Go-1.24-DB-9.0 - 23700483573.14 01 Apr 2026 08:12AM UTC 19
82.0
GitHub Action Run
15 Windows-Go-1.24-DB-8.4 - 23700483573.15 01 Apr 2026 08:12AM UTC 19
81.87
GitHub Action Run
16 Linux-Go-1.23-DB-9.0 - 23700483573.16 01 Apr 2026 08:10AM UTC 19
82.25
GitHub Action Run
17 macOS-Go-1.24-DB-mariadb-11.1 - 23700483573.17 01 Apr 2026 08:12AM UTC 19
81.98
GitHub Action Run
18 Linux-Go-1.24-DB-mariadb-11.1 - 23700483573.18 01 Apr 2026 08:10AM UTC 19
82.1
GitHub Action Run
19 Windows-Go-1.24-DB-mariadb-11.1 - 23700483573.19 01 Apr 2026 08:13AM UTC 19
81.74
GitHub Action Run
20 Linux-Go-1.24-DB-mariadb-11.2 - 23700483573.20 01 Apr 2026 08:10AM UTC 19
82.2
GitHub Action Run
21 Linux-Go-1.24-DB-mariadb-10.5 - 23700483573.21 01 Apr 2026 08:12AM UTC 19
82.03
GitHub Action Run
22 Windows-Go-1.24-DB-mariadb-11.2 - 23700483573.22 01 Apr 2026 08:14AM UTC 19
81.84
GitHub Action Run
23 macOS-Go-1.24-DB-mariadb-10.6 - 23700483573.23 01 Apr 2026 08:12AM UTC 19
82.08
GitHub Action Run
24 macOS-Go-1.24-DB-mariadb-11.4 - 23700483573.24 01 Apr 2026 08:10AM UTC 19
82.03
GitHub Action Run
25 Windows-Go-1.24-DB-8.0 - 23700483573.25 01 Apr 2026 08:12AM UTC 19
81.72
GitHub Action Run
26 macOS-Go-1.24-DB-5.7 - 23700483573.26 01 Apr 2026 08:12AM UTC 19
81.83
GitHub Action Run
27 macOS-Go-1.24-DB-mariadb-10.11 - 23700483573.27 01 Apr 2026 08:10AM UTC 19
81.98
GitHub Action Run
28 Windows-Go-1.24-DB-5.7 - 23700483573.28 01 Apr 2026 08:13AM UTC 19
81.64
GitHub Action Run
29 macOS-Go-1.24-DB-8.0 - 23700483573.29 01 Apr 2026 08:12AM UTC 19
81.8
GitHub Action Run
30 Windows-Go-1.24-DB-mariadb-10.5 - 23700483573.30 01 Apr 2026 08:13AM UTC 19
81.77
GitHub Action Run
31 Linux-Go-1.24-DB-9.0 - 23700483573.31 01 Apr 2026 08:10AM UTC 19
82.15
GitHub Action Run
32 macOS-Go-1.24-DB-mariadb-10.5 - 23700483573.32 01 Apr 2026 08:10AM UTC 19
82.0
GitHub Action Run
Source Files on build 23700483573
  • Tree
  • List 20
  • Changed 7
  • Source Changed 0
  • Coverage Changed 7
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Repo
  • Pull Request #1753
  • PR Base - master (#22184055321)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc