feat(tracing/sql): emit breadcrumbs

This commit is contained in:
DevMiner 2024-08-10 02:00:07 +02:00
parent 91fc1dc9c1
commit 3c254e8768

View file

@ -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
}