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

Added methods for SpanID and TraceID on bridgeSpanContext #3966

Merged
merged 14 commits into from
Apr 25, 2023
Merged
8 changes: 8 additions & 0 deletions bridge/opentracing/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ func (c *bridgeSpanContext) IsSampled() bool {
return c.otelSpanContext.IsSampled()
}

func (c *bridgeSpanContext) TraceID() trace.TraceID {
return c.otelSpanContext.TraceID()
}

func (c *bridgeSpanContext) SpanID() trace.SpanID {
return c.otelSpanContext.SpanID()
}

func (c *bridgeSpanContext) setBaggageItem(restrictedKey, value string) {
crk := http.CanonicalHeaderKey(restrictedKey)
m, err := baggage.NewMember(crk, value)
Expand Down
38 changes: 38 additions & 0 deletions bridge/opentracing/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,41 @@ func TestBridge_SpanContext_IsSampled(t *testing.T) {
})
}
}

func TestBridge_SpanContext_TraceID_SpanID(t *testing.T) {
bridge := NewBridgeTracer()
bridge.SetTextMapPropagator(new(testTextMapPropagator))

tmc := newTextCarrier()

testCases := []struct {
name string
traceID trace.TraceID
spanID trace.SpanID
}{
{
name: "support for getting spanID and traceID",
traceID: [16]byte{byte(1)},
spanID: [8]byte{byte(2)},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Kaushal28 marked this conversation as resolved.
Show resolved Hide resolved
err := bridge.Inject(newBridgeSpanContext(trace.NewSpanContext(trace.SpanContextConfig{
TraceID: tc.traceID,
SpanID: tc.spanID,
}), nil), ot.TextMap, tmc)
assert.NoError(t, err)

spanContext, err := bridge.Extract(ot.TextMap, tmc)
assert.NoError(t, err)

bsc, ok := spanContext.(*bridgeSpanContext)
assert.True(t, ok)

assert.Equal(t, spanID.String(), bsc.SpanID().String())
assert.Equal(t, traceID.String(), bsc.TraceID().String())
})
}
}