|
15 | 15 | from sentry_sdk.integrations.celery.utils import _now_seconds_since_epoch |
16 | 16 | from sentry_sdk.integrations.logging import ignore_logger |
17 | 17 | from sentry_sdk.scope import should_send_default_pii |
18 | | -from sentry_sdk.traces import StreamedSpan |
| 18 | +from sentry_sdk.traces import StreamedSpan, _get_current_streamed_span |
19 | 19 | from sentry_sdk.tracing import BAGGAGE_HEADER_NAME, Span, TransactionSource |
20 | 20 | from sentry_sdk.tracing_utils import Baggage, has_span_streaming_enabled |
21 | 21 | from sentry_sdk.utils import ( |
@@ -98,13 +98,16 @@ def setup_once() -> None: |
98 | 98 |
|
99 | 99 |
|
100 | 100 | def _set_status(status: str) -> None: |
| 101 | + client = sentry_sdk.get_client() |
| 102 | + span_streaming = has_span_streaming_enabled(client.options) |
| 103 | + |
101 | 104 | with capture_internal_exceptions(): |
102 | 105 | scope = sentry_sdk.get_current_scope() |
103 | | - if scope.span is not None: |
104 | | - if isinstance(scope.span, Span): |
105 | | - scope.span.set_status(status) |
106 | | - else: |
107 | | - scope.span.status = "ok" if status == "ok" else "error" |
| 106 | + |
| 107 | + if span_streaming and scope.streamed_span is not None: |
| 108 | + scope.streamed_span.status = "ok" if status == "ok" else "error" |
| 109 | + elif not span_streaming and scope.span is not None: |
| 110 | + scope.span.set_status(status) |
108 | 111 |
|
109 | 112 |
|
110 | 113 | def _capture_exception(task: "Any", exc_info: "ExcInfo") -> None: |
@@ -289,7 +292,7 @@ def apply_async(*args: "Any", **kwargs: "Any") -> "Any": |
289 | 292 |
|
290 | 293 | span_mgr: "Union[StreamedSpan, Span, NoOpMgr]" = NoOpMgr() |
291 | 294 | if span_streaming: |
292 | | - if not task_started_from_beat and sentry_sdk.get_current_span() is not None: |
| 295 | + if not task_started_from_beat and _get_current_streamed_span() is not None: |
293 | 296 | span_mgr = sentry_sdk.traces.start_span( |
294 | 297 | name=task_name, |
295 | 298 | attributes={ |
@@ -570,7 +573,7 @@ def sentry_publish(self: "Producer", *args: "Any", **kwargs: "Any") -> "Any": |
570 | 573 |
|
571 | 574 | span: "Union[StreamedSpan, Span, None]" = None |
572 | 575 | if span_streaming: |
573 | | - if sentry_sdk.get_current_span() is not None: |
| 576 | + if _get_current_streamed_span() is not None: |
574 | 577 | span = sentry_sdk.traces.start_span( |
575 | 578 | name=task_name, |
576 | 579 | attributes={ |
|
0 commit comments