Skip to content

Commit 56bd862

Browse files
authored
Fix inconsistent Jaeger baggage injection/extraction (#972)
1 parent 1efbbb3 commit 56bd862

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

internal/tracer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (t *tracingContextPropagator) InjectFromWorkflow(
100100
if spanContext == nil {
101101
return nil
102102
}
103-
return t.tracer.Inject(spanContext, opentracing.HTTPHeaders, tracingWriter{hw})
103+
return t.tracer.Inject(spanContext, opentracing.TextMap, tracingWriter{hw})
104104
}
105105

106106
func (t *tracingContextPropagator) ExtractToWorkflow(

internal/tracer_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,34 @@ func TestTracingContextPropagatorWorkflowContextNoSpan(t *testing.T) {
116116
returnCtx, err = ctxProp.ExtractToWorkflow(returnCtx, NewHeaderReader(header))
117117
assert.NoError(t, err)
118118
}
119+
120+
func TestConsistentInjectionExtraction(t *testing.T) {
121+
t.Parallel()
122+
tracer, closer, err := jaeger_config.Configuration{ServiceName: "test-service"}.NewTracer()
123+
require.NoError(t, err)
124+
defer closer.Close()
125+
ctxProp := NewTracingContextPropagator(zap.NewNop(), tracer)
126+
127+
span := tracer.StartSpan("test-operation")
128+
// base64 encoded string '{}'
129+
var baggageVal = "e30="
130+
span.SetBaggageItem("request-tenancy", baggageVal)
131+
assert.NotNil(t, span.Context())
132+
ctx := contextWithSpan(Background(), span.Context())
133+
header := &shared.Header{
134+
Fields: map[string][]byte{},
135+
}
136+
err = ctxProp.InjectFromWorkflow(ctx, NewHeaderWriter(header))
137+
require.NoError(t, err)
138+
139+
extractedCtx, err := ctxProp.ExtractToWorkflow(Background(), NewHeaderReader(header))
140+
require.NoError(t, err)
141+
142+
extractedSpanContext := spanFromContext(extractedCtx)
143+
extractedSpanContext.ForeachBaggageItem(func(k, v string) bool {
144+
if k == "request-tenancy" {
145+
assert.Equal(t, v, baggageVal)
146+
}
147+
return false
148+
})
149+
}

0 commit comments

Comments
 (0)