Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions sentry_sdk/integrations/_asgi_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,21 @@
headers = _filter_headers(_get_headers(asgi_scope), use_annotated_value=False)
for header, value in headers.items():
attributes[f"http.request.header.{header.lower()}"] = value

query = _get_query(asgi_scope)
if query:
attributes["http.query"] = query

attributes["url.full"] = _get_url(
asgi_scope, "http" if ty == "http" else "ws", headers.get("host")
)
if should_send_default_pii():
query = _get_query(asgi_scope)
if query:
attributes["http.query"] = query

url_without_query_string = _get_url(
asgi_scope, "http" if ty == "http" else "ws", headers.get("host")

Check warning on line 130 in sentry_sdk/integrations/_asgi_common.py

View check run for this annotation

@sentry/warden / warden: code-review

`url.full` no longer captured on spans when `send_default_pii` is False

In `_get_request_attributes`, the entire `url.full` computation is now nested inside the `if should_send_default_pii():` block (along with `http.query`). Because PII is disabled by default, spans no longer record `url.full` at all in the common default configuration. Only the query string portion is sensitive; the base URL/path returned by `_get_url()` is not PII and was previously always set. Suggested fix: set `attributes["url.full"] = url_without_query_string` unconditionally and only append `?{query_string}` when `should_send_default_pii()` is True.
)
query_string = _get_query(asgi_scope)
attributes["url.full"] = (
f"{url_without_query_string}?{query_string}"
if query_string is not None
else url_without_query_string
)

client = asgi_scope.get("client")
if client and should_send_default_pii():

Check warning on line 140 in sentry_sdk/integrations/_asgi_common.py

View check run for this annotation

@sentry/warden / warden: find-bugs

`url.full` is no longer set when `should_send_default_pii()` is False

Moving `url.full` inside the `should_send_default_pii()` block means the base URL (without query string) is silently dropped from all ASGI spans when PII capture is disabled. The PR description's stated intent was to gate only `http.query` and `client.address`; `url.full` without its query string is not PII. Fix by computing and setting `url.full` (via `_get_url`) unconditionally, then only appending the query string when `should_send_default_pii()` is True.
Comment thread
ericapisani marked this conversation as resolved.
Expand Down
16 changes: 13 additions & 3 deletions tests/integrations/asgi/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ def test_invalid_transaction_style(asgi3_app):


@pytest.mark.asyncio
@pytest.mark.parametrize(
"should_send_pii",
[True, False],
)
@pytest.mark.parametrize(
"span_streaming",
[True, False],
Expand All @@ -174,9 +178,10 @@ async def test_capture_transaction(
capture_events,
capture_items,
span_streaming,
should_send_pii,
):
sentry_init(
send_default_pii=True,
send_default_pii=should_send_pii,
traces_sample_rate=1.0,
_experiments={
"trace_lifecycle": "stream" if span_streaming else "static",
Expand All @@ -203,16 +208,21 @@ async def test_capture_transaction(
assert span["attributes"]["sentry.span.source"] == "url"
assert span["attributes"]["sentry.op"] == "http.server"

assert span["attributes"]["url.full"] == "http://localhost/some_url"
assert span["attributes"]["network.protocol.name"] == "http"
assert span["attributes"]["http.request.method"] == "GET"
assert span["attributes"]["http.query"] == "somevalue=123"
assert span["attributes"]["http.request.header.host"] == "localhost"
assert span["attributes"]["http.request.header.remote-addr"] == "127.0.0.1"
assert (
span["attributes"]["http.request.header.user-agent"] == "ASGI-Test-Client"
)

if should_send_pii:
assert (
span["attributes"]["url.full"]
== "http://localhost/some_url?somevalue=123"
)
assert span["attributes"]["http.query"] == "somevalue=123"

else:
(transaction_event,) = events

Comment thread
ericapisani marked this conversation as resolved.
Expand Down
Loading