diff options
| author | 2025-03-03 10:42:05 +0000 | |
|---|---|---|
| committer | 2025-03-03 10:42:05 +0000 | |
| commit | 67a2b3650c5f586431c8559bc9b609699de8431d (patch) | |
| tree | f4a269939f7f175277a92aaa33bf58e652d4e276 /vendor/github.com/uptrace/bun/extra | |
| parent | [chore]: Bump github.com/prometheus/client_golang from 1.20.5 to 1.21.0 (#3860) (diff) | |
| download | gotosocial-67a2b3650c5f586431c8559bc9b609699de8431d.tar.xz | |
bumps our uptrace/bun dependencies to v1.2.10 (#3865)
Diffstat (limited to 'vendor/github.com/uptrace/bun/extra')
| -rw-r--r-- | vendor/github.com/uptrace/bun/extra/bunotel/option.go | 9 | ||||
| -rw-r--r-- | vendor/github.com/uptrace/bun/extra/bunotel/otel.go | 22 |
2 files changed, 22 insertions, 9 deletions
diff --git a/vendor/github.com/uptrace/bun/extra/bunotel/option.go b/vendor/github.com/uptrace/bun/extra/bunotel/option.go index 4c9c90a30..4824f3863 100644 --- a/vendor/github.com/uptrace/bun/extra/bunotel/option.go +++ b/vendor/github.com/uptrace/bun/extra/bunotel/option.go @@ -1,6 +1,7 @@ package bunotel import ( + "github.com/uptrace/bun" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" semconv "go.opentelemetry.io/otel/semconv/v1.12.0" @@ -33,6 +34,14 @@ func WithFormattedQueries(format bool) Option { } } +// WithSpanNameFormatter takes a function that determines the span name +// for a given query event. +func WithSpanNameFormatter(f func(*bun.QueryEvent) string) Option { + return func(h *QueryHook) { + h.spanNameFormatter = f + } +} + // WithTracerProvider returns an Option to use the TracerProvider when // creating a Tracer. func WithTracerProvider(tp trace.TracerProvider) Option { diff --git a/vendor/github.com/uptrace/bun/extra/bunotel/otel.go b/vendor/github.com/uptrace/bun/extra/bunotel/otel.go index 66b88e989..db098bc6a 100644 --- a/vendor/github.com/uptrace/bun/extra/bunotel/otel.go +++ b/vendor/github.com/uptrace/bun/extra/bunotel/otel.go @@ -22,11 +22,12 @@ import ( ) type QueryHook struct { - attrs []attribute.KeyValue - formatQueries bool - tracer trace.Tracer - meter metric.Meter - queryHistogram metric.Int64Histogram + attrs []attribute.KeyValue + formatQueries bool + tracer trace.Tracer + meter metric.Meter + queryHistogram metric.Int64Histogram + spanNameFormatter func(*bun.QueryEvent) string } var _ bun.QueryHook = (*QueryHook)(nil) @@ -86,7 +87,11 @@ func (h *QueryHook) AfterQuery(ctx context.Context, event *bun.QueryEvent) { return } - span.SetName(operation) + name := operation + if h.spanNameFormatter != nil { + name = h.spanNameFormatter(event) + } + span.SetName(name) defer span.End() query := h.eventQuery(event) @@ -106,9 +111,8 @@ func (h *QueryHook) AfterQuery(ctx context.Context, event *bun.QueryEvent) { attrs = append(attrs, sys) } if event.Result != nil { - if n, _ := event.Result.RowsAffected(); n > 0 { - attrs = append(attrs, attribute.Int64("db.rows_affected", n)) - } + rows, _ := event.Result.RowsAffected() + attrs = append(attrs, attribute.Int64("db.rows_affected", rows)) } switch event.Err { |
