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