From dc1aac689e8fe4bae159925ea01a2af6286e8616 Mon Sep 17 00:00:00 2001 From: Erica Pisani Date: Tue, 29 Sep 2026 13:24:23 -0400 Subject: [PATCH] ref(asgi): Drop `send_default_pii` support in `_get_request_attributes` Remove the legacy `send_default_pii` fallback branches and always gate `http.query`, `url.path`, `url.full` and `client.address` on `data_collection`. Refs PY-2798 Refs #7566 --- sentry_sdk/integrations/_asgi_common.py | 74 ++++++++----------------- tests/integrations/asgi/test_asgi.py | 9 +-- 2 files changed, 23 insertions(+), 60 deletions(-) diff --git a/sentry_sdk/integrations/_asgi_common.py b/sentry_sdk/integrations/_asgi_common.py index fd9ee2b0ec..f6be977de7 100644 --- a/sentry_sdk/integrations/_asgi_common.py +++ b/sentry_sdk/integrations/_asgi_common.py @@ -5,8 +5,6 @@ import sentry_sdk from sentry_sdk.data_collection import _apply_data_collection_filtering_to_query_string from sentry_sdk.integrations._wsgi_common import _filter_headers -from sentry_sdk.scope import should_send_default_pii -from sentry_sdk.utils import has_data_collection_enabled if TYPE_CHECKING: from typing import Any, Dict, Optional, Union @@ -168,64 +166,36 @@ def _get_request_attributes( for header, value in filtered_headers.items(): attributes[f"http.request.header.{header.lower()}"] = value - if has_data_collection_enabled(client_options): - filtered_query_string = None - query = _get_query(asgi_scope) - - if query: - filtered_query_string = ( - _apply_data_collection_filtering_to_query_string( - query_string=query, - behaviour=client_options["data_collection"]["url_query_params"], - ) - ) - if filtered_query_string: - attributes["http.query"] = filtered_query_string - - path = _get_path(asgi_scope=asgi_scope, root_path_in_path=root_path_in_path) - attributes["url.path"] = path - - url_without_query_string = _get_url( - asgi_scope, - "http" if ty == "http" else "ws", - headers.get("host"), - path=path, - ) + filtered_query_string = None + query = _get_query(asgi_scope) - attributes["url.full"] = ( - f"{url_without_query_string}?{filtered_query_string}" - if filtered_query_string is not None - else url_without_query_string + if query: + filtered_query_string = _apply_data_collection_filtering_to_query_string( + query_string=query, + behaviour=client_options["data_collection"]["url_query_params"], ) + if filtered_query_string: + attributes["http.query"] = filtered_query_string - elif should_send_default_pii(): - query = _get_query(asgi_scope) - if query: - attributes["http.query"] = query + path = _get_path(asgi_scope=asgi_scope, root_path_in_path=root_path_in_path) + attributes["url.path"] = path - path = _get_path(asgi_scope=asgi_scope, root_path_in_path=root_path_in_path) - attributes["url.path"] = path + url_without_query_string = _get_url( + asgi_scope, + "http" if ty == "http" else "ws", + headers.get("host"), + path=path, + ) - url_without_query_string = _get_url( - asgi_scope, - "http" if ty == "http" else "ws", - headers.get("host"), - path=path, - ) - 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 - ) + attributes["url.full"] = ( + f"{url_without_query_string}?{filtered_query_string}" + if filtered_query_string is not None + else url_without_query_string + ) asgi_scope_client = asgi_scope.get("client") if asgi_scope_client: - if has_data_collection_enabled(client_options): - if client_options["data_collection"]["user_info"]: - ip = _get_ip(asgi_scope) - attributes["client.address"] = ip - elif should_send_default_pii(): + if client_options["data_collection"]["user_info"]: ip = _get_ip(asgi_scope) attributes["client.address"] = ip diff --git a/tests/integrations/asgi/test_asgi.py b/tests/integrations/asgi/test_asgi.py index 1219eaa679..842844fc14 100644 --- a/tests/integrations/asgi/test_asgi.py +++ b/tests/integrations/asgi/test_asgi.py @@ -830,13 +830,6 @@ def _http_scope(): @pytest.mark.parametrize( "init_kwargs, request_url, expected_query, expected_url_full", [ - pytest.param( - {}, - "/foo?" + QUERY_STRING, - None, - None, - id="defaults", - ), pytest.param( {"data_collection": {}}, "/foo?" + QUERY_STRING, @@ -863,7 +856,7 @@ def _http_scope(): id="data_collection_off", ), pytest.param( - {"_experiments": {"data_collection": {}}}, + {"data_collection": {}}, "/foo", None, "http://example.com/foo",