Skip to content
This repository was archived by the owner on Jun 14, 2023. It is now read-only.

Commit 9094186

Browse files
authored
Fix panic when calling putCorrelation (#95)
1 parent fa1294c commit 9094186

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

correlation_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,31 @@ func TestGetCorrelation_WithTracingContest(t *testing.T) {
9393
return m
9494
}(),
9595
},
96+
{
97+
name: "existing context with empty correlation",
98+
extractor: func(headerKey string) (string, error) {
99+
if headerKey == propagation.HeaderCorrelation {
100+
return "", nil
101+
}
102+
if headerKey == propagation.Header {
103+
return "1-MWYyZDRiZjQ3YmY3MTFlYWI3OTRhY2RlNDgwMDExMjI=-MWU3YzIwNGE3YmY3MTFlYWI4NThhY2RlNDgwMDExMjI=" +
104+
"-0-c2VydmljZQ==-aW5zdGFuY2U=-cHJvcGFnYXRpb24=-cHJvcGFnYXRpb246NTU2Ng==", nil
105+
}
106+
return "", nil
107+
},
108+
extracted: func() map[string]string {
109+
m := make(map[string]string)
110+
return m
111+
}(),
112+
customCase: func(ctx context.Context, t *testing.T) {
113+
verifyPutResult(ctx, correlationTestKey, correlationTestValue, true, t)
114+
},
115+
want: func() map[string]string {
116+
m := make(map[string]string)
117+
m[correlationTestKey] = correlationTestValue
118+
return m
119+
}(),
120+
},
96121
{
97122
name: "empty context with put bound judge",
98123
extractor: func(headerKey string) (string, error) {

segment.go

+3
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ func (s *segmentSpanImpl) createSegmentContext(parent segmentSpan) (err error) {
191191
if s.SegmentContext.FirstSpan == nil {
192192
s.SegmentContext.FirstSpan = s
193193
}
194+
if s.CorrelationContext == nil {
195+
s.CorrelationContext = make(map[string]string)
196+
}
194197
return
195198
}
196199

0 commit comments

Comments
 (0)