Skip to content

Commit 5bd0734

Browse files
committed
ref(sanic): Drop send_default_pii support
1 parent 0fbf5bf commit 5bd0734

1 file changed

Lines changed: 24 additions & 50 deletions

File tree

‎sentry_sdk/integrations/sanic.py‎

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@
1111
)
1212
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
1313
from sentry_sdk.integrations._wsgi_common import RequestExtractor, _filter_headers
14-
from sentry_sdk.scope import should_send_default_pii
1514
from sentry_sdk.traces import SegmentNameSource
1615
from sentry_sdk.utils import (
1716
capture_internal_exceptions,
1817
ensure_integration_enabled,
1918
event_from_exception,
20-
has_data_collection_enabled,
2119
parse_version,
2220
reraise,
2321
)
@@ -135,12 +133,8 @@ async def _context_enter(request: "Request") -> None:
135133
sentry_sdk.continue_trace(dict(request.headers))
136134
scope.set_custom_sampling_context({"sanic_request": request})
137135

138-
if request.remote_addr:
139-
if has_data_collection_enabled(client.options):
140-
if client.options["data_collection"]["user_info"]:
141-
scope.set_attribute(SPANDATA.USER_IP_ADDRESS, request.remote_addr)
142-
elif should_send_default_pii():
143-
scope.set_attribute(SPANDATA.USER_IP_ADDRESS, request.remote_addr)
136+
if request.remote_addr and client.options["data_collection"]["user_info"]:
137+
scope.set_attribute(SPANDATA.USER_IP_ADDRESS, request.remote_addr)
144138

145139
span = sentry_sdk.start_span(
146140
# Unless the request results in a 404 error, the name and source
@@ -258,35 +252,23 @@ def _get_request_attributes(request: "Request") -> "Dict[str, Any]":
258252
urlparts = urlsplit(request.url)
259253
client_options = sentry_sdk.get_client().options
260254

261-
if has_data_collection_enabled(client_options):
262-
attributes["url.path"] = urlparts.path
255+
attributes["url.path"] = urlparts.path
263256

264-
filtered_query = None
265-
if urlparts.query:
266-
filtered_query = _apply_data_collection_filtering_to_query_string(
267-
query_string=urlparts.query,
268-
behaviour=client_options["data_collection"]["url_query_params"],
269-
)
270-
if filtered_query:
271-
attributes[SPANDATA.HTTP_QUERY] = filtered_query
272-
273-
attributes[SPANDATA.URL_FULL] = urlparts._replace(
274-
query=filtered_query or ""
275-
).geturl()
276-
277-
if request.remote_addr:
278-
if client_options["data_collection"]["user_info"]:
279-
attributes[SPANDATA.CLIENT_ADDRESS] = request.remote_addr
280-
281-
elif should_send_default_pii():
282-
attributes[SPANDATA.URL_FULL] = request.url
283-
attributes["url.path"] = urlparts.path
257+
filtered_query = None
258+
if urlparts.query:
259+
filtered_query = _apply_data_collection_filtering_to_query_string(
260+
query_string=urlparts.query,
261+
behaviour=client_options["data_collection"]["url_query_params"],
262+
)
263+
if filtered_query:
264+
attributes[SPANDATA.HTTP_QUERY] = filtered_query
284265

285-
if urlparts.query:
286-
attributes[SPANDATA.HTTP_QUERY] = urlparts.query
266+
attributes[SPANDATA.URL_FULL] = urlparts._replace(
267+
query=filtered_query or ""
268+
).geturl()
287269

288-
if request.remote_addr:
289-
attributes[SPANDATA.CLIENT_ADDRESS] = request.remote_addr
270+
if request.remote_addr and client_options["data_collection"]["user_info"]:
271+
attributes[SPANDATA.CLIENT_ADDRESS] = request.remote_addr
290272

291273
if urlparts.scheme:
292274
attributes[SPANDATA.NETWORK_PROTOCOL_NAME] = urlparts.scheme
@@ -320,25 +302,17 @@ def sanic_processor(event: "Event", hint: "Optional[Hint]") -> "Optional[Event]"
320302
)
321303

322304
client_options = sentry_sdk.get_client().options
323-
if has_data_collection_enabled(client_options):
324-
if urlparts.query:
325-
filtered_query = _apply_data_collection_filtering_to_query_string(
326-
query_string=urlparts.query,
327-
behaviour=client_options["data_collection"]["url_query_params"],
328-
)
329-
if filtered_query:
330-
request_info["query_string"] = filtered_query
331-
else:
332-
request_info["query_string"] = urlparts.query
305+
if urlparts.query:
306+
filtered_query = _apply_data_collection_filtering_to_query_string(
307+
query_string=urlparts.query,
308+
behaviour=client_options["data_collection"]["url_query_params"],
309+
)
310+
if filtered_query:
311+
request_info["query_string"] = filtered_query
333312

334313
request_info["method"] = request.method
335314

336-
# REMOTE_ADDR was unconditionally set pre-data collection, so it
337-
# continues to be set when data collection is not enabled.
338-
if (
339-
not has_data_collection_enabled(client_options)
340-
or client_options["data_collection"]["user_info"]
341-
):
315+
if client_options["data_collection"]["user_info"]:
342316
request_info["env"] = {"REMOTE_ADDR": request.remote_addr}
343317
request_info["headers"] = _filter_headers(dict(request.headers))
344318

0 commit comments

Comments
 (0)