From 340b5a81204e24fef74f1ac928659aeec24712de Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Thu, 1 Oct 2026 13:44:34 +0200 Subject: [PATCH] ref(asgi): Deduplicate by removing _get_transaction_name_and_source() --- sentry_sdk/integrations/asgi.py | 38 +++------------------------------ 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/sentry_sdk/integrations/asgi.py b/sentry_sdk/integrations/asgi.py index dc0ac81888..4191c7388d 100644 --- a/sentry_sdk/integrations/asgi.py +++ b/sentry_sdk/integrations/asgi.py @@ -210,7 +210,7 @@ async def _run_app( ( transaction_name, transaction_source, - ) = self._get_transaction_name_and_source(scope) + ) = self._get_segment_name_and_source(scope) method = scope.get("method", "").upper() @@ -351,7 +351,7 @@ def event_processor( ] ) if not already_set: - name, source = self._get_transaction_name_and_source(asgi_scope) + name, source = self._get_segment_name_and_source(asgi_scope) event["transaction"] = name event["transaction_info"] = {"source": source} @@ -363,7 +363,7 @@ def event_processor( # data to your liking it's recommended to use the `before_send` callback # for that. - def _get_transaction_name_and_source( + def _get_segment_name_and_source( self: "SentryAsgiMiddleware", asgi_scope: "Any" ) -> "Tuple[str, str]": name = None @@ -393,35 +393,3 @@ def _get_transaction_name_and_source( return name, source return name, source - - def _get_segment_name_and_source( - self: "SentryAsgiMiddleware", asgi_scope: "Any" - ) -> "Tuple[str, str]": - name = None - source = SegmentNameSource.ROUTE.value - ty = asgi_scope.get("type") - - # FastAPI includes the route object in the scope to let Sentry extract the - # path from it for the transaction name - route = asgi_scope.get("route") - if route: - path = getattr(route, "path", None) - if path is not None: - name = path - else: - name = _get_url( - asgi_scope, - "http" if ty == "http" else "ws", - host=None, - path=_get_path( - asgi_scope=asgi_scope, root_path_in_path=self.root_path_in_path - ), - ) - source = SegmentNameSource.URL.value - - if name is None: - name = _DEFAULT_TRANSACTION_NAME - source = SegmentNameSource.ROUTE.value - return name, source - - return name, source