55import sentry_sdk
66from sentry_sdk .data_collection import _apply_data_collection_filtering_to_query_string
77from 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
119if TYPE_CHECKING :
1210 from typing import Any , Dict , Optional , Union
@@ -123,19 +121,14 @@ def _get_request_data(
123121
124122 request_data ["headers" ] = _filter_headers (headers )
125123
126- if has_data_collection_enabled (client_options ):
127- qs = _get_query (asgi_scope )
128- if qs :
129- filtered_query_string = (
130- _apply_data_collection_filtering_to_query_string (
131- query_string = qs ,
132- behaviour = client_options ["data_collection" ]["url_query_params" ],
133- )
134- )
135- if filtered_query_string :
136- request_data ["query_string" ] = filtered_query_string
137- else :
138- request_data ["query_string" ] = _get_query (asgi_scope )
124+ qs = _get_query (asgi_scope )
125+ if qs :
126+ filtered_query_string = _apply_data_collection_filtering_to_query_string (
127+ query_string = qs ,
128+ behaviour = client_options ["data_collection" ]["url_query_params" ],
129+ )
130+ if filtered_query_string :
131+ request_data ["query_string" ] = filtered_query_string
139132
140133 request_data ["url" ] = _get_url (
141134 asgi_scope ,
@@ -146,10 +139,7 @@ def _get_request_data(
146139
147140 client = asgi_scope .get ("client" )
148141 if client :
149- if has_data_collection_enabled (client_options ):
150- if client_options ["data_collection" ]["user_info" ]:
151- request_data ["env" ] = {"REMOTE_ADDR" : _get_ip (asgi_scope )}
152- elif should_send_default_pii ():
142+ if client_options ["data_collection" ]["user_info" ]:
153143 request_data ["env" ] = {"REMOTE_ADDR" : _get_ip (asgi_scope )}
154144
155145 return request_data
@@ -176,65 +166,36 @@ def _get_request_attributes(
176166 for header , value in filtered_headers .items ():
177167 attributes [f"http.request.header.{ header .lower ()} " ] = value
178168
179- if has_data_collection_enabled (client_options ):
180- filtered_query_string = None
181- query = _get_query (asgi_scope )
182-
183- if query :
184- filtered_query_string = (
185- _apply_data_collection_filtering_to_query_string (
186- query_string = query ,
187- behaviour = client_options ["data_collection" ]["url_query_params" ],
188- )
189- )
190- if filtered_query_string :
191- attributes ["http.query" ] = filtered_query_string
192-
193- path = _get_path (asgi_scope = asgi_scope , root_path_in_path = root_path_in_path )
194- attributes ["url.path" ] = path
195-
196- url_without_query_string = _get_url (
197- asgi_scope ,
198- "http" if ty == "http" else "ws" ,
199- headers .get ("host" ),
200- path = path ,
201- )
169+ filtered_query_string = None
170+ query = _get_query (asgi_scope )
202171
203- attributes [ "url.full" ] = (
204- f" { url_without_query_string } ? { filtered_query_string } "
205- if filtered_query_string is not None
206- else url_without_query_string
172+ if query :
173+ filtered_query_string = _apply_data_collection_filtering_to_query_string (
174+ query_string = query ,
175+ behaviour = client_options [ "data_collection" ][ "url_query_params" ],
207176 )
177+ if filtered_query_string :
178+ attributes ["http.query" ] = filtered_query_string
208179
209- elif should_send_default_pii ():
210- query = _get_query (asgi_scope )
211- if query :
212- attributes ["http.query" ] = query
180+ path = _get_path (asgi_scope = asgi_scope , root_path_in_path = root_path_in_path )
181+ attributes ["url.path" ] = path
213182
214- path = _get_path (asgi_scope = asgi_scope , root_path_in_path = root_path_in_path )
215- attributes ["url.path" ] = path
183+ url_without_query_string = _get_url (
184+ asgi_scope ,
185+ "http" if ty == "http" else "ws" ,
186+ headers .get ("host" ),
187+ path = path ,
188+ )
216189
217- url_without_query_string = _get_url (
218- asgi_scope ,
219- "http" if ty == "http" else "ws" ,
220- headers .get ("host" ),
221- path = path ,
222- )
223- query_string = _get_query (asgi_scope )
224- attributes ["url.full" ] = (
225- f"{ url_without_query_string } ?{ query_string } "
226- if query_string is not None
227- else url_without_query_string
228- )
190+ attributes ["url.full" ] = (
191+ f"{ url_without_query_string } ?{ filtered_query_string } "
192+ if filtered_query_string is not None
193+ else url_without_query_string
194+ )
229195
230196 asgi_scope_client = asgi_scope .get ("client" )
231197 if asgi_scope_client :
232- if has_data_collection_enabled (client_options ):
233- if client_options ["data_collection" ]["user_info" ]:
234- ip = _get_ip (asgi_scope )
235- attributes ["client.address" ] = ip
236- elif should_send_default_pii ():
198+ if client_options ["data_collection" ]["user_info" ]:
237199 ip = _get_ip (asgi_scope )
238200 attributes ["client.address" ] = ip
239-
240201 return attributes
0 commit comments