Skip to content
This repository was archived by the owner on Aug 17, 2020. It is now read-only.

Commit 689d561

Browse files
committed
Extract priority
1 parent 8bb9f59 commit 689d561

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

tracer/propagation_ot.go

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,9 @@ func (p *textMapPropagator) Extract(
9090
var sampled bool
9191
var err error
9292
decodedBaggage := make(map[string]string)
93+
9394
err = carrier.ForeachKey(func(k, v string) error {
9495
switch strings.ToLower(k) {
95-
case fieldNameTraceID:
96-
traceID, err = uuid.Parse(v)
97-
if err != nil {
98-
return opentracing.ErrSpanContextCorrupted
99-
}
100-
case fieldNameSpanID:
101-
spanID, err = strconv.ParseUint(v, 16, 64)
102-
if err != nil {
103-
return opentracing.ErrSpanContextCorrupted
104-
}
105-
case fieldNameSampled:
106-
sampled, err = strconv.ParseBool(v)
107-
if err != nil {
108-
return opentracing.ErrSpanContextCorrupted
109-
}
11096
case traceParentKey:
11197
if len(v) < 55 {
11298
return opentracing.ErrSpanContextCorrupted
@@ -137,10 +123,6 @@ func (p *textMapPropagator) Extract(
137123
}
138124
}
139125
default:
140-
lowercaseK := strings.ToLower(k)
141-
if strings.HasPrefix(lowercaseK, prefixBaggage) {
142-
decodedBaggage[strings.TrimPrefix(lowercaseK, prefixBaggage)] = v
143-
}
144126
// Balance off the requiredFieldCount++ just below...
145127
requiredFieldCount--
146128
}
@@ -150,6 +132,40 @@ func (p *textMapPropagator) Extract(
150132
if err != nil {
151133
return nil, err
152134
}
135+
if traceID == uuid.Nil && spanID == 0 {
136+
err = carrier.ForeachKey(func(k, v string) error {
137+
switch strings.ToLower(k) {
138+
case fieldNameTraceID:
139+
traceID, err = uuid.Parse(v)
140+
if err != nil {
141+
return opentracing.ErrSpanContextCorrupted
142+
}
143+
case fieldNameSpanID:
144+
spanID, err = strconv.ParseUint(v, 16, 64)
145+
if err != nil {
146+
return opentracing.ErrSpanContextCorrupted
147+
}
148+
case fieldNameSampled:
149+
sampled, err = strconv.ParseBool(v)
150+
if err != nil {
151+
return opentracing.ErrSpanContextCorrupted
152+
}
153+
default:
154+
lowercaseK := strings.ToLower(k)
155+
if strings.HasPrefix(lowercaseK, prefixBaggage) {
156+
decodedBaggage[strings.TrimPrefix(lowercaseK, prefixBaggage)] = v
157+
}
158+
// Balance off the requiredFieldCount++ just below...
159+
requiredFieldCount--
160+
}
161+
requiredFieldCount++
162+
return nil
163+
})
164+
if err != nil {
165+
return nil, err
166+
}
167+
}
168+
153169
if requiredFieldCount < tracerStateFieldCount {
154170
if requiredFieldCount == 0 {
155171
return nil, opentracing.ErrSpanContextNotFound

0 commit comments

Comments
 (0)