Skip to content

Commit

Permalink
Fixed B3 Propagator
Browse files Browse the repository at this point in the history
B3 propagator was returning `None` instead of invalid context after last
change. This resulted in many apps crashing when B3 failed to extract a
valid context from carrier. This PR patches it to not make apps crash
and return an invalid context when one cannot be extracted from the
carrier.
  • Loading branch information
owais committed Apr 6, 2021
1 parent cad261e commit fba4e61
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1721](https://github.com/open-telemetry/opentelemetry-python/pull/1721))
- Update bootstrap cmd to use exact version when installing instrumentation packages.
([#1722](https://github.com/open-telemetry/opentelemetry-python/pull/1722))
- Fix B3 propagator to never return None.
([#1750](https://github.com/open-telemetry/opentelemetry-python/pull/1750))


## [1.0.0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.0.0) - 2021-03-26
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ def extract(
or self._trace_id_regex.fullmatch(trace_id) is None
or self._span_id_regex.fullmatch(span_id) is None
):
if context is None:
return trace.set_span_in_context(trace.INVALID_SPAN, context)
return context

trace_id = int(trace_id, 16)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,12 @@ def test_fields(self):
inject_fields.add(call[1][1])

self.assertEqual(FORMAT.fields, inject_fields)

def test_extract_none_context(self):
"""Given no trace ID, do not modify context"""
old_ctx = None

carrier = {}
new_ctx = FORMAT.extract(carrier, old_ctx)
self.assertIsNotNone(new_ctx)
self.assertEqual(new_ctx["current-span"], trace_api.INVALID_SPAN)

0 comments on commit fba4e61

Please sign in to comment.