Skip to content

Commit f4d2b93

Browse files
.
1 parent 2e81110 commit f4d2b93

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

sentry_sdk/integrations/celery/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,10 @@ def apply_async(*args: "Any", **kwargs: "Any") -> "Any":
292292

293293
span_mgr: "Union[StreamedSpan, Span, NoOpMgr]" = NoOpMgr()
294294
if span_streaming:
295-
if not task_started_from_beat and sentry_sdk.get_current_span() is not None:
295+
if (
296+
not task_started_from_beat
297+
and sentry_sdk.get_current_streamed_span() is not None
298+
):
296299
span_mgr = sentry_sdk.traces.start_span(
297300
name=task_name,
298301
attributes={
@@ -573,7 +576,7 @@ def sentry_publish(self: "Producer", *args: "Any", **kwargs: "Any") -> "Any":
573576

574577
span: "Union[StreamedSpan, Span, None]" = None
575578
if span_streaming:
576-
if sentry_sdk.get_current_span() is not None:
579+
if sentry_sdk.get_current_streamed_span() is not None:
577580
span = sentry_sdk.traces.start_span(
578581
name=task_name,
579582
attributes={

sentry_sdk/integrations/starlette.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -545,19 +545,22 @@ def event_processor(
545545

546546
@functools.wraps(old_func)
547547
def _sentry_sync_func(*args: "Any", **kwargs: "Any") -> "Any":
548-
integration = sentry_sdk.get_client().get_integration(
549-
StarletteIntegration
550-
)
548+
client = sentry_sdk.get_client()
549+
550+
integration = client.get_integration(StarletteIntegration)
551551
if integration is None:
552552
return old_func(*args, **kwargs)
553553

554554
current_scope = sentry_sdk.get_current_scope()
555-
current_span = current_scope.span
556555

557-
if isinstance(current_span, StreamedSpan) and not isinstance(
558-
current_span, NoOpStreamedSpan
559-
):
560-
current_span._segment._update_active_thread()
556+
span_streaming = has_span_streaming_enabled(client.options)
557+
if span_streaming:
558+
current_span = current_scope.streamed_span
559+
560+
if isinstance(current_span, StreamedSpan) and not isinstance(
561+
current_span, NoOpStreamedSpan
562+
):
563+
current_span._segment._update_active_thread()
561564
elif current_scope.transaction is not None:
562565
current_scope.transaction.update_active_thread()
563566

0 commit comments

Comments
 (0)