Skip to content

Commit 7d03ede

Browse files
authored
Merge pull request #826 from defanator/case-insensitive-headers
[core] Use case-insensitive comparison of header names during extract
2 parents a2c8c1d + 7fe3234 commit 7d03ede

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

ddtrace/propagation/http.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,34 +56,35 @@ def parent_call():
5656
headers[HTTP_HEADER_SAMPLING_PRIORITY] = str(span_context.sampling_priority)
5757

5858
@staticmethod
59-
def extract_trace_id(headers):
60-
trace_id = 0
59+
def extract_header_value(possible_header_names, headers, default=None):
60+
for header, value in headers.items():
61+
for header_name in possible_header_names:
62+
if header.lower() == header_name.lower():
63+
return value
6164

62-
for key in POSSIBLE_HTTP_HEADER_TRACE_IDS:
63-
if key in headers:
64-
trace_id = headers.get(key)
65+
return default
6566

66-
return int(trace_id)
67+
@staticmethod
68+
def extract_trace_id(headers):
69+
return int(
70+
HTTPPropagator.extract_header_value(
71+
POSSIBLE_HTTP_HEADER_TRACE_IDS, headers, default=0,
72+
)
73+
)
6774

6875
@staticmethod
6976
def extract_parent_span_id(headers):
70-
parent_span_id = 0
71-
72-
for key in POSSIBLE_HTTP_HEADER_PARENT_IDS:
73-
if key in headers:
74-
parent_span_id = headers.get(key)
75-
76-
return int(parent_span_id)
77+
return int(
78+
HTTPPropagator.extract_header_value(
79+
POSSIBLE_HTTP_HEADER_PARENT_IDS, headers, default=0,
80+
)
81+
)
7782

7883
@staticmethod
7984
def extract_sampling_priority(headers):
80-
sampling_priority = None
81-
82-
for key in POSSIBLE_HTTP_HEADER_SAMPLING_PRIORITIES:
83-
if key in headers:
84-
sampling_priority = headers.get(key)
85-
86-
return sampling_priority
85+
return HTTPPropagator.extract_header_value(
86+
POSSIBLE_HTTP_HEADER_SAMPLING_PRIORITIES, headers,
87+
)
8788

8889
def extract(self, headers):
8990
"""Extract a Context from HTTP headers into a new Context.

0 commit comments

Comments
 (0)