Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1542. Allow missing carrier headers to continue without raising AttributeError #1545

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v0.17b0...HEAD)

=======
### Added
- Added `end_on_exit` argument to `start_as_current_span`
([#1519](https://github.com/open-telemetry/opentelemetry-python/pull/1519)])
- Add `Span.set_attributes` method to set multiple values with one call
([#1520](https://github.com/open-telemetry/opentelemetry-python/pull/1520))
- Make sure Resources follow semantic conventions
([#1480](https://github.com/open-telemetry/opentelemetry-python/pull/1480))
- Allow missing carrier headers to continue without raising AttributeError
([#1545](https://github.com/open-telemetry/opentelemetry-python/pull/1545))

## [0.17b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v0.17b0) - 2021-01-20

Expand Down
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