Skip to content

Commit

Permalink
fix extracting baggage and update so that baggage only context is used
Browse files Browse the repository at this point in the history
  • Loading branch information
ZStriker19 committed Jan 8, 2025
1 parent 87532da commit b32a467
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 1 addition & 3 deletions ddtrace/contrib/trace_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,14 +560,12 @@ def activate_distributed_headers(tracer, int_config=None, request_headers=None,
"""
if override is False:
return None

if override or (int_config and distributed_tracing_enabled(int_config)):
context = HTTPPropagator.extract(request_headers)

# Only need to activate the new context if something was propagated
if not context.trace_id or context._baggage:
if not context.trace_id and not context._baggage:
return None

# Do not reactivate a context with the same trace id
# DEV: An example could be nested web frameworks, when one layer already
# parsed request headers and activated them.
Expand Down
3 changes: 2 additions & 1 deletion ddtrace/propagation/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,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
Expand Down Expand Up @@ -939,7 +940,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={})
Expand Down

0 comments on commit b32a467

Please sign in to comment.