Skip to content

Commit f900aee

Browse files
.
1 parent 9811845 commit f900aee

4 files changed

Lines changed: 5 additions & 2 deletions

File tree

sentry_sdk/integrations/asgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ async def _sentry_wrapped_send(
412412
span.set_attribute(
413413
"sentry.segment.name.source", source
414414
)
415-
http_route = getattr(sentry_sdk.get_current_scope(), "_http_route", None)
415+
http_route = sentry_scope._http_route
416416
if http_route is not None:
417417
span.set_attribute(SPANDATA.HTTP_ROUTE, http_route)
418418
finally:

sentry_sdk/integrations/fastapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def _set_transaction_name_and_source(
7979
if path is not None:
8080
name = path
8181

82-
scope._http_route = route
82+
sentry_sdk.get_isolation_scope()._http_route = name
8383

8484
if not name:
8585
name = _DEFAULT_TRANSACTION_NAME

sentry_sdk/scope.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ def __init__(
254254
self._error_processors: "List[ErrorProcessor]" = []
255255

256256
self._name: "Optional[str]" = None
257+
self._http_route: "Optional[str]" = None
257258
self._propagation_context: "Optional[PropagationContext]" = None
258259
self._n_breadcrumbs_truncated: int = 0
259260
self._gen_ai_original_message_count: "Dict[str, int]" = {}
@@ -279,6 +280,7 @@ def __copy__(self) -> "Scope":
279280
rv.client = self.client
280281
rv._level = self._level
281282
rv._name = self._name
283+
rv._http_route = self._http_route
282284
rv._fingerprint = self._fingerprint
283285
rv._transaction = self._transaction
284286
rv._transaction_info = self._transaction_info.copy()

tests/integrations/fastapi/test_fastapi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,7 @@ async def get_user(user_id: int):
883883
segment = segments[0]
884884
assert segment["name"] == "/api/users/{user_id}"
885885
assert segment["attributes"]["sentry.segment.name.source"] == "route"
886+
assert segment["attributes"]["http.route"] == "/api/users/{user_id}"
886887
else:
887888
(transaction_envelope,) = envelopes
888889
transaction_event = transaction_envelope.get_transaction_event()

0 commit comments

Comments
 (0)