Skip to content

Commit 0335f7f

Browse files
committed
ref(asgi): Drop send_default_pii support
1 parent 40d19b3 commit 0335f7f

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
@@ -126,19 +124,14 @@ def _get_request_data(
126124
use_annotated_value=False,
127125
)
128126

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

143136
request_data["url"] = _get_url(
144137
asgi_scope,
@@ -149,10 +142,7 @@ def _get_request_data(
149142

150143
client = asgi_scope.get("client")
151144
if client:
152-
if has_data_collection_enabled(client_options):
153-
if client_options["data_collection"]["user_info"]:
154-
request_data["env"] = {"REMOTE_ADDR": _get_ip(asgi_scope)}
155-
elif should_send_default_pii():
145+
if client_options["data_collection"]["user_info"]:
156146
request_data["env"] = {"REMOTE_ADDR": _get_ip(asgi_scope)}
157147

158148
return request_data
@@ -179,65 +169,36 @@ def _get_request_attributes(
179169
for header, value in filtered_headers.items():
180170
attributes[f"http.request.header.{header.lower()}"] = value
181171

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

206-
attributes["url.full"] = (
207-
f"{url_without_query_string}?{filtered_query_string}"
208-
if filtered_query_string is not None
209-
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"],
210179
)
180+
if filtered_query_string:
181+
attributes["http.query"] = filtered_query_string
211182

212-
elif should_send_default_pii():
213-
query = _get_query(asgi_scope)
214-
if query:
215-
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
216185

217-
path = _get_path(asgi_scope=asgi_scope, root_path_in_path=root_path_in_path)
218-
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+
)
219192

220-
url_without_query_string = _get_url(
221-
asgi_scope,
222-
"http" if ty == "http" else "ws",
223-
headers.get("host"),
224-
path=path,
225-
)
226-
query_string = _get_query(asgi_scope)
227-
attributes["url.full"] = (
228-
f"{url_without_query_string}?{query_string}"
229-
if query_string is not None
230-
else url_without_query_string
231-
)
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+
)
232198

233199
asgi_scope_client = asgi_scope.get("client")
234200
if asgi_scope_client:
235-
if has_data_collection_enabled(client_options):
236-
if client_options["data_collection"]["user_info"]:
237-
ip = _get_ip(asgi_scope)
238-
attributes["client.address"] = ip
239-
elif should_send_default_pii():
201+
if client_options["data_collection"]["user_info"]:
240202
ip = _get_ip(asgi_scope)
241203
attributes["client.address"] = ip
242-
243204
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)