fixup tracing
Some checks failed
build / test (push) Failing after 1m49s
codeql / analyze (go) (push) Failing after 1m43s
build / lint (push) Successful in 9m16s

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2024-05-06 08:56:16 +03:00
parent 0dfee57dd4
commit 44256cd62f
2 changed files with 19 additions and 19 deletions

26
conn.go
View File

@ -99,9 +99,9 @@ func (w *wrapperConn) Begin() (driver.Tx, error) {
// BeginTx implements driver.ConnBeginTx BeginTx // BeginTx implements driver.ConnBeginTx BeginTx
func (w *wrapperConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) { func (w *wrapperConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
nctx, span := w.opts.Tracer.Start(ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient))
span.AddLabels("db.method", "BeginTx")
name := getQueryName(ctx) name := getQueryName(ctx)
nctx, span := w.opts.Tracer.Start(ctx, "sdk.database "+name, tracer.WithSpanKind(tracer.SpanKindClient))
span.AddLabels("db.method", "BeginTx")
span.AddLabels("db.statement", name) span.AddLabels("db.statement", name)
if id, ok := ctx.Value(requestid.XRequestIDKey{}).(string); ok { if id, ok := ctx.Value(requestid.XRequestIDKey{}).(string); ok {
span.AddLabels("x-request-id", id) span.AddLabels("x-request-id", id)
@ -173,13 +173,13 @@ func (w *wrapperConn) PrepareContext(ctx context.Context, query string) (driver.
var nctx context.Context var nctx context.Context
var span tracer.Span var span tracer.Span
name := getQueryName(ctx)
if w.ctx != nil { if w.ctx != nil {
nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient)) nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database "+name, tracer.WithSpanKind(tracer.SpanKindClient))
} else { } else {
nctx, span = w.opts.Tracer.Start(ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient)) nctx, span = w.opts.Tracer.Start(ctx, "sdk.database "+name, tracer.WithSpanKind(tracer.SpanKindClient))
} }
span.AddLabels("db.method", "PrepareContext") span.AddLabels("db.method", "PrepareContext")
name := getQueryName(ctx)
span.AddLabels("db.statement", name) span.AddLabels("db.statement", name)
if id, ok := ctx.Value(requestid.XRequestIDKey{}).(string); ok { if id, ok := ctx.Value(requestid.XRequestIDKey{}).(string); ok {
span.AddLabels("x-request-id", id) span.AddLabels("x-request-id", id)
@ -252,13 +252,13 @@ func (w *wrapperConn) ExecContext(ctx context.Context, query string, args []driv
var nctx context.Context var nctx context.Context
var span tracer.Span var span tracer.Span
name := getQueryName(ctx)
if w.ctx != nil { if w.ctx != nil {
nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient)) nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database "+name, tracer.WithSpanKind(tracer.SpanKindClient))
} else { } else {
nctx, span = w.opts.Tracer.Start(ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient)) nctx, span = w.opts.Tracer.Start(ctx, "sdk.database "+name, tracer.WithSpanKind(tracer.SpanKindClient))
} }
span.AddLabels("db.method", "ExecContext") span.AddLabels("db.method", "ExecContext")
name := getQueryName(ctx)
span.AddLabels("db.statement", name) span.AddLabels("db.statement", name)
if id, ok := ctx.Value(requestid.XRequestIDKey{}).(string); ok { if id, ok := ctx.Value(requestid.XRequestIDKey{}).(string); ok {
span.AddLabels("x-request-id", id) span.AddLabels("x-request-id", id)
@ -311,9 +311,9 @@ func (w *wrapperConn) Ping(ctx context.Context) error {
var nctx context.Context var nctx context.Context
var span tracer.Span var span tracer.Span
if w.ctx != nil { if w.ctx != nil {
nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient)) nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database Ping", tracer.WithSpanKind(tracer.SpanKindClient))
} else { } else {
nctx, span = w.opts.Tracer.Start(ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient)) nctx, span = w.opts.Tracer.Start(ctx, "sdk.database Ping", tracer.WithSpanKind(tracer.SpanKindClient))
} }
span.AddLabels("db.method", "Ping") span.AddLabels("db.method", "Ping")
defer span.Finish() defer span.Finish()
@ -375,13 +375,13 @@ func (w *wrapperConn) QueryContext(ctx context.Context, query string, args []dri
var nctx context.Context var nctx context.Context
var span tracer.Span var span tracer.Span
name := getQueryName(ctx)
if w.ctx != nil { if w.ctx != nil {
nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient)) nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database "+name, tracer.WithSpanKind(tracer.SpanKindClient))
} else { } else {
nctx, span = w.opts.Tracer.Start(ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient)) nctx, span = w.opts.Tracer.Start(ctx, "sdk.database "+name, tracer.WithSpanKind(tracer.SpanKindClient))
} }
span.AddLabels("db.method", "QueryContext") span.AddLabels("db.method", "QueryContext")
name := getQueryName(ctx)
span.AddLabels("db.statement", name) span.AddLabels("db.statement", name)
if id, ok := ctx.Value(requestid.XRequestIDKey{}).(string); ok { if id, ok := ctx.Value(requestid.XRequestIDKey{}).(string); ok {
span.AddLabels("x-request-id", id) span.AddLabels("x-request-id", id)

12
stmt.go
View File

@ -136,13 +136,13 @@ func (w *wrapperStmt) ExecContext(ctx context.Context, args []driver.NamedValue)
var nctx context.Context var nctx context.Context
var span tracer.Span var span tracer.Span
name := getQueryName(ctx)
if w.ctx != nil { if w.ctx != nil {
nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient)) nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database "+name, tracer.WithSpanKind(tracer.SpanKindClient))
} else { } else {
nctx, span = w.opts.Tracer.Start(ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient)) nctx, span = w.opts.Tracer.Start(ctx, "sdk.database "+name, tracer.WithSpanKind(tracer.SpanKindClient))
} }
span.AddLabels("db.method", "ExecContext") span.AddLabels("db.method", "ExecContext")
name := getQueryName(ctx)
span.AddLabels("db.statement", name) span.AddLabels("db.statement", name)
defer span.Finish() defer span.Finish()
if len(args) > 0 { if len(args) > 0 {
@ -209,13 +209,13 @@ func (w *wrapperStmt) QueryContext(ctx context.Context, args []driver.NamedValue
var nctx context.Context var nctx context.Context
var span tracer.Span var span tracer.Span
name := getQueryName(ctx)
if w.ctx != nil { if w.ctx != nil {
nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient)) nctx, span = w.opts.Tracer.Start(w.ctx, "sdk.database "+name, tracer.WithSpanKind(tracer.SpanKindClient))
} else { } else {
nctx, span = w.opts.Tracer.Start(ctx, "sdk.database", tracer.WithSpanKind(tracer.SpanKindClient)) nctx, span = w.opts.Tracer.Start(ctx, "sdk.database "+name, tracer.WithSpanKind(tracer.SpanKindClient))
} }
span.AddLabels("db.method", "QueryContext") span.AddLabels("db.method", "QueryContext")
name := getQueryName(ctx)
span.AddLabels("db.statement", name) span.AddLabels("db.statement", name)
defer span.Finish() defer span.Finish()
if len(args) > 0 { if len(args) > 0 {