diff --git a/sql_tracing.go b/sql_tracing.go index b685f59..3dbdd02 100644 --- a/sql_tracing.go +++ b/sql_tracing.go @@ -15,6 +15,8 @@ import ( "go.opentelemetry.io/otel/trace" ) +// TODO: Port to github.com/loghole/dbhook for proper error handling + const ( sqlClientID = libBase + "#TracedSQL" ) @@ -79,16 +81,17 @@ func (h *tracedSQLHooks) Before(ctx context.Context, query string, args ...inter } func (h *tracedSQLHooks) After(ctx context.Context, query string, args ...interface{}) (context.Context, error) { - if s := SpanFromContext(ctx); s != nil { - s.End() - } - if val, ok := ctx.Value(dbCtxKey).(dbCtxVal); ok { attrs := val.attrs h.mDuration.Record(ctx, float64(time.Since(val.start).Milliseconds()), metric.WithAttributes(attrs...)) } + if s := SpanFromContext(ctx); s != nil { + s.CaptureBreadcrumb(SeverityDebug, BreadcrumbTypeQuery, "started", query, map[string]any{"args": args}). + End() + } + return ctx, nil }