diff --git a/ddtrace/propagation/http.py b/ddtrace/propagation/http.py index a1664664ace..563ee838d84 100644 --- a/ddtrace/propagation/http.py +++ b/ddtrace/propagation/http.py @@ -101,6 +101,7 @@ def _possible_header(header): _POSSIBLE_HTTP_HEADER_B3_FLAGS = _possible_header(_HTTP_HEADER_B3_FLAGS) _POSSIBLE_HTTP_HEADER_TRACEPARENT = _possible_header(_HTTP_HEADER_TRACEPARENT) _POSSIBLE_HTTP_HEADER_TRACESTATE = _possible_header(_HTTP_HEADER_TRACESTATE) +_POSSIBLE_HTTP_BAGGAGE_HEADER = _possible_header(_HTTP_HEADER_BAGGAGE) # https://www.w3.org/TR/trace-context/#traceparent-header-field-values @@ -937,7 +938,7 @@ def _inject(span_context: Context, headers: Dict[str, str]) -> None: @staticmethod def _extract(headers: Dict[str, str]) -> Context: - header_value = headers.get(_HTTP_HEADER_BAGGAGE) + header_value = _extract_header_value(_POSSIBLE_HTTP_BAGGAGE_HEADER, headers) if not header_value: return Context(baggage={}) diff --git a/releasenotes/notes/case_insensitive_baggage_header_extraction-63167c492474da6f.yaml b/releasenotes/notes/case_insensitive_baggage_header_extraction-63167c492474da6f.yaml new file mode 100644 index 00000000000..ad0eacb28e8 --- /dev/null +++ b/releasenotes/notes/case_insensitive_baggage_header_extraction-63167c492474da6f.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + tracer: This fix resolves an issue where baggage header extraction was case sensitive and didn't accept the header prepended with HTTP. + Now the baggage header will be extracted regardless of casing and the HTTP format. + diff --git a/tests/tracer/test_propagation.py b/tests/tracer/test_propagation.py index 61fec650a70..0d4c5d7c01d 100644 --- a/tests/tracer/test_propagation.py +++ b/tests/tracer/test_propagation.py @@ -1888,6 +1888,14 @@ def test_extract_tracecontext(headers, expected_context): B3_SINGLE_HEADERS_VALID, CONTEXT_EMPTY, ), + ( + "baggage_case_insensitive", + None, + {"BAgGage": "key1=val1,key2=val2"}, + { + "baggage": {"key1": "val1", "key2": "val2"}, + }, + ), # All valid headers ( "valid_all_headers_default_style", @@ -2278,14 +2286,14 @@ def test_propagation_extract_w_config(name, styles, headers, expected_context, r overrides = {} if styles is not None: overrides["_propagation_style_extract"] = styles - with override_global_config(overrides): - context = HTTPPropagator.extract(headers) - if not expected_context.get("tracestate"): - assert context == Context(**expected_context) - else: - copied_expectation = expected_context.copy() - tracestate = copied_expectation.pop("tracestate") - assert context == Context(**copied_expectation, meta={"tracestate": tracestate}) + with override_global_config(overrides): + context = HTTPPropagator.extract(headers) + if not expected_context.get("tracestate"): + assert context == Context(**expected_context) + else: + copied_expectation = expected_context.copy() + tracestate = copied_expectation.pop("tracestate") + assert context == Context(**copied_expectation, meta={"tracestate": tracestate}) EXTRACT_OVERRIDE_FIXTURES = [