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

bridge/opentracing: fix baggage item key is canonicalized #4776

Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
86 changes: 86 additions & 0 deletions bridge/opentracing/bridge_test.go
Expand Up @@ -574,3 +574,89 @@ func TestBridgeSpanContextPromotedMethods(t *testing.T) {
assert.True(t, spanContext.(spanContextProvider).HasTraceID())
})
}

func TestBridgeCarrierBaggagePropagation(t *testing.T) {
testCases := []struct {
name string
format ot.BuiltinFormat
carrier interface{}
baggageItems []bipBaggage
wantBaggageItems []bipBaggage
}{
{
name: "HTTPHeadersCarrier",
format: ot.HTTPHeaders,
carrier: ot.HTTPHeadersCarrier(http.Header{}),
scorpionknifes marked this conversation as resolved.
Show resolved Hide resolved
baggageItems: []bipBaggage{
{
key: "foo",
value: "bar",
},
},
wantBaggageItems: []bipBaggage{
pellared marked this conversation as resolved.
Show resolved Hide resolved
{
key: "Foo",
pellared marked this conversation as resolved.
Show resolved Hide resolved
value: "bar",
},
},
},
{
name: "TextMapCarrier",
format: ot.TextMap,
carrier: ot.TextMapCarrier(map[string]string{}),
baggageItems: []bipBaggage{
{
key: "foo",
value: "bar",
},
{
key: "foo2",
value: "bar2",
},
},
wantBaggageItems: []bipBaggage{
{
key: "Foo",
value: "bar",
},
{
key: "Foo2",
value: "bar2",
},
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
mockOtelTracer := internal.NewMockTracer()
b, _ := NewTracerPair(mockOtelTracer)
b.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(
propagation.TraceContext{},
propagation.Baggage{}), // Required for baggage propagation.
)

// Set baggage items.
span := b.StartSpan("test")
for _, bi := range tc.baggageItems {
span.SetBaggageItem(bi.key, bi.value)
}
defer span.Finish()

err := b.Inject(span.Context(), tc.format, tc.carrier)
assert.NoError(t, err)

spanContext, err := b.Extract(tc.format, tc.carrier)
assert.NoError(t, err)

// Check baggage items.
bsc, ok := spanContext.(*bridgeSpanContext)
assert.True(t, ok)
assert.Equal(t, len(tc.wantBaggageItems), bsc.bag.Len())
for i, m := range bsc.bag.Members() {
assert.Equal(t, tc.wantBaggageItems[i].key, m.Key())
assert.Equal(t, tc.wantBaggageItems[i].value, m.Value())
}
})
}
}