Skip to content

Commit a1913eb

Browse files
ref(boto3): Drop send_default_pii support (#7684)
### Description - remove `send_default_pii` branching in `tests_s3.py`. - Remove `send_default_pii` fallback from `tracing_utils.get_url_attributes()` #### Issues Resolves #7658
1 parent b2d5572 commit a1913eb

6 files changed

Lines changed: 63 additions & 67 deletions

File tree

‎sentry_sdk/integrations/httpx.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from sentry_sdk.tracing_utils import (
88
add_http_breadcrumb,
99
add_http_request_source,
10-
get_url_attributes,
10+
get_url_attributes_legacy,
1111
propagate_trace_headers,
1212
)
1313
from sentry_sdk.utils import (
@@ -59,7 +59,7 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response":
5959
with capture_internal_exceptions():
6060
parsed_url = parse_url(str(request.url), sanitize=False)
6161

62-
url_attributes = get_url_attributes(client, parsed_url)
62+
url_attributes = get_url_attributes_legacy(client, parsed_url)
6363

6464
if sentry_sdk.get_current_span() is None:
6565
span_ctx = nullcontext()
@@ -148,7 +148,7 @@ async def send(
148148
},
149149
)
150150

151-
url_attributes = get_url_attributes(client, parsed_url)
151+
url_attributes = get_url_attributes_legacy(client, parsed_url)
152152

153153
with span_ctx as span:
154154
propagate_trace_headers(client, request)

‎sentry_sdk/integrations/httpx2.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from sentry_sdk.tracing_utils import (
88
add_http_breadcrumb,
99
add_http_request_source,
10-
get_url_attributes,
10+
get_url_attributes_legacy,
1111
propagate_trace_headers,
1212
)
1313
from sentry_sdk.utils import (
@@ -59,7 +59,7 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response":
5959
with capture_internal_exceptions():
6060
parsed_url = parse_url(str(request.url), sanitize=False)
6161

62-
url_attributes = get_url_attributes(client, parsed_url)
62+
url_attributes = get_url_attributes_legacy(client, parsed_url)
6363

6464
if sentry_sdk.get_current_span() is None:
6565
span_ctx = nullcontext()
@@ -148,7 +148,7 @@ async def send(
148148
},
149149
)
150150

151-
url_attributes = get_url_attributes(client, parsed_url)
151+
url_attributes = get_url_attributes_legacy(client, parsed_url)
152152

153153
with span_ctx as span:
154154
propagate_trace_headers(client, request)

‎sentry_sdk/integrations/pyreqwest.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from sentry_sdk.tracing_utils import (
88
add_http_breadcrumb,
99
add_http_request_source,
10-
get_url_attributes,
10+
get_url_attributes_legacy,
1111
propagate_trace_headers,
1212
)
1313
from sentry_sdk.utils import (
@@ -155,7 +155,7 @@ async def sentry_async_middleware(
155155
# after the request has been sent
156156
parsed_url = parse_url(str(request.url), sanitize=False)
157157

158-
url_attributes = get_url_attributes(sentry_sdk.get_client(), parsed_url)
158+
url_attributes = get_url_attributes_legacy(sentry_sdk.get_client(), parsed_url)
159159

160160
response = None
161161
with _sentry_pyreqwest_span(request, url_attributes) as span:
@@ -193,7 +193,7 @@ def sentry_sync_middleware(
193193
# after the request has been sent
194194
parsed_url = parse_url(str(request.url), sanitize=False)
195195

196-
url_attributes = get_url_attributes(sentry_sdk.get_client(), parsed_url)
196+
url_attributes = get_url_attributes_legacy(sentry_sdk.get_client(), parsed_url)
197197

198198
response = None
199199
with _sentry_pyreqwest_span(request, url_attributes) as span:

‎sentry_sdk/integrations/stdlib.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
EnvironHeaders,
1515
add_http_breadcrumb,
1616
add_http_request_source,
17-
get_url_attributes,
17+
get_url_attributes_legacy,
1818
should_propagate_trace,
1919
)
2020
from sentry_sdk.utils import (
@@ -274,7 +274,7 @@ def putrequest(
274274
span: "Optional[Span]" = None
275275
breadcrumb: "dict[str, Any]" = {}
276276

277-
url_attributes = get_url_attributes(client, parsed_url)
277+
url_attributes = get_url_attributes_legacy(client, parsed_url)
278278

279279
breadcrumb[SPANDATA.HTTP_REQUEST_METHOD] = method
280280
breadcrumb.update(url_attributes)

‎sentry_sdk/tracing_utils.py‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,9 @@ def add_http_breadcrumb(status_code: "Optional[int]", data: "dict[str, Any]") ->
191191
sentry_sdk.add_breadcrumb(**kwargs)
192192

193193

194-
def get_url_attributes(
195-
client: "sentry_sdk.client.BaseClient", parsed_url: "Optional[ParsedUrl]"
194+
def get_url_attributes_legacy(
195+
client: "sentry_sdk.client.BaseClient",
196+
parsed_url: "Optional[ParsedUrl]",
196197
) -> "Attributes":
197198
"""Build the `url.*` span attributes for an outgoing HTTP request.
198199
@@ -231,6 +232,40 @@ def get_url_attributes(
231232
return attributes
232233

233234

235+
def get_url_attributes(
236+
client: "sentry_sdk.client.BaseClient",
237+
parsed_url: "Optional[ParsedUrl]",
238+
) -> "Attributes":
239+
"""Build the `url.*` span attributes for an outgoing HTTP request.
240+
241+
The query string is filtered through the resolved `data_collection`
242+
settings.
243+
"""
244+
attributes: "Attributes" = {}
245+
if parsed_url is None:
246+
return attributes
247+
248+
query: "Optional[str]" = None
249+
if parsed_url.query:
250+
query = _apply_data_collection_filtering_to_query_string(
251+
query_string=parsed_url.query,
252+
behaviour=client.options["data_collection"]["url_query_params"],
253+
)
254+
255+
url_full = parsed_url.url
256+
if query:
257+
attributes[SPANDATA.URL_QUERY] = query
258+
url_full += "?" + query
259+
260+
if parsed_url.fragment:
261+
attributes[SPANDATA.URL_FRAGMENT] = parsed_url.fragment
262+
url_full += "#" + parsed_url.fragment
263+
264+
attributes[SPANDATA.URL_FULL] = url_full
265+
266+
return attributes
267+
268+
234269
def _get_frame_module_abs_path(frame: "FrameType") -> "Optional[str]":
235270
try:
236271
return frame.f_code.co_filename

‎tests/integrations/boto3/test_s3.py‎

Lines changed: 15 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,11 @@ def test_basic(
5050
assert span["name"] == "aws.s3.ListObjects"
5151

5252

53-
@pytest.mark.parametrize("send_default_pii", [True, False])
54-
def test_streaming(
55-
sentry_init,
56-
capture_events,
57-
capture_items,
58-
send_default_pii,
59-
):
53+
def test_streaming(sentry_init, capture_events, capture_items):
6054
sentry_init(
6155
traces_sample_rate=1.0,
6256
integrations=[Boto3Integration()],
63-
send_default_pii=send_default_pii,
57+
data_collection={},
6458
)
6559

6660
s3 = session.resource("s3")
@@ -101,15 +95,11 @@ def test_streaming(
10195
"thread.id": mock.ANY,
10296
"thread.name": mock.ANY,
10397
}
104-
if send_default_pii:
105-
expected_attrs["url.full"] = "https://bucket.s3.amazonaws.com/foo.pdf"
98+
expected_attrs["url.full"] = "https://bucket.s3.amazonaws.com/foo.pdf"
10699
assert span1["attributes"] == ApproxDict(expected_attrs)
107100

108101
assert "url.fragment" not in span1["attributes"]
109102
assert "url.query" not in span1["attributes"]
110-
if not send_default_pii:
111-
assert "url.full" not in span1["attributes"]
112-
113103
span2 = spans[1]
114104
assert span2["attributes"]["sentry.op"] == "http.client.stream"
115105
assert span2["name"] == "aws.s3.GetObject"
@@ -157,7 +147,7 @@ def test_omit_url_data_if_parsing_fails(
157147
sentry_init(
158148
traces_sample_rate=1.0,
159149
integrations=[Boto3Integration()],
160-
send_default_pii=True,
150+
data_collection={},
161151
)
162152

163153
s3 = session.resource("s3")
@@ -228,12 +218,11 @@ def test_span_origin(
228218
assert spans[0]["attributes"]["sentry.origin"] == "auto.http.boto3"
229219

230220

231-
@pytest.mark.parametrize("send_default_pii", [True, False])
232-
def test_breadcrumb(sentry_init, capture_events, send_default_pii):
221+
def test_breadcrumb(sentry_init, capture_events):
233222
sentry_init(
234223
integrations=[Boto3Integration()],
235224
default_integrations=False,
236-
send_default_pii=send_default_pii,
225+
data_collection={},
237226
)
238227

239228
s3 = session.resource("s3")
@@ -253,24 +242,14 @@ def test_breadcrumb(sentry_init, capture_events, send_default_pii):
253242
assert crumb["type"] == "http"
254243
assert crumb["category"] == "httplib"
255244

256-
if send_default_pii:
257-
assert crumb["data"] == ApproxDict(
258-
{
259-
SPANDATA.URL_FULL: mock.ANY,
260-
SPANDATA.HTTP_REQUEST_METHOD: "GET",
261-
SPANDATA.URL_QUERY: mock.ANY,
262-
}
263-
)
264-
assert SPANDATA.URL_FRAGMENT not in crumb["data"]
265-
else:
266-
assert crumb["data"] == ApproxDict(
267-
{
268-
SPANDATA.HTTP_REQUEST_METHOD: "GET",
269-
}
270-
)
271-
assert SPANDATA.URL_FULL not in crumb["data"]
272-
assert SPANDATA.URL_QUERY not in crumb["data"]
273-
assert SPANDATA.URL_FRAGMENT not in crumb["data"]
245+
assert crumb["data"] == ApproxDict(
246+
{
247+
SPANDATA.URL_FULL: mock.ANY,
248+
SPANDATA.HTTP_REQUEST_METHOD: "GET",
249+
SPANDATA.URL_QUERY: mock.ANY,
250+
}
251+
)
252+
assert SPANDATA.URL_FRAGMENT not in crumb["data"]
274253

275254

276255
BUCKET_URL = "https://bucket.s3.amazonaws.com/"
@@ -279,19 +258,9 @@ def test_breadcrumb(sentry_init, capture_events, send_default_pii):
279258
# means the URL is recorded without a query string.
280259
# Structure of the parameters is "init_kwargs, expected_query"
281260
URL_QUERY_PARAMS = [
282-
pytest.param(
283-
{"send_default_pii": True},
284-
"list-type=2&prefix=foo&continuation-token=abc&encoding-type=url",
285-
id="send_default_pii_true",
286-
),
287-
pytest.param(
288-
{"send_default_pii": False},
289-
None,
290-
id="send_default_pii_false",
291-
),
292261
pytest.param(
293262
{},
294-
None,
263+
"list-type=2&prefix=foo&continuation-token=%5BFiltered%5D&encoding-type=url",
295264
id="defaults",
296265
),
297266
pytest.param(
@@ -334,14 +303,6 @@ def test_breadcrumb(sentry_init, capture_events, send_default_pii):
334303
"",
335304
id="data_collection_off",
336305
),
337-
pytest.param(
338-
{
339-
"send_default_pii": True,
340-
"data_collection": {"url_query_params": {"mode": "off"}},
341-
},
342-
"",
343-
id="data_collection_wins_over_send_default_pii",
344-
),
345306
]
346307

347308

0 commit comments

Comments
 (0)