|
11 | 11 | from sentry_sdk.hub import Hub, _should_send_default_pii |
12 | 12 | from sentry_sdk.integrations._wsgi_common import _filter_headers |
13 | 13 | from sentry_sdk.utils import ContextVar, event_from_exception, transaction_from_function |
| 14 | +from sentry_sdk.tracing import Span |
14 | 15 |
|
15 | 16 | if MYPY: |
16 | 17 | from typing import Dict |
@@ -60,21 +61,23 @@ async def _run_app(self, scope, callback): |
60 | 61 | hub = Hub(Hub.current) |
61 | 62 | with hub: |
62 | 63 | with hub.configure_scope() as sentry_scope: |
| 64 | + sentry_scope.clear_breadcrumbs() |
63 | 65 | sentry_scope._name = "asgi" |
64 | | - sentry_scope.transaction = ( |
65 | | - scope.get("path") or "unknown asgi request" |
66 | | - ) |
67 | | - |
68 | 66 | processor = functools.partial( |
69 | 67 | self.event_processor, asgi_scope=scope |
70 | 68 | ) |
71 | 69 | sentry_scope.add_event_processor(processor) |
72 | 70 |
|
73 | | - try: |
74 | | - await callback() |
75 | | - except Exception as exc: |
76 | | - _capture_exception(hub, exc) |
77 | | - raise exc from None |
| 71 | + span = Span.continue_from_headers(dict(scope["headers"])) |
| 72 | + span.op = "http.server" |
| 73 | + span.transaction = "generic ASGI request" |
| 74 | + |
| 75 | + with hub.start_span(span) as span: |
| 76 | + try: |
| 77 | + return await callback() |
| 78 | + except Exception as exc: |
| 79 | + _capture_exception(hub, exc) |
| 80 | + raise exc from None |
78 | 81 | finally: |
79 | 82 | _asgi_middleware_applied.set(False) |
80 | 83 |
|
|
0 commit comments