|
12 | 12 | request_body_within_bounds, |
13 | 13 | ) |
14 | 14 | from sentry_sdk.integrations.logging import ignore_logger_for_events |
15 | | -from sentry_sdk.scope import should_send_default_pii |
16 | 15 | from sentry_sdk.traces import SegmentNameSource |
17 | 16 | from sentry_sdk.utils import ( |
18 | 17 | AnnotatedValue, |
19 | 18 | capture_internal_exceptions, |
20 | 19 | ensure_integration_enabled, |
21 | 20 | event_from_exception, |
22 | | - has_data_collection_enabled, |
23 | 21 | parse_url, |
24 | 22 | transaction_from_function, |
25 | 23 | ) |
@@ -98,14 +96,8 @@ def _handle_request_impl(self: "RequestHandler") -> "Generator[None, None, None] |
98 | 96 | sentry_sdk.continue_trace(dict(headers)) |
99 | 97 | scope.set_custom_sampling_context({"tornado_request": self.request}) |
100 | 98 |
|
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) |
109 | 101 |
|
110 | 102 | with sentry_sdk.start_span( |
111 | 103 | name=_DEFAULT_ROOT_SPAN_NAME, |
@@ -151,47 +143,31 @@ def _get_request_attributes(request: "Any") -> "Dict[str, Any]": |
151 | 143 | for header, value in headers.items(): |
152 | 144 | attributes[f"{SPANDATA.HTTP_REQUEST_HEADER}.{header.lower()}"] = value |
153 | 145 |
|
154 | | - if has_data_collection_enabled(client_options): |
155 | | - attributes["url.path"] = request.path |
| 146 | + attributes["url.path"] = request.path |
156 | 147 |
|
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"], |
169 | 153 | ) |
| 154 | + if filtered_query: |
| 155 | + attributes[SPANDATA.URL_QUERY] = filtered_query |
170 | 156 |
|
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 | + ) |
181 | 161 |
|
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 |
184 | 164 |
|
185 | 165 | if request.protocol: |
186 | 166 | attributes[SPANDATA.NETWORK_PROTOCOL_NAME] = request.protocol |
187 | 167 |
|
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 | + ) |
195 | 171 |
|
196 | 172 | if record_incoming_request_data: |
197 | 173 | with capture_internal_exceptions(): |
@@ -260,38 +236,21 @@ def tornado_processor(event: "Event", hint: "dict[str, Any]") -> "Event": |
260 | 236 | request.path, |
261 | 237 | ) |
262 | 238 |
|
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 |
273 | 246 |
|
274 | 247 | request_info["method"] = request.method |
275 | 248 |
|
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"]: |
282 | 250 | request_info["env"] = {"REMOTE_ADDR": request.remote_ip} |
283 | 251 | request_info["headers"] = _filter_headers(dict(request.headers)) |
284 | 252 |
|
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"]: |
295 | 254 | try: |
296 | 255 | current_user = handler.current_user |
297 | 256 | except Exception: |
|
0 commit comments