Skip to content

Commit

Permalink
feat(tracing): Add propagate_traces deprecation warning
Browse files Browse the repository at this point in the history
Fixes GH-3106
  • Loading branch information
mgaligniana committed Jan 3, 2025
1 parent bb85c26 commit 5e15320
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
8 changes: 8 additions & 0 deletions sentry_sdk/integrations/celery/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import sys
import warnings

from collections.abc import Mapping
from functools import wraps

Expand Down Expand Up @@ -67,6 +69,12 @@ def __init__(
monitor_beat_tasks=False,
exclude_beat_tasks=None,
):
warnings.warn(
"The `propagate_traces` parameter is deprecated. "
"Please use `trace_propagation_targets` instead.",
DeprecationWarning,
stacklevel=2,
)
# type: (bool, bool, Optional[List[str]]) -> None
self.propagate_traces = propagate_traces
self.monitor_beat_tasks = monitor_beat_tasks
Expand Down
5 changes: 5 additions & 0 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions tests/integrations/celery/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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):
Expand Down
14 changes: 14 additions & 0 deletions tests/tracing/test_integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5e15320

Please sign in to comment.