Skip to content

Commit 4038bdc

Browse files
committed
fix: Missing traceback in celery
Fix #107
1 parent 7ec22b0 commit 4038bdc

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

sentry_sdk/integrations/celery.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import absolute_import
22

3+
import sys
4+
35
from celery.signals import task_failure, task_prerun, task_postrun
46
from celery.exceptions import SoftTimeLimitExceeded
57

@@ -20,6 +22,9 @@ def install(self):
2022
task_failure.connect(self._process_failure_signal, weak=False)
2123

2224
def _process_failure_signal(self, sender, task_id, einfo, **kw):
25+
# einfo from celery is not reliable
26+
exc_info = sys.exc_info()
27+
2328
if hasattr(sender, "throws") and isinstance(einfo.exception, sender.throws):
2429
return
2530

@@ -33,9 +38,9 @@ def _process_failure_signal(self, sender, task_id, einfo, **kw):
3338
getattr(sender, "name", sender),
3439
]
3540

36-
self._capture_event(hub, einfo.exc_info)
41+
self._capture_event(hub, exc_info)
3742
else:
38-
self._capture_event(hub, einfo.exc_info)
43+
self._capture_event(hub, exc_info)
3944

4045
def _capture_event(self, hub, exc_info):
4146
event, hint = event_from_exception(

tests/integrations/celery/test_celery.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def test_simple(capture_events, celery):
2020

2121
@celery.task(name="dummy_task")
2222
def dummy_task(x, y):
23+
foo = 42
2324
return x / y
2425

2526
dummy_task.delay(1, 2)
@@ -29,9 +30,8 @@ def dummy_task(x, y):
2930

3031
exception, = event["exception"]["values"]
3132
assert exception["type"] == "ZeroDivisionError"
32-
33-
event, = events
34-
assert event["exception"]["values"][0]["mechanism"]["type"] == "celery"
33+
assert exception["mechanism"]["type"] == "celery"
34+
assert exception["stacktrace"]["frames"][1]["vars"]["foo"] == "42"
3535

3636

3737
def test_ignore_expected(capture_events, celery):

0 commit comments

Comments
 (0)