|
27 | 27 | from sentry_sdk.traces import ( |
28 | 28 | StreamedSpan, |
29 | 29 | SegmentSource, |
30 | | - SOURCE_FOR_STYLE as SEGMENT_SOURCE_FOR_STYLE, |
31 | 30 | ) |
32 | 31 | from sentry_sdk.tracing import ( |
33 | 32 | SOURCE_FOR_STYLE, |
|
45 | 44 | _get_installed_modules, |
46 | 45 | reraise, |
47 | 46 | capture_internal_exceptions, |
48 | | - qualname_from_function, |
49 | 47 | ) |
50 | 48 |
|
51 | 49 | from typing import TYPE_CHECKING |
@@ -364,8 +362,7 @@ async def _sentry_wrapped_send( |
364 | 362 | finally: |
365 | 363 | if isinstance(span, StreamedSpan): |
366 | 364 | already_set = ( |
367 | | - span is not None |
368 | | - and span.name != _DEFAULT_TRANSACTION_NAME |
| 365 | + span.name != _DEFAULT_TRANSACTION_NAME |
369 | 366 | and span.get_attributes().get("sentry.span.source") |
370 | 367 | in [ |
371 | 368 | SegmentSource.COMPONENT.value, |
@@ -460,36 +457,5 @@ def _get_transaction_name_and_source( |
460 | 457 | def _get_segment_name_and_source( |
461 | 458 | self: "SentryAsgiMiddleware", segment_style: str, asgi_scope: "Any" |
462 | 459 | ) -> "Tuple[str, str]": |
463 | | - name = None |
464 | | - source = SEGMENT_SOURCE_FOR_STYLE[segment_style].value |
465 | | - ty = asgi_scope.get("type") |
466 | | - |
467 | | - if segment_style == "endpoint": |
468 | | - endpoint = asgi_scope.get("endpoint") |
469 | | - # Webframeworks like Starlette mutate the ASGI env once routing is |
470 | | - # done, which is sometime after the request has started. If we have |
471 | | - # an endpoint, overwrite our generic transaction name. |
472 | | - if endpoint: |
473 | | - name = qualname_from_function(endpoint) or "" |
474 | | - else: |
475 | | - name = _get_url(asgi_scope, "http" if ty == "http" else "ws", host=None) |
476 | | - source = SegmentSource.URL.value |
477 | | - |
478 | | - elif segment_style == "url": |
479 | | - # FastAPI includes the route object in the scope to let Sentry extract the |
480 | | - # path from it for the transaction name |
481 | | - route = asgi_scope.get("route") |
482 | | - if route: |
483 | | - path = getattr(route, "path", None) |
484 | | - if path is not None: |
485 | | - name = path |
486 | | - else: |
487 | | - name = _get_url(asgi_scope, "http" if ty == "http" else "ws", host=None) |
488 | | - source = SegmentSource.URL.value |
489 | | - |
490 | | - if name is None: |
491 | | - name = _DEFAULT_TRANSACTION_NAME |
492 | | - source = SegmentSource.ROUTE.value |
493 | | - return name, source |
494 | | - |
495 | | - return name, source |
| 460 | + name, source = self._get_transaction_name_and_source(segment_style, asgi_scope) |
| 461 | + return name, str(source) |
0 commit comments