From 353453367ee8fae6017ded1af60e056f264e46cb Mon Sep 17 00:00:00 2001 From: ZStriker19 Date: Thu, 9 Jan 2025 14:02:35 -0500 Subject: [PATCH] cover case of only span_link --- ddtrace/contrib/trace_utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ddtrace/contrib/trace_utils.py b/ddtrace/contrib/trace_utils.py index 5694ff6300..75a44d3db5 100644 --- a/ddtrace/contrib/trace_utils.py +++ b/ddtrace/contrib/trace_utils.py @@ -564,7 +564,8 @@ 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 and not context._baggage: + # The new context must have one of these values in order for it to be activated + if not context.trace_id and not context._baggage and not context._span_links: return None # Do not reactivate a context with the same trace id # DEV: An example could be nested web frameworks, when one layer already @@ -576,8 +577,8 @@ def activate_distributed_headers(tracer, int_config=None, request_headers=None, # app = DDWSGIMiddleware(app) # Extra layer on top for WSGI current_context = tracer.current_trace_context() - # We accept incoming contexts with only baggage, however if we - # already have a current_context then a baggage only context will be tossed out + # We accept incoming contexts with only baggage or only span_links, however if we + # already have a current_context then a baggage only or span_link only context will be tossed out if current_context and (not context.trace_id or 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