From 8a70b76f69789585efbd39fcef087005b765a346 Mon Sep 17 00:00:00 2001 From: Marcelo Galigniana Date: Tue, 14 Jan 2025 11:34:38 -0300 Subject: [PATCH] feat(tracing): Add `propagate_traces` deprecation warning (#3899) Fixes GH-3106 Co-authored-by: Anton Pirker --- sentry_sdk/integrations/celery/__init__.py | 7 +++++++ sentry_sdk/scope.py | 5 +++++ tests/integrations/celery/test_celery.py | 11 +++++++---- tests/tracing/test_integration_tests.py | 14 ++++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/sentry_sdk/integrations/celery/__init__.py b/sentry_sdk/integrations/celery/__init__.py index dc48aac0e6..80decb6064 100644 --- a/sentry_sdk/integrations/celery/__init__.py +++ b/sentry_sdk/integrations/celery/__init__.py @@ -1,4 +1,6 @@ import sys +import warnings + from collections.abc import Mapping from functools import wraps @@ -68,6 +70,11 @@ def __init__( exclude_beat_tasks=None, ): # type: (bool, bool, Optional[List[str]]) -> None + warnings.warn( + "The `propagate_traces` parameter is deprecated. Please use `trace_propagation_targets` instead.", + DeprecationWarning, + stacklevel=2, + ) self.propagate_traces = propagate_traces self.monitor_beat_tasks = monitor_beat_tasks self.exclude_beat_tasks = exclude_beat_tasks diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index ab0f1f4156..c22cdfb030 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -621,6 +621,11 @@ def iter_trace_propagation_headers(self, *args, **kwargs): """ client = self.get_client() if not client.options.get("propagate_traces"): + warnings.warn( + "The `propagate_traces` parameter is deprecated. Please use `trace_propagation_targets` instead.", + DeprecationWarning, + stacklevel=2, + ) return span = kwargs.pop("span", None) diff --git a/tests/integrations/celery/test_celery.py b/tests/integrations/celery/test_celery.py index e51341599f..f8d118e7e9 100644 --- a/tests/integrations/celery/test_celery.py +++ b/tests/integrations/celery/test_celery.py @@ -268,7 +268,9 @@ def dummy_task(): def test_simple_no_propagation(capture_events, init_celery): - celery = init_celery(propagate_traces=False) + with pytest.warns(DeprecationWarning): + celery = init_celery(propagate_traces=False) + events = capture_events() @celery.task(name="dummy_task") @@ -532,9 +534,10 @@ def test_sentry_propagate_traces_override(init_celery): Test if the `sentry-propagate-traces` header given to `apply_async` overrides the `propagate_traces` parameter in the integration constructor. """ - celery = init_celery( - propagate_traces=True, traces_sample_rate=1.0, release="abcdef" - ) + with pytest.warns(DeprecationWarning): + celery = init_celery( + propagate_traces=True, traces_sample_rate=1.0, release="abcdef" + ) @celery.task(name="dummy_task", bind=True) def dummy_task(self, message): diff --git a/tests/tracing/test_integration_tests.py b/tests/tracing/test_integration_tests.py index e27dbea901..da3efef9eb 100644 --- a/tests/tracing/test_integration_tests.py +++ b/tests/tracing/test_integration_tests.py @@ -138,6 +138,20 @@ def test_continue_from_headers(sentry_init, capture_envelopes, sampled, sample_r assert message_payload["message"] == "hello" +@pytest.mark.parametrize("sample_rate", [0.0, 1.0]) +def test_propagate_traces_deprecation_warning(sentry_init, sample_rate): + sentry_init(traces_sample_rate=sample_rate, propagate_traces=False) + + with start_transaction(name="hi"): + with start_span() as old_span: + with pytest.warns(DeprecationWarning): + dict( + sentry_sdk.get_current_scope().iter_trace_propagation_headers( + old_span + ) + ) + + @pytest.mark.parametrize("sample_rate", [0.5, 1.0]) def test_dynamic_sampling_head_sdk_creates_dsc( sentry_init, capture_envelopes, sample_rate, monkeypatch