Skip to content

Commit 37830aa

Browse files
authored
fix(celery): Add functools.wraps to wrapped Task methods (getsentry#432)
Fix getsentry#421
1 parent ce3b49f commit 37830aa

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

sentry_sdk/integrations/celery.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import absolute_import
22

3+
import functools
34
import sys
45

56
from celery.exceptions import ( # type: ignore
@@ -64,6 +65,7 @@ def sentry_build_tracer(name, task, *args, **kwargs):
6465

6566

6667
def _wrap_apply_async(task, f):
68+
@functools.wraps(f)
6769
def apply_async(*args, **kwargs):
6870
hub = Hub.current
6971
integration = hub.get_integration(CeleryIntegration)
@@ -87,6 +89,7 @@ def _wrap_tracer(task, f):
8789
# This is the reason we don't use signals for hooking in the first place.
8890
# Also because in Celery 3, signal dispatch returns early if one handler
8991
# crashes.
92+
@functools.wraps(f)
9093
def _inner(*args, **kwargs):
9194
hub = Hub.current
9295
if hub.get_integration(CeleryIntegration) is None:
@@ -114,6 +117,11 @@ def _inner(*args, **kwargs):
114117
def _wrap_task_call(task, f):
115118
# Need to wrap task call because the exception is caught before we get to
116119
# see it. Also celery's reported stacktrace is untrustworthy.
120+
121+
# functools.wraps is important here because celery-once looks at this
122+
# method's name.
123+
# https://github.com/getsentry/sentry-python/issues/421
124+
@functools.wraps(f)
117125
def _inner(*args, **kwargs):
118126
try:
119127
return f(*args, **kwargs)

0 commit comments

Comments
 (0)