Skip to content

Commit

Permalink
don't drop extract contexts lacking trace_id
Browse files Browse the repository at this point in the history
  • Loading branch information
ZStriker19 committed Jan 7, 2025
1 parent 290d9e6 commit 87532da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions ddtrace/contrib/trace_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def activate_distributed_headers(tracer, int_config=None, request_headers=None,
context = HTTPPropagator.extract(request_headers)

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

# Do not reactivate a context with the same trace id
Expand All @@ -577,7 +577,7 @@ def activate_distributed_headers(tracer, int_config=None, request_headers=None,
# app = Flask(__name__) # Traced via Flask instrumentation
# app = DDWSGIMiddleware(app) # Extra layer on top for WSGI
current_context = tracer.current_trace_context()
if current_context and current_context.trace_id == context.trace_id:
if current_context and current_context.trace_id and current_context.trace_id == context.trace_id:
log.debug(
"will not activate extracted Context(trace_id=%r, span_id=%r), a context with that trace id is already active", # noqa: E501
context.trace_id,
Expand Down
16 changes: 8 additions & 8 deletions tests/tracer/test_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2494,14 +2494,14 @@ def test_propagation_extract_w_config(
overrides["_propagation_style_extract"] = styles
if extract_behavior is not None:
overrides["_propagation_behavior_extract"] = extract_behavior
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 = [
Expand Down

0 comments on commit 87532da

Please sign in to comment.