From 1fe4100d2422854aeeebe4e07ba0951b86aead7b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 24 Sep 2026 20:42:33 +0000 Subject: [PATCH] fix(deps): update module github.com/exaring/otelpgx to v0.12.0 --- go.mod | 2 +- go.sum | 2 + vendor/github.com/exaring/otelpgx/options.go | 61 +++++++++++-- vendor/github.com/exaring/otelpgx/tracer.go | 92 ++++++++++++-------- vendor/modules.txt | 2 +- 5 files changed, 110 insertions(+), 49 deletions(-) diff --git a/go.mod b/go.mod index c3a8c44f..78a2e4f6 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/coreos/go-oidc/v3 v3.21.0 github.com/envoyproxy/go-control-plane v0.14.0 github.com/envoyproxy/go-control-plane/envoy v1.39.0 - github.com/exaring/otelpgx v0.11.1 + github.com/exaring/otelpgx v0.12.0 github.com/goccy/go-yaml v1.19.2 github.com/gogo/protobuf v1.3.2 github.com/google/go-cmp v0.7.0 diff --git a/go.sum b/go.sum index b4c1ca90..eec0be72 100644 --- a/go.sum +++ b/go.sum @@ -200,6 +200,8 @@ github.com/envoyproxy/protoc-gen-validate v1.3.3 h1:MVQghNeW+LZcmXe7SY1V36Z+WFMD github.com/envoyproxy/protoc-gen-validate v1.3.3/go.mod h1:TsndJ/ngyIdQRhMcVVGDDHINPLWB7C82oDArY51KfB0= github.com/exaring/otelpgx v0.11.1 h1:pE79fIg/qh/Lpu00kvswFC5dKfqyJJhMJ4Y4N3w5Lj4= github.com/exaring/otelpgx v0.11.1/go.mod h1:3OojrUKhhy3lTbYIMBijP3YjMey/jo14eHAW5cXcUdk= +github.com/exaring/otelpgx v0.12.0 h1:K3NG2YUiYB384YWptKglk8gLDYek5YptMdm1b0G4pQM= +github.com/exaring/otelpgx v0.12.0/go.mod h1:3OojrUKhhy3lTbYIMBijP3YjMey/jo14eHAW5cXcUdk= github.com/felixge/httpsnoop v1.1.0 h1:3YtUj32ZZkqZtt3sZZsClsymw/QDuVfpNhoA31zeORc= github.com/felixge/httpsnoop v1.1.0/go.mod h1:Zqxgdd+1Rkcz8euOqdr7lqgCRJztwr5hp9vDSi5UZCE= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= diff --git a/vendor/github.com/exaring/otelpgx/options.go b/vendor/github.com/exaring/otelpgx/options.go index f987d4d4..d1859fee 100644 --- a/vendor/github.com/exaring/otelpgx/options.go +++ b/vendor/github.com/exaring/otelpgx/options.go @@ -62,12 +62,30 @@ func WithMeterAttributes(attrs ...attribute.KeyValue) Option { }) } -// WithTrimSQLInSpanName will use the SQL statement's first word as the span -// name. By default, the whole SQL statement is used as a span name, where -// applicable. +// Deprecated: This is now the default behavior; use [WithFullSQLInSpanName] to +// opt back into the previous behavior of using the whole SQL statement. +// +// WithTrimSQLInSpanName uses the SQL statement's first word (the operation +// name, e.g. "SELECT") as the span name. func WithTrimSQLInSpanName() Option { return optionFunc(func(cfg *tracerConfig) { - cfg.trimQuerySpanName = true + cfg.fullQuerySpanName = false + }) +} + +// WithFullSQLInSpanName uses the whole SQL statement as the span name. +// +// This is generally discouraged: the OpenTelemetry database span conventions +// recommend a low-cardinality span name, and redaction/masking rules are +// typically applied to the db.query.text attribute rather than the span name, +// so any sensitive data embedded in the statement can leak through the name. +// By default, the low-cardinality operation name (e.g. "SELECT") is used +// instead. +// +// See https://opentelemetry.io/docs/specs/semconv/db/database-spans/. +func WithFullSQLInSpanName() Option { + return optionFunc(func(cfg *tracerConfig) { + cfg.fullQuerySpanName = true }) } @@ -92,7 +110,9 @@ type SpanNameCtxFunc func(ctx context.Context, stmt string) string // a SQL statement. The function will be called with the SQL statement as a // parameter. // -// By default, the whole SQL statement is used as a span name, where applicable. +// By default, the low-cardinality operation name (e.g. "SELECT") is extracted +// from the SQL statement and used as the span name. This function also +// determines the value of the db.operation.name attribute. func WithSpanNameFunc(fn SpanNameFunc) Option { return WithSpanNameCtxFunc(func(_ context.Context, stmt string) string { return fn(stmt) @@ -103,21 +123,35 @@ func WithSpanNameFunc(fn SpanNameFunc) Option { // for a SQL statement. The function will be called with the context.Context and // SQL statement as a parameter. // -// By default, the whole SQL statement is used as a span name, where applicable. +// By default, the low-cardinality operation name (e.g. "SELECT") is extracted +// from the SQL statement and used as the span name. This function also +// determines the value of the db.operation.name attribute. func WithSpanNameCtxFunc(fn SpanNameCtxFunc) Option { return optionFunc(func(cfg *tracerConfig) { cfg.spanNameCtxFunc = fn }) } -// WithDisableQuerySpanNamePrefix will disable the default prefix for the span -// name. By default, the span name is prefixed with "batch query" or "query". +// Deprecated: Span names are no longer prefixed by default, so this is a no-op. +// Use [WithQuerySpanNamePrefix] to opt back into the previous prefixing +// behavior. +// +// WithDisableQuerySpanNamePrefix disables the prefix for the span name. func WithDisableQuerySpanNamePrefix() Option { return optionFunc(func(cfg *tracerConfig) { cfg.prefixQuerySpanName = false }) } +// WithQuerySpanNamePrefix prefixes the span name with the operation kind, i.e. +// "query ", "prepare " or "batch query ". By default no prefix is added so that +// span names follow the OpenTelemetry database span conventions. +func WithQuerySpanNamePrefix() Option { + return optionFunc(func(cfg *tracerConfig) { + cfg.prefixQuerySpanName = true + }) +} + // WithDisableConnectionDetailsInAttributes will disable logging the connection details. // in the span's attributes. func WithDisableConnectionDetailsInAttributes() Option { @@ -134,11 +168,20 @@ func WithDisableSQLStatementInAttributes() Option { }) } +// QueryParametersFilterFunc is a predicate that controls whether query parameters are recorded +// for a given SQL statement. Return true to record parameters, false to omit them. +type QueryParametersFilterFunc func(sql string) bool + // WithIncludeQueryParameters includes the SQL query parameters in the span attribute with key pgx.query.parameters. // This is implicitly disabled if WithDisableSQLStatementInAttributes is used. -func WithIncludeQueryParameters() Option { +// +// An optional filter can be provided to omit parameters for specific queries. +func WithIncludeQueryParameters(filter ...QueryParametersFilterFunc) Option { return optionFunc(func(cfg *tracerConfig) { cfg.includeParams = true + if len(filter) > 0 { + cfg.queryParamsFilter = filter[0] + } }) } diff --git a/vendor/github.com/exaring/otelpgx/tracer.go b/vendor/github.com/exaring/otelpgx/tracer.go index 9b2e9bd6..31b4bb65 100644 --- a/vendor/github.com/exaring/otelpgx/tracer.go +++ b/vendor/github.com/exaring/otelpgx/tracer.go @@ -17,7 +17,7 @@ import ( "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/metric" semconv "go.opentelemetry.io/otel/semconv/v1.40.0" - dbconv "go.opentelemetry.io/otel/semconv/v1.40.0/dbconv" + "go.opentelemetry.io/otel/semconv/v1.40.0/dbconv" "go.opentelemetry.io/otel/trace" ) @@ -75,12 +75,13 @@ type Tracer struct { operationDuration dbconv.ClientOperationDuration operationErrors metric.Int64Counter - trimQuerySpanName bool + fullQuerySpanName bool spanNameCtxFunc SpanNameCtxFunc prefixQuerySpanName bool logSQLStatement bool logConnectionDetails bool includeParams bool + queryParamsFilter QueryParametersFilterFunc disableAcquireTracer bool } @@ -91,12 +92,13 @@ type tracerConfig struct { tracerAttrs []attribute.KeyValue meterAttrs []attribute.KeyValue - trimQuerySpanName bool + fullQuerySpanName bool spanNameCtxFunc SpanNameCtxFunc prefixQuerySpanName bool logSQLStatement bool logConnectionDetails bool includeParams bool + queryParamsFilter QueryParametersFilterFunc disableAcquireTracer bool } @@ -111,9 +113,9 @@ func NewTracer(opts ...Option) *Tracer { meterAttrs: []attribute.KeyValue{ semconv.DBSystemNamePostgreSQL, }, - trimQuerySpanName: false, + fullQuerySpanName: false, spanNameCtxFunc: defaultSpanNameCtxFunc, - prefixQuerySpanName: true, + prefixQuerySpanName: false, logSQLStatement: true, logConnectionDetails: true, includeParams: false, @@ -141,12 +143,13 @@ func NewTracer(opts ...Option) *Tracer { }, tracerAttrs: cfg.tracerAttrs, meterAttrs: cfg.meterAttrs, - trimQuerySpanName: cfg.trimQuerySpanName, + fullQuerySpanName: cfg.fullQuerySpanName, spanNameCtxFunc: cfg.spanNameCtxFunc, prefixQuerySpanName: cfg.prefixQuerySpanName, logSQLStatement: cfg.logSQLStatement, logConnectionDetails: cfg.logConnectionDetails, includeParams: cfg.includeParams, + queryParamsFilter: cfg.queryParamsFilter, disableAcquireTracer: cfg.disableAcquireTracer, } @@ -161,7 +164,12 @@ func NewTracer(opts ...Option) *Tracer { func (t *Tracer) createMetrics() { var err error - t.operationDuration, err = dbconv.NewClientOperationDuration(t.meter) + t.operationDuration, err = dbconv.NewClientOperationDuration( + t.meter, + metric.WithExplicitBucketBoundaries( + 0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10, + ), + ) if err != nil { otel.Handle(err) } @@ -262,13 +270,15 @@ func (t *Tracer) TraceQueryStart(ctx context.Context, conn *pgx.Conn, data pgx.T attrs = append(attrs, connectionAttributesFromConfig(conn.Config())...) } + operationName := t.spanNameCtxFunc(ctx, data.SQL) + if t.logSQLStatement { attrs = append(attrs, semconv.DBQueryText(data.SQL), - semconv.DBOperationName(t.spanNameCtxFunc(ctx, data.SQL)), + semconv.DBOperationName(operationName), ) - if t.includeParams { + if t.includeParams && t.shouldRecordParams(data.SQL) { attrs = append(attrs, makeParamsAttribute(data.Args)) } } @@ -278,18 +288,31 @@ func (t *Tracer) TraceQueryStart(ctx context.Context, conn *pgx.Conn, data pgx.T trace.WithAttributes(attrs...), ) - spanName := data.SQL - if t.trimQuerySpanName { - spanName = t.spanNameCtxFunc(ctx, data.SQL) + spanName := t.spanName(data.SQL, operationName, "query ") + + ctx, _ = t.tracer.Start(ctx, spanName, opts...) + + return ctx +} + +// spanName builds the span name following the OpenTelemetry database span +// conventions: the low-cardinality operation name (operationName, e.g. +// "SELECT") by default, or the full SQL statement when WithFullSQLInSpanName is +// set, optionally prefixed when WithQuerySpanNamePrefix is set. +// +// See https://opentelemetry.io/docs/specs/semconv/db/database-spans/ for the +// span name guidance this follows. +func (t *Tracer) spanName(sql, operationName, prefix string) string { + name := operationName + if t.fullQuerySpanName { + name = sql } if t.prefixQuerySpanName { - spanName = "query " + spanName + name = prefix + name } - ctx, _ = t.tracer.Start(ctx, spanName, opts...) - - return ctx + return name } // TraceQueryEnd is called at the end of Query, QueryRow, and Exec calls. @@ -429,13 +452,15 @@ func (t *Tracer) TraceBatchQuery(ctx context.Context, conn *pgx.Conn, data pgx.T attrs = append(attrs, connectionAttributesFromConfig(conn.Config())...) } + operationName := t.spanNameCtxFunc(ctx, data.SQL) + if t.logSQLStatement { attrs = append(attrs, semconv.DBQueryText(data.SQL), - semconv.DBOperationName(t.spanNameCtxFunc(ctx, data.SQL)), + semconv.DBOperationName(operationName), ) - if t.includeParams { + if t.includeParams && t.shouldRecordParams(data.SQL) { attrs = append(attrs, makeParamsAttribute(data.Args)) } } @@ -445,18 +470,7 @@ func (t *Tracer) TraceBatchQuery(ctx context.Context, conn *pgx.Conn, data pgx.T trace.WithAttributes(attrs...), ) - var spanName string - if t.trimQuerySpanName { - spanName = t.spanNameCtxFunc(ctx, data.SQL) - if t.prefixQuerySpanName { - spanName = "query " + spanName - } - } else { - spanName = data.SQL - if t.prefixQuerySpanName { - spanName = "batch query " + spanName - } - } + spanName := t.spanName(data.SQL, operationName, "batch query ") _, span := t.tracer.Start(ctx, spanName, opts...) recordSpanError(span, data.Err) @@ -556,7 +570,8 @@ func (t *Tracer) TracePrepareStart(ctx context.Context, conn *pgx.Conn, data pgx attrs = append(attrs, connectionAttributesFromConfig(conn.Config())...) } - attrs = append(attrs, semconv.DBOperationName(t.spanNameCtxFunc(ctx, data.SQL))) + operationName := t.spanNameCtxFunc(ctx, data.SQL) + attrs = append(attrs, semconv.DBOperationName(operationName)) if t.logSQLStatement { attrs = append(attrs, semconv.DBQueryText(data.SQL)) @@ -567,13 +582,7 @@ func (t *Tracer) TracePrepareStart(ctx context.Context, conn *pgx.Conn, data pgx trace.WithAttributes(attrs...), ) - spanName := data.SQL - if t.trimQuerySpanName { - spanName = t.spanNameCtxFunc(ctx, data.SQL) - } - if t.prefixQuerySpanName { - spanName = "prepare " + spanName - } + spanName := t.spanName(data.SQL, operationName, "prepare ") ctx, _ = t.tracer.Start(ctx, spanName, opts...) @@ -652,6 +661,13 @@ func (t *Tracer) TraceAcquireEnd(ctx context.Context, _ *pgxpool.Pool, data pgxp span.End() } +func (t *Tracer) shouldRecordParams(sql string) bool { + if t.queryParamsFilter == nil { + return true + } + return t.queryParamsFilter(sql) +} + func makeParamsAttribute(args []any) attribute.KeyValue { ss := make([]string, len(args)) for i := range args { diff --git a/vendor/modules.txt b/vendor/modules.txt index cacef013..bd427fb9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -382,7 +382,7 @@ github.com/envoyproxy/go-control-plane/ratelimit/service/ratelimit/v3 # github.com/envoyproxy/protoc-gen-validate v1.3.3 ## explicit; go 1.24.1 github.com/envoyproxy/protoc-gen-validate/validate -# github.com/exaring/otelpgx v0.11.1 +# github.com/exaring/otelpgx v0.12.0 ## explicit; go 1.25.0 github.com/exaring/otelpgx # github.com/felixge/httpsnoop v1.1.0