@@ -61,7 +61,6 @@ def sentry_build_tracer(name, task, *args, **kwargs):
61
61
# short-circuits to task.run if it thinks it's safe.
62
62
task .__call__ = _wrap_task_call (task , task .__call__ )
63
63
task .run = _wrap_task_call (task , task .run )
64
- task .apply_async = _wrap_apply_async (task , task .apply_async )
65
64
66
65
# `build_tracer` is apparently called for every task
67
66
# invocation. Can't wrap every celery task for every invocation
@@ -72,6 +71,10 @@ def sentry_build_tracer(name, task, *args, **kwargs):
72
71
73
72
trace .build_tracer = sentry_build_tracer
74
73
74
+ from celery .app .task import Task # type: ignore
75
+
76
+ Task .apply_async = _wrap_apply_async (Task .apply_async )
77
+
75
78
_patch_worker_exit ()
76
79
77
80
# This logger logs every status of every task that ran on the worker.
@@ -85,15 +88,15 @@ def sentry_build_tracer(name, task, *args, **kwargs):
85
88
ignore_logger ("celery.redirected" )
86
89
87
90
88
- def _wrap_apply_async (task , f ):
89
- # type: (Any, F) -> F
91
+ def _wrap_apply_async (f ):
92
+ # type: (F) -> F
90
93
@wraps (f )
91
94
def apply_async (* args , ** kwargs ):
92
95
# type: (*Any, **Any) -> Any
93
96
hub = Hub .current
94
97
integration = hub .get_integration (CeleryIntegration )
95
98
if integration is not None and integration .propagate_traces :
96
- with hub .start_span (op = "celery.submit" , description = task .name ):
99
+ with hub .start_span (op = "celery.submit" , description = args [ 0 ] .name ):
97
100
with capture_internal_exceptions ():
98
101
headers = dict (hub .iter_trace_propagation_headers ())
99
102
0 commit comments