Skip to content

Commit

Permalink
fix(ddtrace/tracer): fix panic in SQLCommentCarrier
Browse files Browse the repository at this point in the history
  • Loading branch information
rarguelloF committed Dec 30, 2024
1 parent 4f57a47 commit b09d1dc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ddtrace/tracer/spancontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ func (c *spanContext) baggageItem(key string) string {
}

func (c *spanContext) meta(key string) (val string, ok bool) {
if c.span == nil {
return "", false
}
c.span.RLock()
defer c.span.RUnlock()
val, ok = c.span.Meta[key]
Expand Down
29 changes: 29 additions & 0 deletions ddtrace/tracer/sqlcomment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,35 @@ func TestSQLCommentCarrier(t *testing.T) {
}
}

// https://github.com/DataDog/dd-trace-go/issues/2837
func TestSQLCommentCarrierInjectNilSpan(t *testing.T) {
tracer := newTracer()
defer tracer.Stop()

headers := TextMapCarrier(map[string]string{
DefaultTraceIDHeader: "4",
DefaultParentIDHeader: "1",
originHeader: "synthetics",
b3TraceIDHeader: "0021dc1807524785",
traceparentHeader: "00-00000000000000000000000000000004-2222222222222222-01",
tracestateHeader: "dd=s:2;o:rum;p:0000000000000001;t.tid:1230000000000000~~,othervendor=t61rcWkgMzE",
})

spanCtx, err := tracer.Extract(headers)
require.NoError(t, err)

carrier := SQLCommentCarrier{
Query: "SELECT * from FOO",
Mode: DBMPropagationModeFull,
DBServiceName: "whiskey-db",
PeerDBHostname: "",
PeerDBName: "",
PeerService: "",
}
err = carrier.Inject(spanCtx)
require.NoError(t, err)
}

func TestExtractOpenTelemetryTraceInformation(t *testing.T) {
// open-telemetry supports 128 bit trace ids
traceID := "5bd66ef5095369c7b0d1f8f4bd33716a"
Expand Down

0 comments on commit b09d1dc

Please sign in to comment.