Skip to content

Commit

Permalink
1542. Allow missing carrier headers to continue without raising Attri…
Browse files Browse the repository at this point in the history
…buteError
  • Loading branch information
ehiggs committed Jan 27, 2021
1 parent ad894b1 commit 41cdc44
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ def extract(

if context is None:
context = get_current()
fields = _extract_first_element(
getter.get(carrier, self.TRACE_ID_KEY)
).split(":")
header = getter.get(carrier, self.TRACE_ID_KEY)
if not header:
return trace.set_span_in_context(trace.INVALID_SPAN, context)
fields = _extract_first_element(header).split(":")

context = self._extract_baggage(getter, carrier, context)
if len(fields) != 4:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ def test_extract_valid_span(self):
self.assertEqual(span_context.trace_id, self.trace_id)
self.assertEqual(span_context.span_id, self.span_id)

def test_missing_carrier(self):
old_carrier = {}
ctx = FORMAT.extract(carrier_getter, old_carrier)
span_context = trace_api.get_current_span(ctx).get_span_context()
self.assertEqual(span_context.trace_id, trace_api.INVALID_TRACE_ID)
self.assertEqual(span_context.span_id, trace_api.INVALID_SPAN_ID)

def test_trace_id(self):
old_carrier = {FORMAT.TRACE_ID_KEY: self.serialized_uber_trace_id}
_, new_carrier = get_context_new_carrier(old_carrier)
Expand Down

0 comments on commit 41cdc44

Please sign in to comment.