Skip to content

Commit

Permalink
otelhttptrace: handle missing getconn hook without panic
Browse files Browse the repository at this point in the history
We have many reports that end() gets called without the
span being defined in start() and causes a panic.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Feb 27, 2024
1 parent 45226f8 commit d12420f
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ func (ct *clientTracer) start(hook, spanName string, attrs ...attribute.KeyValue

func (ct *clientTracer) end(hook string, err error, attrs ...attribute.KeyValue) {
if !ct.useSpans {
// sometimes end may be called without previous start
if ct.root == nil {
ct.root = trace.SpanFromContext(ct.Context)
}

Check warning on line 232 in instrumentation/net/http/httptrace/otelhttptrace/clienttrace.go

View check run for this annotation

Codecov / codecov/patch

instrumentation/net/http/httptrace/otelhttptrace/clienttrace.go#L231-L232

Added lines #L231 - L232 were not covered by tests
if err != nil {
attrs = append(attrs, attribute.String(hook+".error", err.Error()))
}
Expand Down

0 comments on commit d12420f

Please sign in to comment.