From e311995daa07daca807a00a90d195f09b6ebf739 Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Wed, 15 Oct 2025 11:45:12 -0700 Subject: [PATCH 01/10] remove deprecated non_active_span argument --- ddtrace/propagation/http.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/ddtrace/propagation/http.py b/ddtrace/propagation/http.py index 5a0101d351e..d675ea3504e 100644 --- a/ddtrace/propagation/http.py +++ b/ddtrace/propagation/http.py @@ -1121,7 +1121,7 @@ def _resolve_contexts(contexts, styles_w_ctx, normalized_headers): return primary_context @staticmethod - def inject(context: Union[Context, Span], headers: Dict[str, str], non_active_span: Optional[Span] = None) -> None: + def inject(context: Union[Context, Span], headers: Dict[str, str]) -> None: """Inject Context attributes that have to be propagated as HTTP headers. Here is an example using `requests`:: @@ -1150,26 +1150,16 @@ def parent_call(): Span objects automatically trigger sampling decisions. Context objects should have sampling_priority set to avoid inconsistent downstream sampling. :param dict headers: HTTP headers to extend with tracing attributes. - :param Span non_active_span: **DEPRECATED** - Pass Span objects to the context parameter instead. """ - if non_active_span is not None: - # non_active_span is only used for sampling decisions, not to inject headers. - deprecate( - "The non_active_span parameter is deprecated", - message="Use the context parameter instead.", - category=DDTraceDeprecationWarning, - removal_version="4.0.0", - ) # Cannot rename context parameter due to backwards compatibility # Handle sampling and get context for header injection - span_context = HTTPPropagator._get_sampled_injection_context(context, non_active_span) + span_context = HTTPPropagator._get_sampled_injection_context(context, None) # Log a warning if we cannot determine a sampling decision before injecting headers. if span_context.span_id and span_context.trace_id and span_context.sampling_priority is None: log.debug( "Sampling decision not available. Downstream spans will not inherit a sampling priority: " - "args=(context=%s, ..., non_active_span=%s) detected span context=%s", + "args=(context=%s, ...) detected span context=%s", context, - non_active_span, span_context, ) From 815fe7c85f14b51767cfabcd7b8b70e45b700ae8 Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Sat, 18 Oct 2025 15:04:45 -0400 Subject: [PATCH 02/10] remove unused imports --- ddtrace/propagation/http.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ddtrace/propagation/http.py b/ddtrace/propagation/http.py index d675ea3504e..d9c56f92ed2 100644 --- a/ddtrace/propagation/http.py +++ b/ddtrace/propagation/http.py @@ -22,10 +22,8 @@ from ddtrace.internal import core from ddtrace.internal.telemetry import telemetry_writer from ddtrace.internal.telemetry.constants import TELEMETRY_NAMESPACE -from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning from ddtrace.settings._config import config from ddtrace.settings.asm import config as asm_config -from ddtrace.vendor.debtcollector import deprecate from ..constants import AUTO_KEEP from ..constants import AUTO_REJECT From 28788c9054362246ad5c6d46f29afef0923e899d Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Fri, 24 Oct 2025 07:36:27 -0700 Subject: [PATCH 03/10] lint --- tests/contrib/yaaredis/test_yaaredis.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/contrib/yaaredis/test_yaaredis.py b/tests/contrib/yaaredis/test_yaaredis.py index 84185652ba0..d3fa5743b70 100644 --- a/tests/contrib/yaaredis/test_yaaredis.py +++ b/tests/contrib/yaaredis/test_yaaredis.py @@ -9,7 +9,6 @@ from ddtrace.contrib.internal.yaaredis.patch import patch from ddtrace.contrib.internal.yaaredis.patch import unpatch from ddtrace.internal.compat import is_wrapted -from tests.opentracer.utils import init_tracer from tests.utils import override_config from ..config import REDIS_CONFIG From 25726041ad1de4a5d75dee8854be18ef87659223 Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Fri, 24 Oct 2025 07:37:51 -0700 Subject: [PATCH 04/10] reno --- releasenotes/notes/non-active-span-3398e88b19eb94c3.yaml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 releasenotes/notes/non-active-span-3398e88b19eb94c3.yaml diff --git a/releasenotes/notes/non-active-span-3398e88b19eb94c3.yaml b/releasenotes/notes/non-active-span-3398e88b19eb94c3.yaml new file mode 100644 index 00000000000..32eef0cfafe --- /dev/null +++ b/releasenotes/notes/non-active-span-3398e88b19eb94c3.yaml @@ -0,0 +1,4 @@ +--- +other: + - | + This change removes the deprecated non_active_span parameter to `HttpPropagator.inject` From acc18eba7edfd11570f3116c787d6ef775483ccd Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Fri, 24 Oct 2025 09:29:20 -0700 Subject: [PATCH 05/10] fix a couple of tests --- .../internal/grpc/client_interceptor.py | 3 +- tests/commands/ddtrace_run_logs_injection.py | 1 + tests/tracer/test_propagation.py | 78 ------------------- 3 files changed, 2 insertions(+), 80 deletions(-) diff --git a/ddtrace/contrib/internal/grpc/client_interceptor.py b/ddtrace/contrib/internal/grpc/client_interceptor.py index e55ea67fc50..cf9727c8543 100644 --- a/ddtrace/contrib/internal/grpc/client_interceptor.py +++ b/ddtrace/contrib/internal/grpc/client_interceptor.py @@ -225,8 +225,7 @@ def _intercept_client_call(self, method_kind, client_call_details): # propagate distributed tracing headers if available headers = {} if config.grpc.distributed_tracing_enabled: - # NOTE: We need to pass the span to the HTTPPropagator since it isn't active at this point - HTTPPropagator.inject(span.context, headers, span) + HTTPPropagator.inject(span.context, headers) metadata = [] if client_call_details.metadata is not None: diff --git a/tests/commands/ddtrace_run_logs_injection.py b/tests/commands/ddtrace_run_logs_injection.py index 3a08ba3736d..3691830c566 100644 --- a/tests/commands/ddtrace_run_logs_injection.py +++ b/tests/commands/ddtrace_run_logs_injection.py @@ -4,6 +4,7 @@ if __name__ == "__main__": # Ensure if module is patched then default log formatter is set up for logs ddtrace_logger = logging.getLogger("ddtrace") + print(ddtrace_logger.handlers) if logging._datadog_patch: assert ( "[dd.service=%(dd.service)s dd.env=%(dd.env)s dd.version=%(dd.version)s" diff --git a/tests/tracer/test_propagation.py b/tests/tracer/test_propagation.py index eee54604355..271f0234551 100644 --- a/tests/tracer/test_propagation.py +++ b/tests/tracer/test_propagation.py @@ -3579,84 +3579,6 @@ def test_baggage_span_tags_wildcard(): assert "baggage.session.id" not in context._meta -def test_inject_non_active_span_parameter_deprecated(): - """Test that the non_active_span parameter triggers a deprecation warning.""" - headers = {} - with ddtracer.start_span("non_active_span") as span: - assert span.context.sampling_priority is None # No sampling decision yet - with pytest.warns() as warnings_list: - HTTPPropagator.inject(context=Context(), headers=headers, non_active_span=span) - assert span.context.sampling_priority is not None # Sampling should be triggered - assert not headers, f"No headers should be injected, Context is empty: {headers}" - - # Should capture exactly one deprecation warning - assert len(warnings_list) == 1 - assert "non_active_span parameter is deprecated" in str(warnings_list[0].message) - - -def test_inject_context_and_span_same_trace_deprecated(): - """Test injecting Context + non_active_span from the same trace (parent-child).""" - headers = {} - with ddtracer.trace("parent") as parent: - with ddtracer.start_span("child", child_of=parent) as non_active_child: - assert non_active_child.context.sampling_priority is None # No sampling yet - assert ddtracer.current_span() is not non_active_child # Child is not active - with mock.patch("ddtrace.propagation.http.log.debug") as mock_debug, pytest.warns() as warnings_list: - HTTPPropagator.inject( - context=non_active_child.context, headers=headers, non_active_span=non_active_child - ) - # Sampling decision should be set on root span even when child is used for propagation - assert parent.context.sampling_priority is not None - assert non_active_child.context.sampling_priority is not None - - mock_debug.assert_has_calls( - [ - mock.call( - "%s sampled before propagating trace: span_context=%s", - non_active_child._local_root, - non_active_child.context, - ) - ] - ) - assert headers.get("x-datadog-sampling-priority") == str(parent.context.sampling_priority) - # Parent span info propagated (context takes precedence over non_active_span) - # Non_active_span is only used to make a sampling decision, not to inject headers. - assert headers.get("x-datadog-parent-id") == str(non_active_child.span_id) - - # Should capture deprecation warning - assert len(warnings_list) == 1 - assert "non_active_span parameter is deprecated" in str(warnings_list[0].message) - - -def test_inject_context_and_span_different_trace_deprecated(): - """Test injecting Context + non_active_span from completely different traces.""" - headers = {} - with ddtracer.start_span("span1", child_of=None) as span1: - with ddtracer.start_span("span2", child_of=None) as span2: - with mock.patch("ddtrace.propagation.http.log.debug") as mock_debug, pytest.warns() as warnings_list: - HTTPPropagator.inject(context=span1.context, headers=headers, non_active_span=span2) - - mock_debug.assert_has_calls( - [ - mock.call( - "Sampling decision not available. Downstream spans will not inherit a sampling priority" - ": args=(context=%s, ..., non_active_span=%s) detected span context=%s", - span1.context, - span2, - span1.context, - ) - ] - ) - - # Span1 span info propagated (context takes precedence over Span2) - # non_active_span parameter is only used to make a sampling decision, not to inject headers. - assert headers.get("x-datadog-parent-id") == str(span1.span_id) - - # Should capture deprecation warning - assert len(warnings_list) == 1 - assert "non_active_span parameter is deprecated" in str(warnings_list[0].message) - - def test_inject_context_without_sampling_priority_active_trace(): """Test injecting a Context without sampling priority when there's an active trace.""" headers = {} From 0606a788c76862bf702431b8b61b36e8b4b740b3 Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Fri, 24 Oct 2025 09:49:05 -0700 Subject: [PATCH 06/10] print statement breaks test --- tests/commands/ddtrace_run_logs_injection.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/commands/ddtrace_run_logs_injection.py b/tests/commands/ddtrace_run_logs_injection.py index 3691830c566..3a08ba3736d 100644 --- a/tests/commands/ddtrace_run_logs_injection.py +++ b/tests/commands/ddtrace_run_logs_injection.py @@ -4,7 +4,6 @@ if __name__ == "__main__": # Ensure if module is patched then default log formatter is set up for logs ddtrace_logger = logging.getLogger("ddtrace") - print(ddtrace_logger.handlers) if logging._datadog_patch: assert ( "[dd.service=%(dd.service)s dd.env=%(dd.env)s dd.version=%(dd.version)s" From 6c0bcd2c5d5f30f81618a7a2f7a8285a54f85583 Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Fri, 24 Oct 2025 09:50:54 -0700 Subject: [PATCH 07/10] delete test that no longer applies --- tests/contrib/grpc/test_grpc.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/tests/contrib/grpc/test_grpc.py b/tests/contrib/grpc/test_grpc.py index f45b8b2190e..34b689eb96a 100644 --- a/tests/contrib/grpc/test_grpc.py +++ b/tests/contrib/grpc/test_grpc.py @@ -339,21 +339,6 @@ def callback(response): self._check_client_span(client_span, "grpc-client", "SayHelloRepeatedly", "bidi_streaming") self._check_server_span(server_span, "grpc-server", "SayHelloRepeatedly", "bidi_streaming") - def test_priority_sampling(self): - # DEV: Priority sampling is enabled by default - # Setting priority sampling reset the writer, we need to re-override it - - with grpc.insecure_channel("127.0.0.1:%d" % (_GRPC_PORT)) as channel: - stub = HelloStub(channel) - response = stub.SayHello(HelloRequest(name="propogator")) - - spans = self.get_spans_with_sync_and_assert(size=2) - client_span, server_span = spans - assert f"x-datadog-trace-id={str(client_span._trace_id_64bits)}" in response.message - assert f"_dd.p.tid={_get_64_highest_order_bits_as_hex(client_span.trace_id)}" in response.message - assert "x-datadog-parent-id={}".format(client_span.span_id) in response.message - assert "x-datadog-sampling-priority=1" in response.message - def test_unary_abort(self): with grpc.secure_channel("127.0.0.1:%d" % (_GRPC_PORT), credentials=grpc.ChannelCredentials(None)) as channel: stub = HelloStub(channel) From 6f7accb28e71534839773bdada6c54e555de2c32 Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Fri, 24 Oct 2025 09:57:07 -0700 Subject: [PATCH 08/10] unused import --- tests/contrib/grpc/test_grpc.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/contrib/grpc/test_grpc.py b/tests/contrib/grpc/test_grpc.py index 34b689eb96a..cf8049ef966 100644 --- a/tests/contrib/grpc/test_grpc.py +++ b/tests/contrib/grpc/test_grpc.py @@ -6,7 +6,6 @@ import pytest from ddtrace._trace.pin import Pin -from ddtrace._trace.span import _get_64_highest_order_bits_as_hex from ddtrace.constants import ERROR_MSG from ddtrace.constants import ERROR_STACK from ddtrace.constants import ERROR_TYPE From f718108e619934fd0aff07c0aa9d38562b067483 Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Fri, 24 Oct 2025 10:33:36 -0700 Subject: [PATCH 09/10] adjust test expectation --- tests/tracer/test_propagation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tracer/test_propagation.py b/tests/tracer/test_propagation.py index 271f0234551..a5f0533ccd9 100644 --- a/tests/tracer/test_propagation.py +++ b/tests/tracer/test_propagation.py @@ -3615,7 +3615,7 @@ def test_inject_context_without_sampling_priority_inactive_trace(): [ mock.call( "Sampling decision not available. Downstream spans will not inherit a sampling priority" - ": args=(context=%s, ..., non_active_span=%s) detected span context=%s", + ": args=(context=%s, ...) detected span context=%s", span.context, None, span.context, From 1434c6573b3fe04a7eceb1c1101dfc024dbf428b Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Fri, 24 Oct 2025 11:06:01 -0700 Subject: [PATCH 10/10] fix text expectation --- tests/tracer/test_propagation.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/tracer/test_propagation.py b/tests/tracer/test_propagation.py index a5f0533ccd9..a6ea2de15c2 100644 --- a/tests/tracer/test_propagation.py +++ b/tests/tracer/test_propagation.py @@ -3617,7 +3617,6 @@ def test_inject_context_without_sampling_priority_inactive_trace(): "Sampling decision not available. Downstream spans will not inherit a sampling priority" ": args=(context=%s, ...) detected span context=%s", span.context, - None, span.context, ) ]