2323 SENSITIVE_DATA_SUBSTITUTE ,
2424 capture_internal_exceptions ,
2525 event_from_exception ,
26- nullcontext ,
2726 reraise ,
2827)
2928
@@ -420,17 +419,17 @@ def _inner(*args: "Any", **kwargs: "Any") -> "Any":
420419 span_streaming = has_span_streaming_enabled (client .options )
421420
422421 try :
423- span_ctx : "Any"
422+ if span_streaming and get_current_span () is None :
423+ return f (* args , ** kwargs )
424+
424425 if span_streaming :
425- span_ctx = nullcontext ()
426- if get_current_span () is not None :
427- span_ctx = sentry_sdk .traces .start_span (
428- name = task .name ,
429- attributes = {
430- "sentry.op" : OP .QUEUE_PROCESS ,
431- "sentry.origin" : CeleryIntegration .origin ,
432- },
433- )
426+ span_ctx = sentry_sdk .traces .start_span (
427+ name = task .name ,
428+ attributes = {
429+ "sentry.op" : OP .QUEUE_PROCESS ,
430+ "sentry.origin" : CeleryIntegration .origin ,
431+ },
432+ )
434433 else :
435434 span_ctx = sentry_sdk .start_span (
436435 op = OP .QUEUE_PROCESS ,
@@ -439,44 +438,42 @@ def _inner(*args: "Any", **kwargs: "Any") -> "Any":
439438 )
440439
441440 with span_ctx as span :
442- if span is not None :
443- if isinstance (span , StreamedSpan ):
444- set_on_span = span .set_attribute
445- else :
446- set_on_span = span .set_data
447-
448- _set_messaging_destination_name (task , span )
449-
450- latency = None
451- with capture_internal_exceptions ():
452- if (
453- task .request .headers is not None
454- and "sentry-task-enqueued-time" in task .request .headers
455- ):
456- latency = (
457- _now_seconds_since_epoch ()
458- - task .request .headers .pop ("sentry-task-enqueued-time" )
459- )
460-
461- if latency is not None :
462- latency *= 1000 # milliseconds
463- set_on_span (SPANDATA .MESSAGING_MESSAGE_RECEIVE_LATENCY , latency )
464-
465- with capture_internal_exceptions ():
466- set_on_span (SPANDATA .MESSAGING_MESSAGE_ID , task .request .id )
467-
468- with capture_internal_exceptions ():
469- set_on_span (
470- SPANDATA .MESSAGING_MESSAGE_RETRY_COUNT ,
471- task .request .retries ,
441+ if isinstance (span , StreamedSpan ):
442+ set_on_span = span .set_attribute
443+ else :
444+ set_on_span = span .set_data
445+
446+ _set_messaging_destination_name (task , span )
447+
448+ latency = None
449+ with capture_internal_exceptions ():
450+ if (
451+ task .request .headers is not None
452+ and "sentry-task-enqueued-time" in task .request .headers
453+ ):
454+ latency = _now_seconds_since_epoch () - task .request .headers .pop (
455+ "sentry-task-enqueued-time"
472456 )
473457
474- with capture_internal_exceptions ():
475- with task .app .connection () as conn :
476- set_on_span (
477- SPANDATA .MESSAGING_SYSTEM ,
478- conn .transport .driver_type ,
479- )
458+ if latency is not None :
459+ latency *= 1000 # milliseconds
460+ set_on_span (SPANDATA .MESSAGING_MESSAGE_RECEIVE_LATENCY , latency )
461+
462+ with capture_internal_exceptions ():
463+ set_on_span (SPANDATA .MESSAGING_MESSAGE_ID , task .request .id )
464+
465+ with capture_internal_exceptions ():
466+ set_on_span (
467+ SPANDATA .MESSAGING_MESSAGE_RETRY_COUNT ,
468+ task .request .retries ,
469+ )
470+
471+ with capture_internal_exceptions ():
472+ with task .app .connection () as conn :
473+ set_on_span (
474+ SPANDATA .MESSAGING_SYSTEM ,
475+ conn .transport .driver_type ,
476+ )
480477
481478 return f (* args , ** kwargs )
482479 except Exception :
0 commit comments