Skip to content

Commit b5d5d3d

Browse files
committed
ref(tornado): Drop send_default_pii support
1 parent b5b96b8 commit b5d5d3d

1 file changed

Lines changed: 28 additions & 69 deletions

File tree

‎sentry_sdk/integrations/tornado.py‎

Lines changed: 28 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
request_body_within_bounds,
1313
)
1414
from sentry_sdk.integrations.logging import ignore_logger_for_events
15-
from sentry_sdk.scope import should_send_default_pii
1615
from sentry_sdk.traces import SegmentNameSource
1716
from sentry_sdk.utils import (
1817
AnnotatedValue,
1918
capture_internal_exceptions,
2019
ensure_integration_enabled,
2120
event_from_exception,
22-
has_data_collection_enabled,
2321
parse_url,
2422
transaction_from_function,
2523
)
@@ -98,14 +96,8 @@ def _handle_request_impl(self: "RequestHandler") -> "Generator[None, None, None]
9896
sentry_sdk.continue_trace(dict(headers))
9997
scope.set_custom_sampling_context({"tornado_request": self.request})
10098

101-
if self.request.remote_ip:
102-
if has_data_collection_enabled(client.options):
103-
if client.options["data_collection"]["user_info"]:
104-
scope.set_attribute(
105-
SPANDATA.USER_IP_ADDRESS, self.request.remote_ip
106-
)
107-
elif should_send_default_pii():
108-
scope.set_attribute(SPANDATA.USER_IP_ADDRESS, self.request.remote_ip)
99+
if self.request.remote_ip and client.options["data_collection"]["user_info"]:
100+
scope.set_attribute(SPANDATA.USER_IP_ADDRESS, self.request.remote_ip)
109101

110102
with sentry_sdk.start_span(
111103
name=_DEFAULT_ROOT_SPAN_NAME,
@@ -151,47 +143,31 @@ def _get_request_attributes(request: "Any") -> "Dict[str, Any]":
151143
for header, value in headers.items():
152144
attributes[f"{SPANDATA.HTTP_REQUEST_HEADER}.{header.lower()}"] = value
153145

154-
if has_data_collection_enabled(client_options):
155-
attributes["url.path"] = request.path
146+
attributes["url.path"] = request.path
156147

157-
filtered_query = None
158-
if request.query:
159-
filtered_query = _apply_data_collection_filtering_to_query_string(
160-
query_string=request.query,
161-
behaviour=client_options["data_collection"]["url_query_params"],
162-
)
163-
if filtered_query:
164-
attributes[SPANDATA.URL_QUERY] = filtered_query
165-
166-
parsed_url = parse_url(request.full_url())
167-
attributes[SPANDATA.URL_FULL] = (
168-
f"{parsed_url.url}?{filtered_query}" if filtered_query else parsed_url.url
148+
filtered_query = None
149+
if request.query:
150+
filtered_query = _apply_data_collection_filtering_to_query_string(
151+
query_string=request.query,
152+
behaviour=client_options["data_collection"]["url_query_params"],
169153
)
154+
if filtered_query:
155+
attributes[SPANDATA.URL_QUERY] = filtered_query
170156

171-
if request.remote_ip:
172-
if client_options["data_collection"]["user_info"]:
173-
attributes[SPANDATA.CLIENT_ADDRESS] = request.remote_ip
174-
175-
elif should_send_default_pii():
176-
attributes[SPANDATA.URL_FULL] = request.full_url()
177-
attributes["url.path"] = request.path
178-
179-
if request.query:
180-
attributes[SPANDATA.URL_QUERY] = request.query
157+
parsed_url = parse_url(request.full_url())
158+
attributes[SPANDATA.URL_FULL] = (
159+
f"{parsed_url.url}?{filtered_query}" if filtered_query else parsed_url.url
160+
)
181161

182-
if request.remote_ip:
183-
attributes[SPANDATA.CLIENT_ADDRESS] = request.remote_ip
162+
if request.remote_ip and client_options["data_collection"]["user_info"]:
163+
attributes[SPANDATA.CLIENT_ADDRESS] = request.remote_ip
184164

185165
if request.protocol:
186166
attributes[SPANDATA.NETWORK_PROTOCOL_NAME] = request.protocol
187167

188-
# The request data was unconditionally set pre-data collection which is
189-
# why we're defaulting to True
190-
record_incoming_request_data = True
191-
if has_data_collection_enabled(client_options):
192-
record_incoming_request_data = (
193-
"incoming_request" in client_options["data_collection"]["http_bodies"]
194-
)
168+
record_incoming_request_data = (
169+
"incoming_request" in client_options["data_collection"]["http_bodies"]
170+
)
195171

196172
if record_incoming_request_data:
197173
with capture_internal_exceptions():
@@ -260,38 +236,21 @@ def tornado_processor(event: "Event", hint: "dict[str, Any]") -> "Event":
260236
request.path,
261237
)
262238

263-
if has_data_collection_enabled(client_options):
264-
if request.query:
265-
filtered_query = _apply_data_collection_filtering_to_query_string(
266-
query_string=request.query,
267-
behaviour=client_options["data_collection"]["url_query_params"],
268-
)
269-
if filtered_query:
270-
request_info["query_string"] = filtered_query
271-
else:
272-
request_info["query_string"] = request.query
239+
if request.query:
240+
filtered_query = _apply_data_collection_filtering_to_query_string(
241+
query_string=request.query,
242+
behaviour=client_options["data_collection"]["url_query_params"],
243+
)
244+
if filtered_query:
245+
request_info["query_string"] = filtered_query
273246

274247
request_info["method"] = request.method
275248

276-
# REMOTE_ADDR was unconditionally set pre-data collection, so it
277-
# continues to be set when data collection is not enabled.
278-
if (
279-
not has_data_collection_enabled(client_options)
280-
or client_options["data_collection"]["user_info"]
281-
):
249+
if client_options["data_collection"]["user_info"]:
282250
request_info["env"] = {"REMOTE_ADDR": request.remote_ip}
283251
request_info["headers"] = _filter_headers(dict(request.headers))
284252

285-
if has_data_collection_enabled(client_options):
286-
if client_options["data_collection"]["user_info"]:
287-
try:
288-
current_user = handler.current_user
289-
except Exception:
290-
current_user = None
291-
292-
if current_user:
293-
event.setdefault("user", {}).setdefault("is_authenticated", True)
294-
elif should_send_default_pii():
253+
if client_options["data_collection"]["user_info"]:
295254
try:
296255
current_user = handler.current_user
297256
except Exception:

0 commit comments

Comments
 (0)