Skip to content

Commit c6c36ff

Browse files
Vlad Vladovdivaltor
authored andcommitted
Add wrapper for Celery().send_task to support behavior as Task.apply_async
1 parent 2f05ccb commit c6c36ff

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

sentry_sdk/integrations/celery.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ def sentry_build_tracer(name, task, *args, **kwargs):
108108
trace.build_tracer = sentry_build_tracer
109109

110110
from celery.app.task import Task # type: ignore
111+
from celery import Celery # type: ignore
111112

112113
Task.apply_async = _wrap_apply_async(Task.apply_async)
114+
Celery.send_task = _wrap_apply_async(Celery.send_task)
113115

114116
_patch_worker_exit()
115117

tests/integrations/celery/test_celery.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,12 @@ def dummy_task(self):
359359

360360

361361
# TODO: This test is hanging when running test with `tox --parallel auto`. Find out why and fix it!
362-
@pytest.mark.skip
362+
# @pytest.mark.skip
363363
@pytest.mark.forked
364-
def test_redis_backend_trace_propagation(init_celery, capture_events_forksafe):
364+
@pytest.mark.parametrize("execution_way", ["apply_async", "send_task"])
365+
def test_redis_backend_trace_propagation(
366+
init_celery, capture_events_forksafe, execution_way
367+
):
365368
celery = init_celery(traces_sample_rate=1.0, backend="redis", debug=True)
366369

367370
events = capture_events_forksafe()
@@ -375,7 +378,12 @@ def dummy_task(self):
375378

376379
with start_transaction(name="submit_celery"):
377380
# Curious: Cannot use delay() here or py2.7-celery-4.2 crashes
378-
res = dummy_task.apply_async()
381+
if execution_way == "apply_async":
382+
res = dummy_task.apply_async()
383+
elif execution_way == "send_task":
384+
res = celery.send_task("dummy_task")
385+
else: # pragma: no cover
386+
raise ValueError(execution_way)
379387

380388
with pytest.raises(Exception): # noqa: B017
381389
# Celery 4.1 raises a gibberish exception

0 commit comments

Comments
 (0)