Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

otelhttptrace: handle missing getconn hook without panic #5965

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Fixed

- Possible nil dereference panic in `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace`. (#5965)

<!-- Released section -->
<!-- Don't change this section unless doing release -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,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()))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,22 @@ func TestEndBeforeStartCreatesSpan(t *testing.T) {
require.Len(t, spans, 1)
}

func TestEndBeforeStartWithoutSubSpansDoesNotPanic(t *testing.T) {
sr := tracetest.NewSpanRecorder()
tp := trace.NewTracerProvider(trace.WithSpanProcessor(sr))
otel.SetTracerProvider(tp)

ct := otelhttptrace.NewClientTrace(context.Background(), otelhttptrace.WithoutSubSpans())

require.NotPanics(t, func() {
ct.DNSDone(httptrace.DNSDoneInfo{})
})

// no spans created because we were just using background context without span
// and Start wasn't called which would have started a span
require.Len(t, sr.Ended(), 0)
}

type clientTraceTestFixture struct {
Address string
URL string
Expand Down
Loading