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
@@ -126,19 +124,14 @@ def _get_request_data(
126124 use_annotated_value = False ,
127125 )
128126
129- if has_data_collection_enabled (client_options ):
130- qs = _get_query (asgi_scope )
131- if qs :
132- filtered_query_string = (
133- _apply_data_collection_filtering_to_query_string (
134- query_string = qs ,
135- behaviour = client_options ["data_collection" ]["url_query_params" ],
136- )
137- )
138- if filtered_query_string :
139- request_data ["query_string" ] = filtered_query_string
140- else :
141- request_data ["query_string" ] = _get_query (asgi_scope )
127+ qs = _get_query (asgi_scope )
128+ if qs :
129+ filtered_query_string = _apply_data_collection_filtering_to_query_string (
130+ query_string = qs ,
131+ behaviour = client_options ["data_collection" ]["url_query_params" ],
132+ )
133+ if filtered_query_string :
134+ request_data ["query_string" ] = filtered_query_string
142135
143136 request_data ["url" ] = _get_url (
144137 asgi_scope ,
@@ -149,10 +142,7 @@ def _get_request_data(
149142
150143 client = asgi_scope .get ("client" )
151144 if client :
152- if has_data_collection_enabled (client_options ):
153- if client_options ["data_collection" ]["user_info" ]:
154- request_data ["env" ] = {"REMOTE_ADDR" : _get_ip (asgi_scope )}
155- elif should_send_default_pii ():
145+ if client_options ["data_collection" ]["user_info" ]:
156146 request_data ["env" ] = {"REMOTE_ADDR" : _get_ip (asgi_scope )}
157147
158148 return request_data
@@ -179,65 +169,36 @@ def _get_request_attributes(
179169 for header , value in filtered_headers .items ():
180170 attributes [f"http.request.header.{ header .lower ()} " ] = value
181171
182- if has_data_collection_enabled (client_options ):
183- filtered_query_string = None
184- query = _get_query (asgi_scope )
185-
186- if query :
187- filtered_query_string = (
188- _apply_data_collection_filtering_to_query_string (
189- query_string = query ,
190- behaviour = client_options ["data_collection" ]["url_query_params" ],
191- )
192- )
193- if filtered_query_string :
194- attributes ["http.query" ] = filtered_query_string
195-
196- path = _get_path (asgi_scope = asgi_scope , root_path_in_path = root_path_in_path )
197- attributes ["url.path" ] = path
198-
199- url_without_query_string = _get_url (
200- asgi_scope ,
201- "http" if ty == "http" else "ws" ,
202- headers .get ("host" ),
203- path = path ,
204- )
172+ filtered_query_string = None
173+ query = _get_query (asgi_scope )
205174
206- attributes [ "url.full" ] = (
207- f" { url_without_query_string } ? { filtered_query_string } "
208- if filtered_query_string is not None
209- else url_without_query_string
175+ if query :
176+ filtered_query_string = _apply_data_collection_filtering_to_query_string (
177+ query_string = query ,
178+ behaviour = client_options [ "data_collection" ][ "url_query_params" ],
210179 )
180+ if filtered_query_string :
181+ attributes ["http.query" ] = filtered_query_string
211182
212- elif should_send_default_pii ():
213- query = _get_query (asgi_scope )
214- if query :
215- attributes ["http.query" ] = query
183+ path = _get_path (asgi_scope = asgi_scope , root_path_in_path = root_path_in_path )
184+ attributes ["url.path" ] = path
216185
217- path = _get_path (asgi_scope = asgi_scope , root_path_in_path = root_path_in_path )
218- attributes ["url.path" ] = path
186+ url_without_query_string = _get_url (
187+ asgi_scope ,
188+ "http" if ty == "http" else "ws" ,
189+ headers .get ("host" ),
190+ path = path ,
191+ )
219192
220- url_without_query_string = _get_url (
221- asgi_scope ,
222- "http" if ty == "http" else "ws" ,
223- headers .get ("host" ),
224- path = path ,
225- )
226- query_string = _get_query (asgi_scope )
227- attributes ["url.full" ] = (
228- f"{ url_without_query_string } ?{ query_string } "
229- if query_string is not None
230- else url_without_query_string
231- )
193+ attributes ["url.full" ] = (
194+ f"{ url_without_query_string } ?{ filtered_query_string } "
195+ if filtered_query_string is not None
196+ else url_without_query_string
197+ )
232198
233199 asgi_scope_client = asgi_scope .get ("client" )
234200 if asgi_scope_client :
235- if has_data_collection_enabled (client_options ):
236- if client_options ["data_collection" ]["user_info" ]:
237- ip = _get_ip (asgi_scope )
238- attributes ["client.address" ] = ip
239- elif should_send_default_pii ():
201+ if client_options ["data_collection" ]["user_info" ]:
240202 ip = _get_ip (asgi_scope )
241203 attributes ["client.address" ] = ip
242-
243204 return attributes
0 commit comments