Skip to content

Commit 0e50715

Browse files
committed
Simplify and add list/tuple support for extract
1 parent f326fa4 commit 0e50715

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

instana/propagator.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import absolute_import
22
import opentracing as ot
3+
from basictracer.context import SpanContext
34
from instana import util, log
45

56
prefix_tracer_state = 'HTTP_X_INSTANA_'
@@ -31,25 +32,21 @@ def inject(self, span_context, carrier):
3132

3233
def extract(self, carrier): # noqa
3334
try:
34-
count = 0
35-
span_id, trace_id = (0, 0)
36-
for k in carrier:
37-
v = carrier[k]
38-
k = k.lower()
39-
if k == field_name_span_id:
40-
span_id = util.header_to_id(v)
41-
count += 1
42-
elif k == field_name_trace_id:
43-
trace_id = util.header_to_id(v)
44-
count += 1
45-
46-
if count != field_count:
35+
if type(carrier) is dict:
36+
dc = carrier
37+
elif type(carrier) is list:
38+
dc = dict(carrier)
39+
else:
4740
raise ot.SpanContextCorruptedException()
4841

49-
return ot.SpanContext(
50-
span_id=span_id,
51-
trace_id=trace_id,
52-
baggage={},
53-
sampled=True)
42+
if field_name_trace_id in dc and field_name_span_id in dc:
43+
trace_id = util.header_to_id(dc[field_name_trace_id])
44+
span_id = util.header_to_id(dc[field_name_span_id])
45+
46+
return SpanContext(span_id=span_id,
47+
trace_id=trace_id,
48+
baggage={},
49+
sampled=True)
50+
5451
except Exception as e:
5552
log.debug("extract error: ", str(e))

0 commit comments

Comments
 (0)