@@ -329,9 +329,6 @@ def _inner(*args: "Any", **kwargs: "Any") -> "Any":
329329 scope .clear_breadcrumbs ()
330330 scope .add_event_processor (_make_event_processor (task , * args , ** kwargs ))
331331
332- span : "Optional[Union[Span, StreamedSpan]]" = None
333- span_ctx : "Optional[Union[Span, StreamedSpan]]" = None
334-
335332 custom_sampling_context = {
336333 "celery_job" : {
337334 "task" : task .name ,
@@ -345,6 +342,9 @@ def _inner(*args: "Any", **kwargs: "Any") -> "Any":
345342 scope .set_custom_sampling_context (custom_sampling_context )
346343 scope .set_transaction_name (task .name , source = TransactionSource .TASK )
347344
345+ span : "Union[Span, StreamedSpan]"
346+ span_ctx : "Union[StreamedSpan, Span, NoOpMgr]" = NoOpMgr ()
347+
348348 # Celery task objects are not a thing to be trusted. Even
349349 # something such as attribute access can fail.
350350 with capture_internal_exceptions ():
@@ -377,9 +377,6 @@ def _inner(*args: "Any", **kwargs: "Any") -> "Any":
377377 custom_sampling_context = custom_sampling_context ,
378378 )
379379
380- if span is None or span_ctx is None :
381- return f (* args , ** kwargs )
382-
383380 with span_ctx :
384381 return f (* args , ** kwargs )
385382
0 commit comments