Skip to content

Commit ae1b1d0

Browse files
update url.path
1 parent e5d65f8 commit ae1b1d0

4 files changed

Lines changed: 14 additions & 4 deletions

File tree

sentry_sdk/consts.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,12 @@ class SPANDATA:
10201020
Example: "details"
10211021
"""
10221022

1023+
URL_PATH = "url.path"
1024+
"""
1025+
The URI path component.
1026+
Example: "/foo"
1027+
"""
1028+
10231029
URL_QUERY = "url.query"
10241030
"""
10251031
The query string present in the URL. Note that this does not contain the leading ? character, while the `http.query` attribute does.

sentry_sdk/integrations/_asgi_common.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,10 @@ def _get_request_attributes(
150150
if query_string is not None
151151
else url_without_query_string
152152
)
153-
attributes["url.path"] = asgi_scope.get("root_path", "") + asgi_scope.get(
154-
"path", ""
153+
attributes["url.path"] = (
154+
asgi_scope.get("path", "")
155+
if path_includes_root_path
156+
else asgi_scope.get("root_path", "") + asgi_scope.get("path", "")
155157
)
156158

157159
client = asgi_scope.get("client")

tests/integrations/fastapi/test_fastapi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,9 +1076,10 @@ def test_request_url(sentry_init, capture_events, capture_items, span_streaming)
10761076
for span in spans
10771077
if span["attributes"].get("sentry.op") == "http.server"
10781078
)
1079-
assert server_span["attributes"]["url.full"] == (
1079+
assert server_span["attributes"][SPANDATA.URL_FULL] == (
10801080
"http://testserver/root/nomessage"
10811081
)
1082+
assert server_span["attributes"][SPANDATA.URL_PATH] == "/root/nomessage"
10821083
else:
10831084
events = capture_events()
10841085

tests/integrations/starlette/test_starlette.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,9 +1513,10 @@ def test_request_url(sentry_init, capture_events, capture_items, span_streaming)
15131513
for span in spans
15141514
if span["attributes"].get("sentry.op") == "http.server"
15151515
)
1516-
assert server_span["attributes"]["url.full"] == (
1516+
assert server_span["attributes"][SPANDATA.URL_FULL] == (
15171517
"http://testserver/root/nomessage"
15181518
)
1519+
assert server_span["attributes"][SPANDATA.URL_PATH] == "/root/nomessage"
15191520
else:
15201521
events = capture_events()
15211522

0 commit comments

Comments
 (0)