From 3b493e16dcac77891d664c21a5adbd68b3899ef0 Mon Sep 17 00:00:00 2001 From: nellaG Date: Sat, 2 Nov 2024 15:08:18 +0900 Subject: [PATCH 1/5] ref(celery): remove deprecated `propagate_traces` option `propagate_traces` is not documented and superseded by `trace_propagation_targets`. Refs #3106 --- sentry_sdk/consts.py | 1 - sentry_sdk/integrations/celery/__init__.py | 10 +--------- sentry_sdk/scope.py | 7 ------- .../test_celery_beat_cron_monitoring.py | 3 +-- tests/integrations/celery/test_celery.py | 6 +----- 5 files changed, 3 insertions(+), 24 deletions(-) diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 74d18ce80b..8207663905 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -511,7 +511,6 @@ def __init__( debug=None, # type: Optional[bool] attach_stacktrace=False, # type: bool ca_certs=None, # type: Optional[str] - propagate_traces=True, # type: bool traces_sample_rate=None, # type: Optional[float] traces_sampler=None, # type: Optional[TracesSampler] profiles_sample_rate=None, # type: Optional[float] diff --git a/sentry_sdk/integrations/celery/__init__.py b/sentry_sdk/integrations/celery/__init__.py index 238704fa68..8975db14d3 100644 --- a/sentry_sdk/integrations/celery/__init__.py +++ b/sentry_sdk/integrations/celery/__init__.py @@ -62,12 +62,10 @@ class CeleryIntegration(Integration): def __init__( self, - propagate_traces=True, monitor_beat_tasks=False, exclude_beat_tasks=None, ): - # type: (bool, bool, Optional[List[str]]) -> None - self.propagate_traces = propagate_traces + # type: (bool, Optional[List[str]]) -> None self.monitor_beat_tasks = monitor_beat_tasks self.exclude_beat_tasks = exclude_beat_tasks @@ -254,12 +252,6 @@ def apply_async(*args, **kwargs): return f(*args, **kwargs) kwarg_headers = kwargs.get("headers") or {} - propagate_traces = kwarg_headers.pop( - "sentry-propagate-traces", integration.propagate_traces - ) - - if not propagate_traces: - return f(*args, **kwargs) if isinstance(args[0], Task): task_name = args[0].name # type: str diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index bf4a62ab01..43cb94a32d 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -610,13 +610,6 @@ def iter_trace_propagation_headers(self, *args, **kwargs): If no span is given, the trace data is taken from the scope. """ 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) span = span or self.span diff --git a/tests/integrations/celery/integration_tests/test_celery_beat_cron_monitoring.py b/tests/integrations/celery/integration_tests/test_celery_beat_cron_monitoring.py index 53f2f63215..20539a1af2 100644 --- a/tests/integrations/celery/integration_tests/test_celery_beat_cron_monitoring.py +++ b/tests/integrations/celery/integration_tests/test_celery_beat_cron_monitoring.py @@ -34,11 +34,10 @@ def celery_init(sentry_init, celery_config): from sentry_sdk.integrations.celery import CeleryIntegration - def inner(propagate_traces=True, monitor_beat_tasks=False, **kwargs): + def inner(monitor_beat_tasks=False, **kwargs): sentry_init( integrations=[ CeleryIntegration( - propagate_traces=propagate_traces, monitor_beat_tasks=monitor_beat_tasks, ) ], diff --git a/tests/integrations/celery/test_celery.py b/tests/integrations/celery/test_celery.py index 241c79dc9d..705bf258fc 100644 --- a/tests/integrations/celery/test_celery.py +++ b/tests/integrations/celery/test_celery.py @@ -30,7 +30,6 @@ def inner(signal, f): @pytest.fixture def init_celery(sentry_init, request): def inner( - propagate_traces=True, backend="always_eager", monitor_beat_tasks=False, **kwargs, @@ -38,7 +37,6 @@ def inner( sentry_init( integrations=[ CeleryIntegration( - propagate_traces=propagate_traces, monitor_beat_tasks=monitor_beat_tasks, ) ], @@ -535,9 +533,7 @@ 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" - ) + celery = init_celery(traces_sample_rate=1.0, release="abcdef") # Since we're applying the task inline eagerly, # we need to cleanup the otel context for this test. From 3ba990f239f4309f4a4d7c8740c58e48d17680b6 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 27 Mar 2025 13:29:12 +0100 Subject: [PATCH 2/5] revert celery propagate_traces --- sentry_sdk/integrations/celery/__init__.py | 10 +++++++++- .../test_celery_beat_cron_monitoring.py | 3 ++- tests/integrations/celery/test_celery.py | 6 +++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/integrations/celery/__init__.py b/sentry_sdk/integrations/celery/__init__.py index 8975db14d3..238704fa68 100644 --- a/sentry_sdk/integrations/celery/__init__.py +++ b/sentry_sdk/integrations/celery/__init__.py @@ -62,10 +62,12 @@ class CeleryIntegration(Integration): def __init__( self, + propagate_traces=True, monitor_beat_tasks=False, exclude_beat_tasks=None, ): - # type: (bool, Optional[List[str]]) -> None + # type: (bool, bool, Optional[List[str]]) -> None + self.propagate_traces = propagate_traces self.monitor_beat_tasks = monitor_beat_tasks self.exclude_beat_tasks = exclude_beat_tasks @@ -252,6 +254,12 @@ def apply_async(*args, **kwargs): return f(*args, **kwargs) kwarg_headers = kwargs.get("headers") or {} + propagate_traces = kwarg_headers.pop( + "sentry-propagate-traces", integration.propagate_traces + ) + + if not propagate_traces: + return f(*args, **kwargs) if isinstance(args[0], Task): task_name = args[0].name # type: str diff --git a/tests/integrations/celery/integration_tests/test_celery_beat_cron_monitoring.py b/tests/integrations/celery/integration_tests/test_celery_beat_cron_monitoring.py index 20539a1af2..53f2f63215 100644 --- a/tests/integrations/celery/integration_tests/test_celery_beat_cron_monitoring.py +++ b/tests/integrations/celery/integration_tests/test_celery_beat_cron_monitoring.py @@ -34,10 +34,11 @@ def celery_init(sentry_init, celery_config): from sentry_sdk.integrations.celery import CeleryIntegration - def inner(monitor_beat_tasks=False, **kwargs): + def inner(propagate_traces=True, monitor_beat_tasks=False, **kwargs): sentry_init( integrations=[ CeleryIntegration( + propagate_traces=propagate_traces, monitor_beat_tasks=monitor_beat_tasks, ) ], diff --git a/tests/integrations/celery/test_celery.py b/tests/integrations/celery/test_celery.py index 705bf258fc..241c79dc9d 100644 --- a/tests/integrations/celery/test_celery.py +++ b/tests/integrations/celery/test_celery.py @@ -30,6 +30,7 @@ def inner(signal, f): @pytest.fixture def init_celery(sentry_init, request): def inner( + propagate_traces=True, backend="always_eager", monitor_beat_tasks=False, **kwargs, @@ -37,6 +38,7 @@ def inner( sentry_init( integrations=[ CeleryIntegration( + propagate_traces=propagate_traces, monitor_beat_tasks=monitor_beat_tasks, ) ], @@ -533,7 +535,9 @@ 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(traces_sample_rate=1.0, release="abcdef") + celery = init_celery( + propagate_traces=True, traces_sample_rate=1.0, release="abcdef" + ) # Since we're applying the task inline eagerly, # we need to cleanup the otel context for this test. From 52afe0d278301e76392f69ff43130bdfdb5d5799 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 27 Mar 2025 13:30:24 +0100 Subject: [PATCH 3/5] migration guide --- MIGRATION_GUIDE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index d57696d910..3d807d795a 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -134,6 +134,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh - Spans no longer have a `description`. Use `name` instead. - Dropped support for Python 3.6. - The `enable_tracing` `init` option has been removed. Configure `traces_sample_rate` directly. +- The `propagate_traces` `init` option has been removed. Use `trace_propagation_targets` instead. - The `custom_sampling_context` parameter of `start_transaction` has been removed. Use `attributes` instead to set key-value pairs of data that should be accessible in the traces sampler. Note that span attributes need to conform to the [OpenTelemetry specification](https://opentelemetry.io/docs/concepts/signals/traces/#attributes), meaning only certain types can be set as values. - The PyMongo integration no longer sets tags. The data is still accessible via span attributes. - The PyMongo integration doesn't set `operation_ids` anymore. The individual IDs (`operation_id`, `request_id`, `session_id`) are now accessible as separate span attributes. From 6c17361d6279ea25f90f24113631d295f84b820a Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 27 Mar 2025 13:33:15 +0100 Subject: [PATCH 4/5] also remove from docstring --- sentry_sdk/consts.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 8207663905..1fc920ac52 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -914,8 +914,6 @@ def __init__( :param profile_session_sample_rate: - :param propagate_traces: - :param auto_session_tracking: :param spotlight: From d86d58538385dedc474da2291fe655a97f818311 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 27 Mar 2025 13:33:33 +0100 Subject: [PATCH 5/5] remove test for deprecation --- tests/tracing/test_integration_tests.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/tests/tracing/test_integration_tests.py b/tests/tracing/test_integration_tests.py index 6fa9d66964..e6e436dbd2 100644 --- a/tests/tracing/test_integration_tests.py +++ b/tests/tracing/test_integration_tests.py @@ -117,20 +117,6 @@ def test_continue_trace(sentry_init, capture_envelopes, sample_rate): # noqa:N8 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_span(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,