Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Fix handling of missing ParentSpanId for B3 codec (#182)
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Gravel <ggravel@appnexus.com>
  • Loading branch information
gravelg authored and yurishkuro committed May 31, 2018
1 parent c007964 commit 2e0b5bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion jaeger_client/codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def header_to_hex(header):
class B3Codec(Codec):
"""
Support B3 header properties
https://github.com/openzipkin/b3-propagation
"""
def __init__(self):
Expand All @@ -277,7 +278,9 @@ def extract(self, carrier):
raise InvalidCarrierException('carrier not a dictionary')
trace_id = header_to_hex(carrier.get(self.trace_header.lower()))
span_id = header_to_hex(carrier.get(self.span_header.lower()))
parent_id = header_to_hex(carrier.get(self.parent_span_header.lower()))
parent_id = carrier.get(self.parent_span_header.lower(), None)
if parent_id:
parent_id = header_to_hex(parent_id)
flags = 0x00
sampled = carrier.get(self.sampled_header.lower())
if sampled == '1':
Expand Down
5 changes: 5 additions & 0 deletions tests/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ def test_b3_extract(self):
assert span_context.parent_id == int('0020000000000001', 16)
assert span_context.flags == 0x02

# validate that missing parentspanid does not cause an error
carrier.pop('x-b3-parentspanid')
span_context = codec.extract(carrier)
assert span_context.parent_id is None

carrier.update({'x-b3-sampled': '1'})

span_context = codec.extract(carrier)
Expand Down

0 comments on commit 2e0b5bd

Please sign in to comment.