|
11 | 11 | ) |
12 | 12 | from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version |
13 | 13 | from sentry_sdk.integrations._wsgi_common import RequestExtractor, _filter_headers |
14 | | -from sentry_sdk.scope import should_send_default_pii |
15 | 14 | from sentry_sdk.traces import SegmentNameSource |
16 | 15 | from sentry_sdk.utils import ( |
17 | 16 | capture_internal_exceptions, |
18 | 17 | ensure_integration_enabled, |
19 | 18 | event_from_exception, |
20 | | - has_data_collection_enabled, |
21 | 19 | parse_version, |
22 | 20 | reraise, |
23 | 21 | ) |
@@ -135,12 +133,8 @@ async def _context_enter(request: "Request") -> None: |
135 | 133 | sentry_sdk.continue_trace(dict(request.headers)) |
136 | 134 | scope.set_custom_sampling_context({"sanic_request": request}) |
137 | 135 |
|
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) |
144 | 138 |
|
145 | 139 | span = sentry_sdk.start_span( |
146 | 140 | # 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]": |
258 | 252 | urlparts = urlsplit(request.url) |
259 | 253 | client_options = sentry_sdk.get_client().options |
260 | 254 |
|
261 | | - if has_data_collection_enabled(client_options): |
262 | | - attributes["url.path"] = urlparts.path |
| 255 | + attributes["url.path"] = urlparts.path |
263 | 256 |
|
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 |
284 | 265 |
|
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() |
287 | 269 |
|
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 |
290 | 272 |
|
291 | 273 | if urlparts.scheme: |
292 | 274 | attributes[SPANDATA.NETWORK_PROTOCOL_NAME] = urlparts.scheme |
@@ -320,25 +302,17 @@ def sanic_processor(event: "Event", hint: "Optional[Hint]") -> "Optional[Event]" |
320 | 302 | ) |
321 | 303 |
|
322 | 304 | 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 |
333 | 312 |
|
334 | 313 | request_info["method"] = request.method |
335 | 314 |
|
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"]: |
342 | 316 | request_info["env"] = {"REMOTE_ADDR": request.remote_addr} |
343 | 317 | request_info["headers"] = _filter_headers(dict(request.headers)) |
344 | 318 |
|
|
0 commit comments