Skip to content

Commit a0c8bc7

Browse files
use documented url attributes
1 parent c39c549 commit a0c8bc7

3 files changed

Lines changed: 42 additions & 8 deletions

File tree

sentry_sdk/consts.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,12 @@ class SPANDATA:
881881
Example: "tcp", "udp", "unix"
882882
"""
883883

884+
PROCESS_PID = "process.pid"
885+
"""
886+
The process ID of the running process.
887+
Example: 12345
888+
"""
889+
884890
PROFILER_ID = "profiler_id"
885891
"""
886892
Label identifying the profiler id that the span occurred in. This should be a string.
@@ -924,6 +930,24 @@ class SPANDATA:
924930
Example: "MainThread"
925931
"""
926932

933+
URL_FULL = "url.full"
934+
"""
935+
The URL of the resource that was fetched.
936+
Example: "https://example.com/test?foo=bar#buzz"
937+
"""
938+
939+
URL_FRAGMENT = "url.fragment"
940+
"""
941+
The fragments present in the URI. Note that this does not contain the leading # character, while the `http.fragment` attribute does.
942+
Example: "details"
943+
"""
944+
945+
URL_QUERY = "url.query"
946+
"""
947+
The query string present in the URL. Note that this does not contain the leading ? character, while the `http.query` attribute does.
948+
Example: "foo=bar&bar=baz"
949+
"""
950+
927951
MCP_TOOL_NAME = "mcp.tool.name"
928952
"""
929953
The name of the MCP tool being called.

sentry_sdk/integrations/stdlib.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def putrequest(
104104
parsed_url = parse_url(real_url, sanitize=False)
105105

106106
span_streaming = has_span_streaming_enabled(client.options)
107-
span: "Union[Span, StreamedSpan]"
108107
if span_streaming:
109108
span = sentry_sdk.traces.start_span(
110109
name="%s %s"
@@ -114,6 +113,13 @@ def putrequest(
114113
"sentry.op": OP.HTTP_CLIENT,
115114
},
116115
)
116+
117+
span.set_attribute(SPANDATA.HTTP_METHOD, method)
118+
if parsed_url is not None:
119+
span.set_attribute(SPANDATA.URL_FULL, parsed_url.url)
120+
span.set_attribute(SPANDATA.URL_QUERY, parsed_url.query)
121+
span.set_attribute(SPANDATA.URL_FRAGMENT, parsed_url.fragment)
122+
117123
set_on_span = span.set_attribute
118124

119125
else:
@@ -123,13 +129,14 @@ def putrequest(
123129
% (method, parsed_url.url if parsed_url else SENSITIVE_DATA_SUBSTITUTE),
124130
origin="auto.http.stdlib.httplib",
125131
)
126-
set_on_span = span.set_data
127132

128-
set_on_span(SPANDATA.HTTP_METHOD, method)
129-
if parsed_url is not None:
130-
set_on_span("url", parsed_url.url)
131-
set_on_span(SPANDATA.HTTP_QUERY, parsed_url.query)
132-
set_on_span(SPANDATA.HTTP_FRAGMENT, parsed_url.fragment)
133+
span.set_data(SPANDATA.HTTP_METHOD, method)
134+
if parsed_url is not None:
135+
span.set_data("url", parsed_url.url)
136+
span.set_data(SPANDATA.HTTP_QUERY, parsed_url.query)
137+
span.set_data(SPANDATA.HTTP_FRAGMENT, parsed_url.fragment)
138+
139+
set_on_span = span.set_data
133140

134141
# for proxies, these point to the proxy host/port
135142
if tunnel_host:

tests/integrations/stdlib/test_httplib.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,10 @@ def test_proxy_http_tunnel(
980980

981981
port_modifier = f":{tunnel_port}" if tunnel_port else ""
982982
assert span["name"] == f"GET http://api.example.com{port_modifier}/foo"
983-
assert span["attributes"]["url"] == f"http://api.example.com{port_modifier}/foo"
983+
assert (
984+
span["attributes"][SPANDATA.URL_FULL]
985+
== f"http://api.example.com{port_modifier}/foo"
986+
)
984987
assert span["attributes"][SPANDATA.HTTP_METHOD] == "GET"
985988
assert span["attributes"][SPANDATA.NETWORK_PEER_ADDRESS] == "localhost"
986989
assert span["attributes"][SPANDATA.NETWORK_PEER_PORT] == PROXY_PORT

0 commit comments

Comments
 (0)