feat(tracing/sql): emit breadcrumbs
This commit is contained in:
parent
91fc1dc9c1
commit
3c254e8768
1 changed files with 7 additions and 4 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue