Skip to content

Commit 7aa4d83

Browse files
committed
ref(asgi): Drop send_default_pii support
1 parent 0d73f7a commit 7aa4d83

2 files changed

Lines changed: 33 additions & 78 deletions

File tree

‎sentry_sdk/integrations/_asgi_common.py‎

Lines changed: 31 additions & 70 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
@@ -123,19 +121,14 @@ def _get_request_data(
123121

124122
request_data["headers"] = _filter_headers(headers)
125123

126-
if has_data_collection_enabled(client_options):
127-
qs = _get_query(asgi_scope)
128-
if qs:
129-
filtered_query_string = (
130-
_apply_data_collection_filtering_to_query_string(
131-
query_string=qs,
132-
behaviour=client_options["data_collection"]["url_query_params"],
133-
)
134-
)
135-
if filtered_query_string:
136-
request_data["query_string"] = filtered_query_string
137-
else:
138-
request_data["query_string"] = _get_query(asgi_scope)
124+
qs = _get_query(asgi_scope)
125+
if qs:
126+
filtered_query_string = _apply_data_collection_filtering_to_query_string(
127+
query_string=qs,
128+
behaviour=client_options["data_collection"]["url_query_params"],
129+
)
130+
if filtered_query_string:
131+
request_data["query_string"] = filtered_query_string
139132

140133
request_data["url"] = _get_url(
141134
asgi_scope,
@@ -146,10 +139,7 @@ def _get_request_data(
146139

147140
client = asgi_scope.get("client")
148141
if client:
149-
if has_data_collection_enabled(client_options):
150-
if client_options["data_collection"]["user_info"]:
151-
request_data["env"] = {"REMOTE_ADDR": _get_ip(asgi_scope)}
152-
elif should_send_default_pii():
142+
if client_options["data_collection"]["user_info"]:
153143
request_data["env"] = {"REMOTE_ADDR": _get_ip(asgi_scope)}
154144

155145
return request_data
@@ -176,65 +166,36 @@ def _get_request_attributes(
176166
for header, value in filtered_headers.items():
177167
attributes[f"http.request.header.{header.lower()}"] = value
178168

179-
if has_data_collection_enabled(client_options):
180-
filtered_query_string = None
181-
query = _get_query(asgi_scope)
182-
183-
if query:
184-
filtered_query_string = (
185-
_apply_data_collection_filtering_to_query_string(
186-
query_string=query,
187-
behaviour=client_options["data_collection"]["url_query_params"],
188-
)
189-
)
190-
if filtered_query_string:
191-
attributes["http.query"] = filtered_query_string
192-
193-
path = _get_path(asgi_scope=asgi_scope, root_path_in_path=root_path_in_path)
194-
attributes["url.path"] = path
195-
196-
url_without_query_string = _get_url(
197-
asgi_scope,
198-
"http" if ty == "http" else "ws",
199-
headers.get("host"),
200-
path=path,
201-
)
169+
filtered_query_string = None
170+
query = _get_query(asgi_scope)
202171

203-
attributes["url.full"] = (
204-
f"{url_without_query_string}?{filtered_query_string}"
205-
if filtered_query_string is not None
206-
else url_without_query_string
172+
if query:
173+
filtered_query_string = _apply_data_collection_filtering_to_query_string(
174+
query_string=query,
175+
behaviour=client_options["data_collection"]["url_query_params"],
207176
)
177+
if filtered_query_string:
178+
attributes["http.query"] = filtered_query_string
208179

209-
elif should_send_default_pii():
210-
query = _get_query(asgi_scope)
211-
if query:
212-
attributes["http.query"] = query
180+
path = _get_path(asgi_scope=asgi_scope, root_path_in_path=root_path_in_path)
181+
attributes["url.path"] = path
213182

214-
path = _get_path(asgi_scope=asgi_scope, root_path_in_path=root_path_in_path)
215-
attributes["url.path"] = path
183+
url_without_query_string = _get_url(
184+
asgi_scope,
185+
"http" if ty == "http" else "ws",
186+
headers.get("host"),
187+
path=path,
188+
)
216189

217-
url_without_query_string = _get_url(
218-
asgi_scope,
219-
"http" if ty == "http" else "ws",
220-
headers.get("host"),
221-
path=path,
222-
)
223-
query_string = _get_query(asgi_scope)
224-
attributes["url.full"] = (
225-
f"{url_without_query_string}?{query_string}"
226-
if query_string is not None
227-
else url_without_query_string
228-
)
190+
attributes["url.full"] = (
191+
f"{url_without_query_string}?{filtered_query_string}"
192+
if filtered_query_string is not None
193+
else url_without_query_string
194+
)
229195

230196
asgi_scope_client = asgi_scope.get("client")
231197
if asgi_scope_client:
232-
if has_data_collection_enabled(client_options):
233-
if client_options["data_collection"]["user_info"]:
234-
ip = _get_ip(asgi_scope)
235-
attributes["client.address"] = ip
236-
elif should_send_default_pii():
198+
if client_options["data_collection"]["user_info"]:
237199
ip = _get_ip(asgi_scope)
238200
attributes["client.address"] = ip
239-
240201
return attributes

‎sentry_sdk/integrations/asgi.py‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from sentry_sdk.integrations._wsgi_common import (
2727
DEFAULT_HTTP_METHODS_TO_CAPTURE,
2828
)
29-
from sentry_sdk.scope import Scope, should_send_default_pii
29+
from sentry_sdk.scope import Scope
3030
from sentry_sdk.sessions import track_session
3131
from sentry_sdk.traces import (
3232
SOURCE_FOR_STYLE,
@@ -37,7 +37,6 @@
3737
_get_installed_modules,
3838
capture_internal_exceptions,
3939
event_from_exception,
40-
has_data_collection_enabled,
4140
logger,
4241
qualname_from_function,
4342
reraise,
@@ -223,12 +222,7 @@ async def _run_app(
223222

224223
if scope.get("client"):
225224
client_options = sentry_sdk.get_client().options
226-
if has_data_collection_enabled(client_options):
227-
if client_options["data_collection"]["user_info"]:
228-
sentry_scope.set_attribute(
229-
SPANDATA.USER_IP_ADDRESS, _get_ip(scope)
230-
)
231-
elif should_send_default_pii():
225+
if client_options["data_collection"]["user_info"]:
232226
sentry_scope.set_attribute(
233227
SPANDATA.USER_IP_ADDRESS, _get_ip(scope)
234228
)

0 commit comments

Comments
 (0)