Skip to content

Commit

Permalink
ref(celery): remove deprecated propagate_traces option
Browse files Browse the repository at this point in the history
`propagate_traces` is not documented and superseded by
`trace_propagation_targets`.

Refs #3106
  • Loading branch information
nellaG committed Nov 2, 2024
1 parent 5e2d2cf commit b8ef896
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 44 deletions.
1 change: 0 additions & 1 deletion sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,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]
Expand Down
10 changes: 1 addition & 9 deletions sentry_sdk/integrations/celery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,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

Expand Down Expand Up @@ -257,12 +255,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
Expand Down
2 changes: 0 additions & 2 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,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"):
return

span = kwargs.pop("span", None)
span = span or self.span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
],
Expand Down
31 changes: 1 addition & 30 deletions tests/integrations/celery/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ 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,
):
sentry_init(
integrations=[
CeleryIntegration(
propagate_traces=propagate_traces,
monitor_beat_tasks=monitor_beat_tasks,
)
],
Expand Down Expand Up @@ -267,24 +265,6 @@ def dummy_task():
assert not sentry_sdk.get_isolation_scope()._tags


def test_simple_no_propagation(capture_events, init_celery):
celery = init_celery(propagate_traces=False)
events = capture_events()

@celery.task(name="dummy_task")
def dummy_task():
1 / 0

with start_transaction() as transaction:
dummy_task.delay()

(event,) = events
assert event["contexts"]["trace"]["trace_id"] != transaction.trace_id
assert event["transaction"] == "dummy_task"
(exception,) = event["exception"]["values"]
assert exception["type"] == "ZeroDivisionError"


def test_ignore_expected(capture_events, celery):
events = capture_events()

Expand Down Expand Up @@ -532,9 +512,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")

@celery.task(name="dummy_task", bind=True)
def dummy_task(self, message):
Expand All @@ -550,13 +528,6 @@ def dummy_task(self, message):
).get()
assert transaction_trace_id == task_transaction_id

# should NOT propagate trace (overrides `propagate_traces` parameter in integration constructor)
task_transaction_id = dummy_task.apply_async(
args=("another message",),
headers={"sentry-propagate-traces": False},
).get()
assert transaction_trace_id != task_transaction_id


def test_apply_async_manually_span(sentry_init):
sentry_init(
Expand Down

0 comments on commit b8ef896

Please sign in to comment.