From 41cdc44544f69d59b938c8bcc15427b0a705d915 Mon Sep 17 00:00:00 2001 From: Ewan Higgs Date: Fri, 22 Jan 2021 06:28:33 +0100 Subject: [PATCH] 1542. Allow missing carrier headers to continue without raising AttributeError --- .../src/opentelemetry/propagators/jaeger/__init__.py | 7 ++++--- .../tests/test_jaeger_propagator.py | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/propagator/opentelemetry-propagator-jaeger/src/opentelemetry/propagators/jaeger/__init__.py b/propagator/opentelemetry-propagator-jaeger/src/opentelemetry/propagators/jaeger/__init__.py index f9ad768291d..67c7d716c96 100644 --- a/propagator/opentelemetry-propagator-jaeger/src/opentelemetry/propagators/jaeger/__init__.py +++ b/propagator/opentelemetry-propagator-jaeger/src/opentelemetry/propagators/jaeger/__init__.py @@ -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: diff --git a/propagator/opentelemetry-propagator-jaeger/tests/test_jaeger_propagator.py b/propagator/opentelemetry-propagator-jaeger/tests/test_jaeger_propagator.py index 6e6f548d093..46c554d4f5e 100644 --- a/propagator/opentelemetry-propagator-jaeger/tests/test_jaeger_propagator.py +++ b/propagator/opentelemetry-propagator-jaeger/tests/test_jaeger_propagator.py @@ -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)