Skip to content

Commit e43247d

Browse files
ericapisaniclaude
andcommitted
fix(boto3): Gate url.full, url.query, url.fragment behind send_default_pii
URL attributes on streamed spans now require send_default_pii=True, consistent with the aiohttp and wsgi integrations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7787e6d commit e43247d

2 files changed

Lines changed: 32 additions & 21 deletions

File tree

sentry_sdk/integrations/boto3.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sentry_sdk
55
from sentry_sdk.consts import OP, SPANDATA
66
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
7+
from sentry_sdk.scope import should_send_default_pii
78
from sentry_sdk.traces import StreamedSpan
89
from sentry_sdk.tracing import Span
910
from sentry_sdk.tracing_utils import has_span_streaming_enabled
@@ -74,7 +75,7 @@ def _sentry_request_created(
7475
SPANDATA.RPC_METHOD: f"{service_id}/{operation_name}",
7576
},
7677
)
77-
if request.url is not None:
78+
if request.url is not None and should_send_default_pii():
7879
with capture_internal_exceptions():
7980
parsed_url = parse_url(request.url, sanitize=False)
8081
span.set_attribute(SPANDATA.URL_FULL, parsed_url.url)

tests/integrations/boto3/test_s3.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,19 @@ def test_basic(
7272
assert span["description"] == "aws.s3.ListObjects"
7373

7474

75+
@pytest.mark.parametrize("send_default_pii", [True, False])
7576
@pytest.mark.parametrize("span_streaming", [True, False])
7677
def test_streaming(
7778
sentry_init,
7879
capture_events,
7980
capture_items,
8081
span_streaming,
82+
send_default_pii,
8183
):
8284
sentry_init(
8385
traces_sample_rate=1.0,
8486
integrations=[Boto3Integration()],
87+
send_default_pii=send_default_pii,
8588
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},
8689
)
8790

@@ -108,26 +111,32 @@ def test_streaming(
108111
span1 = spans[0]
109112
assert span1["attributes"]["sentry.op"] == "http.client"
110113
assert span1["name"] == "aws.s3.GetObject"
111-
assert span1["attributes"] == ApproxDict(
112-
{
113-
"http.request.method": "GET",
114-
"rpc.method": "S3/GetObject",
115-
"sentry.environment": "production",
116-
"sentry.op": "http.client",
117-
"sentry.origin": "auto.http.boto3",
118-
"sentry.release": mock.ANY,
119-
"sentry.sdk.name": "sentry.python",
120-
"sentry.sdk.version": mock.ANY,
121-
"sentry.segment.id": mock.ANY,
122-
"sentry.segment.name": "custom parent",
123-
"server.address": mock.ANY,
124-
"thread.id": mock.ANY,
125-
"thread.name": mock.ANY,
126-
"url.full": "https://bucket.s3.amazonaws.com/foo.pdf",
127-
"url.fragment": "",
128-
"url.query": "",
129-
}
130-
)
114+
115+
expected_attrs = {
116+
"http.request.method": "GET",
117+
"rpc.method": "S3/GetObject",
118+
"sentry.environment": "production",
119+
"sentry.op": "http.client",
120+
"sentry.origin": "auto.http.boto3",
121+
"sentry.release": mock.ANY,
122+
"sentry.sdk.name": "sentry.python",
123+
"sentry.sdk.version": mock.ANY,
124+
"sentry.segment.id": mock.ANY,
125+
"sentry.segment.name": "custom parent",
126+
"server.address": mock.ANY,
127+
"thread.id": mock.ANY,
128+
"thread.name": mock.ANY,
129+
}
130+
if send_default_pii:
131+
expected_attrs["url.full"] = "https://bucket.s3.amazonaws.com/foo.pdf"
132+
expected_attrs["url.fragment"] = ""
133+
expected_attrs["url.query"] = ""
134+
assert span1["attributes"] == ApproxDict(expected_attrs)
135+
136+
if not send_default_pii:
137+
assert "url.full" not in span1["attributes"]
138+
assert "url.fragment" not in span1["attributes"]
139+
assert "url.query" not in span1["attributes"]
131140

132141
span2 = spans[1]
133142
assert span2["attributes"]["sentry.op"] == "http.client.stream"
@@ -233,6 +242,7 @@ def test_omit_url_data_if_parsing_fails(
233242
sentry_init(
234243
traces_sample_rate=1.0,
235244
integrations=[Boto3Integration()],
245+
send_default_pii=True,
236246
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},
237247
)
238248

0 commit comments

Comments
 (0)