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

Fix handling of missing headers in the b3 codec #215

Merged
merged 4 commits into from
Jan 2, 2019

Conversation

cshowe
Copy link
Contributor

@cshowe cshowe commented Oct 26, 2018

The b3 codec uses .get() to extract headers and so does not throw a key
error if headers are missing. However many of these headers are decoded
via "header_to_hex" which throws an exception on a None value. Other
codecs handle the missing header case by returning None, update the b3
codec to follow this convention.

Signed-off-by: Caleb Howe Caleb.S.Howe@gmail.com

@codecov
Copy link

codecov bot commented Oct 26, 2018

Codecov Report

Merging #215 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #215      +/-   ##
==========================================
+ Coverage   94.89%   94.91%   +0.01%     
==========================================
  Files          25       25              
  Lines        1843     1848       +5     
  Branches      240      245       +5     
==========================================
+ Hits         1749     1754       +5     
  Misses         61       61              
  Partials       33       33
Impacted Files Coverage Δ
jaeger_client/codecs.py 95.4% <100%> (+0.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 22859a3...bd23034. Read the comment docs.

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for contributing a fix. I have a slightly different suggestion on a fix.

if header_value is not None:
header_value = header_to_hex(header_value)
return header_value

def extract(self, carrier):
if not isinstance(carrier, dict):
raise InvalidCarrierException('carrier not a dictionary')
lowercase_keys = dict([(k.lower(), k) for k in carrier])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be simpler and more efficient to just loop through the carrier keys, e.g.

for key, value in six.itemitems(carrier):
    if value is None:
        continue  # is this even possible in Python?
    lowerKey = key.lower()
    if lowerKey == self._trace_header_lc:
        # parse
    elif lowerKey == self._span_header_lc:
        # parse

This avoids creating an intermediate dictionary, and partially addresses your issue

@yurishkuro
Copy link
Member

@cshowe ping - are you still interested in this PR?

@cshowe
Copy link
Contributor Author

cshowe commented Dec 31, 2018

Yes, just fell off my radar. I should address your comments today.

The b3 codec uses .get() to extract headers and so does not throw a key
error if headers are missing.  However many of these headers are decoded
via "header_to_hex" which throws an exception on a None value.  Other
codecs handle the missing header case by returning None, update the b3
codec to follow this convention.

Signed-off-by: Caleb Howe <Caleb.S.Howe@gmail.com>
Signed-off-by: Caleb Howe <Caleb.S.Howe@gmail.com>
Signed-off-by: Caleb Howe <Caleb.S.Howe@gmail.com>
Signed-off-by: Caleb Howe <Caleb.S.Howe@gmail.com>
@@ -339,6 +339,20 @@ def test_b3_extract(self):
span_context = codec.extract(carrier)
assert span_context.flags == 0x01

# validate present debug header with falsy value
carrier = {'X-b3-SpanId': 'a2fb4a1d1a96d312', 'X-B3-flags': '0',
'X-B3-traceId': '463ac35c9f6413ad48485a3953bb6124'}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting...

>>> header = '463ac35c9f6413ad48485a3953bb6124'
>>> int(header, 16)
93351075330931896558786731617803788580L

perhaps supporting 128bit IDs (#228) is not going to be particularly difficult.

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@yurishkuro yurishkuro merged commit 73ea288 into jaegertracing:master Jan 2, 2019
pravarag added a commit to pravarag/jaeger-client-python that referenced this pull request Jan 9, 2019
Fix handling of missing headers in the b3 codec (jaegertracing#215)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants