Skip to content

Commit 0c25131

Browse files
.
1 parent 5eddc69 commit 0c25131

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

‎sentry_sdk/integrations/starlette.py‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,20 @@ async def _create_span_call(
184184
if integration is None:
185185
return await old_call(app, scope, receive, send, **kwargs)
186186

187+
route_path, name_source = _http_route_and_source_from_router(scope)
188+
189+
server_span = sentry_sdk.get_current_scope()._server_segment_span
190+
if (
191+
server_span is not None
192+
and route_path is not None
193+
and name_source == TransactionSource.ROUTE
194+
):
195+
server_span.set_attribute(SPANDATA.HTTP_ROUTE, route_path)
196+
187197
# Update transaction name with middleware name
188-
name, source = _get_transaction_from_middleware(app, scope, integration)
198+
name, source = _get_transaction_from_middleware(
199+
app, integration, route_path=route_path, name_source=name_source
200+
)
189201

190202
if name is not None:
191203
sentry_sdk.get_current_scope().set_transaction_name(
@@ -915,7 +927,10 @@ def _set_transaction_name_and_source(
915927

916928

917929
def _get_transaction_from_middleware(
918-
app: "Any", asgi_scope: "Dict[str, Any]", integration: "StarletteIntegration"
930+
app: "Any",
931+
integration: "StarletteIntegration",
932+
route_path: "Optional[str]",
933+
name_source: "TransactionSource",
919934
) -> "Tuple[Optional[str], Optional[str]]":
920935
name = None
921936
source = None
@@ -924,14 +939,6 @@ def _get_transaction_from_middleware(
924939
name = transaction_from_function(app.__class__)
925940
source = TransactionSource.COMPONENT
926941
elif integration.transaction_style == "url":
927-
route_path, name_source = _http_route_and_source_from_router(asgi_scope)
928-
929-
server_span = sentry_sdk.get_current_scope()._server_segment_span
930-
if (
931-
server_span is not None
932-
and route_path is not None
933-
and name_source == TransactionSource.ROUTE
934-
):
935-
server_span.set_attribute(SPANDATA.HTTP_ROUTE, route_path)
942+
name, source = route_path, name_source
936943

937944
return name, source

0 commit comments

Comments
 (0)