File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -121,6 +121,7 @@ def _get_request_attributes(asgi_scope: "Any") -> "dict[str, Any]":
121121 for header , value in headers .items ():
122122 attributes [f"http.request.header.{ header .lower ()} " ] = value
123123
124+ if should_send_default_pii ():
124125 query = _get_query (asgi_scope )
125126 if query :
126127 attributes ["http.query" ] = query
@@ -129,9 +130,9 @@ def _get_request_attributes(asgi_scope: "Any") -> "dict[str, Any]":
129130 asgi_scope , "http" if ty == "http" else "ws" , headers .get ("host" )
130131 )
131132
132- client = asgi_scope .get ("client" )
133- if client and should_send_default_pii () :
134- ip = _get_ip (asgi_scope )
135- attributes ["client.address" ] = ip
133+ client = asgi_scope .get ("client" )
134+ if client :
135+ ip = _get_ip (asgi_scope )
136+ attributes ["client.address" ] = ip
136137
137138 return attributes
Original file line number Diff line number Diff line change @@ -164,6 +164,10 @@ def test_invalid_transaction_style(asgi3_app):
164164
165165
166166@pytest .mark .asyncio
167+ @pytest .mark .parametrize (
168+ "should_send_pii" ,
169+ [True , False ],
170+ )
167171@pytest .mark .parametrize (
168172 "span_streaming" ,
169173 [True , False ],
@@ -174,9 +178,10 @@ async def test_capture_transaction(
174178 capture_events ,
175179 capture_items ,
176180 span_streaming ,
181+ should_send_pii ,
177182):
178183 sentry_init (
179- send_default_pii = True ,
184+ send_default_pii = should_send_pii ,
180185 traces_sample_rate = 1.0 ,
181186 _experiments = {
182187 "trace_lifecycle" : "stream" if span_streaming else "static" ,
@@ -203,16 +208,18 @@ async def test_capture_transaction(
203208 assert span ["attributes" ]["sentry.span.source" ] == "url"
204209 assert span ["attributes" ]["sentry.op" ] == "http.server"
205210
206- assert span ["attributes" ]["url.full" ] == "http://localhost/some_url"
207211 assert span ["attributes" ]["network.protocol.name" ] == "http"
208212 assert span ["attributes" ]["http.request.method" ] == "GET"
209- assert span ["attributes" ]["http.query" ] == "somevalue=123"
210213 assert span ["attributes" ]["http.request.header.host" ] == "localhost"
211214 assert span ["attributes" ]["http.request.header.remote-addr" ] == "127.0.0.1"
212215 assert (
213216 span ["attributes" ]["http.request.header.user-agent" ] == "ASGI-Test-Client"
214217 )
215218
219+ if should_send_pii :
220+ assert span ["attributes" ]["url.full" ] == "http://localhost/some_url"
221+ assert span ["attributes" ]["http.query" ] == "somevalue=123"
222+
216223 else :
217224 (transaction_event ,) = events
218225
You can’t perform that action at this time.
0 commit comments