Skip to content

Commit b0fcd98

Browse files
authored
ref(asgi): Drop send_default_pii support in _get_request_attributes (#7769)
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
1 parent 8a896b6 commit b0fcd98

2 files changed

Lines changed: 23 additions & 60 deletions

File tree

‎sentry_sdk/integrations/_asgi_common.py‎

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import sentry_sdk
66
from sentry_sdk.data_collection import _apply_data_collection_filtering_to_query_string
77
from sentry_sdk.integrations._wsgi_common import _filter_headers
8-
from sentry_sdk.scope import should_send_default_pii
9-
from sentry_sdk.utils import has_data_collection_enabled
108

119
if TYPE_CHECKING:
1210
from typing import Any, Dict, Optional, Union
@@ -171,64 +169,36 @@ def _get_request_attributes(
171169
for header, value in filtered_headers.items():
172170
attributes[f"http.request.header.{header.lower()}"] = [value]
173171

174-
if has_data_collection_enabled(client_options):
175-
filtered_query_string = None
176-
query = _get_query(asgi_scope)
177-
178-
if query:
179-
filtered_query_string = (
180-
_apply_data_collection_filtering_to_query_string(
181-
query_string=query,
182-
behaviour=client_options["data_collection"]["url_query_params"],
183-
)
184-
)
185-
if filtered_query_string:
186-
attributes["http.query"] = filtered_query_string
187-
188-
path = _get_path(asgi_scope=asgi_scope, root_path_in_path=root_path_in_path)
189-
attributes["url.path"] = path
190-
191-
url_without_query_string = _get_url(
192-
asgi_scope,
193-
"http" if ty == "http" else "ws",
194-
headers.get("host"),
195-
path=path,
196-
)
172+
filtered_query_string = None
173+
query = _get_query(asgi_scope)
197174

198-
attributes["url.full"] = (
199-
f"{url_without_query_string}?{filtered_query_string}"
200-
if filtered_query_string is not None
201-
else url_without_query_string
175+
if query:
176+
filtered_query_string = _apply_data_collection_filtering_to_query_string(
177+
query_string=query,
178+
behaviour=client_options["data_collection"]["url_query_params"],
202179
)
180+
if filtered_query_string:
181+
attributes["http.query"] = filtered_query_string
203182

204-
elif should_send_default_pii():
205-
query = _get_query(asgi_scope)
206-
if query:
207-
attributes["http.query"] = query
183+
path = _get_path(asgi_scope=asgi_scope, root_path_in_path=root_path_in_path)
184+
attributes["url.path"] = path
208185

209-
path = _get_path(asgi_scope=asgi_scope, root_path_in_path=root_path_in_path)
210-
attributes["url.path"] = path
186+
url_without_query_string = _get_url(
187+
asgi_scope,
188+
"http" if ty == "http" else "ws",
189+
headers.get("host"),
190+
path=path,
191+
)
211192

212-
url_without_query_string = _get_url(
213-
asgi_scope,
214-
"http" if ty == "http" else "ws",
215-
headers.get("host"),
216-
path=path,
217-
)
218-
query_string = _get_query(asgi_scope)
219-
attributes["url.full"] = (
220-
f"{url_without_query_string}?{query_string}"
221-
if query_string is not None
222-
else url_without_query_string
223-
)
193+
attributes["url.full"] = (
194+
f"{url_without_query_string}?{filtered_query_string}"
195+
if filtered_query_string is not None
196+
else url_without_query_string
197+
)
224198

225199
asgi_scope_client = asgi_scope.get("client")
226200
if asgi_scope_client:
227-
if has_data_collection_enabled(client_options):
228-
if client_options["data_collection"]["user_info"]:
229-
ip = _get_ip(asgi_scope)
230-
attributes["client.address"] = ip
231-
elif should_send_default_pii():
201+
if client_options["data_collection"]["user_info"]:
232202
ip = _get_ip(asgi_scope)
233203
attributes["client.address"] = ip
234204

‎tests/integrations/asgi/test_asgi.py‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -826,13 +826,6 @@ def _http_scope():
826826
@pytest.mark.parametrize(
827827
"init_kwargs, request_url, expected_query, expected_url_full",
828828
[
829-
pytest.param(
830-
{},
831-
"/foo?" + QUERY_STRING,
832-
None,
833-
None,
834-
id="defaults",
835-
),
836829
pytest.param(
837830
{"data_collection": {}},
838831
"/foo?" + QUERY_STRING,
@@ -859,7 +852,7 @@ def _http_scope():
859852
id="data_collection_off",
860853
),
861854
pytest.param(
862-
{"_experiments": {"data_collection": {}}},
855+
{"data_collection": {}},
863856
"/foo",
864857
None,
865858
"http://example.com/foo",

0 commit comments

Comments
 (0)