Skip to content

Commit

Permalink
Record error and status for Otelsql when SQL returns an error
Browse files Browse the repository at this point in the history
The Span ends early when SQL returns an error, which prevents Otelsql from recording the error and setting the status. This commit fixes this issue by deferring the Span.End() call.
  • Loading branch information
empire authored Dec 6, 2023
1 parent 4700947 commit 34abe49
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion otelsql/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (t *dbInstrum) withSpan(
trace.WithSpanKind(trace.SpanKindClient),
trace.WithAttributes(attrs...))
err := fn(ctx, span)
span.End()
defer span.End()

if query != "" {
t.queryHistogram.Record(ctx, time.Since(startTime).Milliseconds(), metric.WithAttributes(t.attrs...))
Expand Down

0 comments on commit 34abe49

Please sign in to comment.