|
25 | 25 | ) |
26 | 26 | from sentry_sdk.integrations.asgi import SentryAsgiMiddleware |
27 | 27 | from sentry_sdk.scope import should_send_default_pii |
28 | | -from sentry_sdk.traces import StreamedSpan, get_current_span |
| 28 | +from sentry_sdk.traces import StreamedSpan |
29 | 29 | from sentry_sdk.tracing import ( |
30 | 30 | SOURCE_FOR_STYLE, |
31 | 31 | TransactionSource, |
32 | 32 | ) |
33 | | -from sentry_sdk.tracing_utils import has_span_streaming_enabled |
34 | 33 | from sentry_sdk.utils import ( |
35 | 34 | AnnotatedValue, |
36 | 35 | capture_internal_exceptions, |
@@ -170,24 +169,18 @@ async def _create_span_call( |
170 | 169 | return await old_call(app, scope, receive, send, **kwargs) |
171 | 170 |
|
172 | 171 | middleware_name = app.__class__.__name__ |
173 | | - is_span_streaming_enabled = has_span_streaming_enabled(client.options) |
174 | 172 |
|
175 | 173 | def _start_middleware_span(op: str, name: str) -> "Any": |
176 | | - if is_span_streaming_enabled: |
177 | | - if sentry_sdk.traces.get_current_span() is None: |
178 | | - return nullcontext() |
179 | | - return sentry_sdk.traces.start_span( |
180 | | - name=name, |
181 | | - attributes={ |
182 | | - "sentry.op": op, |
183 | | - "sentry.origin": StarletteIntegration.origin, |
184 | | - "middleware.name": middleware_name, |
185 | | - }, |
186 | | - ) |
187 | | - return sentry_sdk.start_span( |
188 | | - op=op, |
| 174 | + if sentry_sdk.traces.get_current_span() is None: |
| 175 | + return nullcontext() |
| 176 | + |
| 177 | + return sentry_sdk.traces.start_span( |
189 | 178 | name=name, |
190 | | - origin=StarletteIntegration.origin, |
| 179 | + attributes={ |
| 180 | + "sentry.op": op, |
| 181 | + "sentry.origin": StarletteIntegration.origin, |
| 182 | + "middleware.name": middleware_name, |
| 183 | + }, |
191 | 184 | ) |
192 | 185 |
|
193 | 186 | with _start_middleware_span(op=OP.MIDDLEWARE_STARLETTE, name=middleware_name): |
@@ -549,7 +542,7 @@ def event_processor(event: "Event", hint: "Dict[str, Any]") -> "Event": |
549 | 542 | try: |
550 | 543 | return await handler(*args, **kwargs) |
551 | 544 | finally: |
552 | | - current_span = get_current_span() |
| 545 | + current_span = sentry_sdk.traces.get_current_span() |
553 | 546 |
|
554 | 547 | if type(current_span) is StreamedSpan: |
555 | 548 | attach_request_data = True |
@@ -594,23 +587,19 @@ def _sentry_sync_func(*args: "Any", **kwargs: "Any") -> "Any": |
594 | 587 | if integration is None: |
595 | 588 | return old_func(*args, **kwargs) |
596 | 589 |
|
597 | | - current_scope = sentry_sdk.get_current_scope() |
598 | | - |
599 | | - span_streaming = has_span_streaming_enabled(client.options) |
600 | | - if span_streaming: |
601 | | - current_span = current_scope.streamed_span |
| 590 | + current_span = sentry_sdk.traces.get_current_span() |
602 | 591 |
|
603 | | - if type(current_span) is StreamedSpan: |
604 | | - current_span._segment._update_active_thread() |
605 | | - elif current_scope.transaction is not None: |
606 | | - current_scope.transaction.update_active_thread() |
| 592 | + if type(current_span) is StreamedSpan: |
| 593 | + current_span._segment._update_active_thread() |
607 | 594 |
|
608 | 595 | sentry_scope = sentry_sdk.get_isolation_scope() |
609 | 596 |
|
610 | 597 | request = args[0] |
611 | 598 |
|
612 | 599 | _set_transaction_name_and_source( |
613 | | - current_scope, integration.transaction_style, request |
| 600 | + sentry_sdk.get_current_scope(), |
| 601 | + integration.transaction_style, |
| 602 | + request, |
614 | 603 | ) |
615 | 604 |
|
616 | 605 | extractor = StarletteRequestExtractor(request) |
|
0 commit comments