Skip to content

Commit 3ba990f

Browse files
committed
revert celery propagate_traces
1 parent 3b493e1 commit 3ba990f

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

sentry_sdk/integrations/celery/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ class CeleryIntegration(Integration):
6262

6363
def __init__(
6464
self,
65+
propagate_traces=True,
6566
monitor_beat_tasks=False,
6667
exclude_beat_tasks=None,
6768
):
68-
# type: (bool, Optional[List[str]]) -> None
69+
# type: (bool, bool, Optional[List[str]]) -> None
70+
self.propagate_traces = propagate_traces
6971
self.monitor_beat_tasks = monitor_beat_tasks
7072
self.exclude_beat_tasks = exclude_beat_tasks
7173

@@ -252,6 +254,12 @@ def apply_async(*args, **kwargs):
252254
return f(*args, **kwargs)
253255

254256
kwarg_headers = kwargs.get("headers") or {}
257+
propagate_traces = kwarg_headers.pop(
258+
"sentry-propagate-traces", integration.propagate_traces
259+
)
260+
261+
if not propagate_traces:
262+
return f(*args, **kwargs)
255263

256264
if isinstance(args[0], Task):
257265
task_name = args[0].name # type: str

tests/integrations/celery/integration_tests/test_celery_beat_cron_monitoring.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ def celery_init(sentry_init, celery_config):
3434

3535
from sentry_sdk.integrations.celery import CeleryIntegration
3636

37-
def inner(monitor_beat_tasks=False, **kwargs):
37+
def inner(propagate_traces=True, monitor_beat_tasks=False, **kwargs):
3838
sentry_init(
3939
integrations=[
4040
CeleryIntegration(
41+
propagate_traces=propagate_traces,
4142
monitor_beat_tasks=monitor_beat_tasks,
4243
)
4344
],

tests/integrations/celery/test_celery.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ def inner(signal, f):
3030
@pytest.fixture
3131
def init_celery(sentry_init, request):
3232
def inner(
33+
propagate_traces=True,
3334
backend="always_eager",
3435
monitor_beat_tasks=False,
3536
**kwargs,
3637
):
3738
sentry_init(
3839
integrations=[
3940
CeleryIntegration(
41+
propagate_traces=propagate_traces,
4042
monitor_beat_tasks=monitor_beat_tasks,
4143
)
4244
],
@@ -533,7 +535,9 @@ def test_sentry_propagate_traces_override(init_celery):
533535
Test if the `sentry-propagate-traces` header given to `apply_async`
534536
overrides the `propagate_traces` parameter in the integration constructor.
535537
"""
536-
celery = init_celery(traces_sample_rate=1.0, release="abcdef")
538+
celery = init_celery(
539+
propagate_traces=True, traces_sample_rate=1.0, release="abcdef"
540+
)
537541

538542
# Since we're applying the task inline eagerly,
539543
# we need to cleanup the otel context for this test.

0 commit comments

Comments
 (0)