From d12420f2ce12f1114e7163b46fdbb3b6a80c3ea6 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Mon, 26 Feb 2024 21:59:53 -0800 Subject: [PATCH] otelhttptrace: handle missing getconn hook without panic We have many reports that end() gets called without the span being defined in start() and causes a panic. Signed-off-by: Tonis Tiigi --- .../net/http/httptrace/otelhttptrace/clienttrace.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/instrumentation/net/http/httptrace/otelhttptrace/clienttrace.go b/instrumentation/net/http/httptrace/otelhttptrace/clienttrace.go index 882f9a10ba7..911f92aba4d 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/clienttrace.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/clienttrace.go @@ -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) + } if err != nil { attrs = append(attrs, attribute.String(hook+".error", err.Error())) }