From 25da37702b1c2ee192abc53a5dfc90ddae86dba0 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Wed, 23 Sep 2026 11:15:27 +0200 Subject: [PATCH 1/6] ref(aiohttp): Remove support for send_default_pii --- sentry_sdk/integrations/aiohttp.py | 162 +++++++-------------- tests/integrations/aiohttp/test_aiohttp.py | 116 ++------------- tests/integrations/utils.py | 10 -- 3 files changed, 61 insertions(+), 227 deletions(-) diff --git a/sentry_sdk/integrations/aiohttp.py b/sentry_sdk/integrations/aiohttp.py index 50eaaed816..a2f9ace3d4 100644 --- a/sentry_sdk/integrations/aiohttp.py +++ b/sentry_sdk/integrations/aiohttp.py @@ -18,7 +18,7 @@ request_body_within_bounds, ) from sentry_sdk.integrations.logging import ignore_logger_for_events -from sentry_sdk.scope import Scope, should_send_default_pii +from sentry_sdk.scope import Scope from sentry_sdk.sessions import track_session from sentry_sdk.traces import ( BAGGAGE_HEADER_NAME, @@ -42,7 +42,6 @@ capture_internal_exceptions, ensure_integration_enabled, event_from_exception, - has_data_collection_enabled, logger, parse_url, parse_version, @@ -146,52 +145,28 @@ async def sentry_app_handle( url_attributes = {} client_address_attributes = {} - if has_data_collection_enabled(client.options): - url_attributes["url.full"] = "%s://%s%s" % ( - request.scheme, - request.host, - request.path, - ) - url_attributes["url.path"] = request.path - - if request.query_string: - filtered_query_string = ( - _apply_data_collection_filtering_to_query_string( - query_string=request.query_string, - behaviour=client.options["data_collection"][ - "url_query_params" - ], - ) + url_attributes["url.full"] = "%s://%s%s" % ( + request.scheme, + request.host, + request.path, + ) + url_attributes["url.path"] = request.path + + if request.query_string: + filtered_query_string = ( + _apply_data_collection_filtering_to_query_string( + query_string=request.query_string, + behaviour=client.options["data_collection"][ + "url_query_params" + ], ) - if filtered_query_string: - url_attributes["url.query"] = filtered_query_string - url_attributes["url.full"] += ( - "?" + filtered_query_string - ) - - if request.remote: - if client.options["data_collection"]["user_info"]: - client_address_attributes["client.address"] = ( - request.remote - ) - scope.set_attribute( - SPANDATA.USER_IP_ADDRESS, request.remote - ) - - elif should_send_default_pii(): - url_full = "%s://%s%s" % ( - request.scheme, - request.host, - request.path, ) - if request.query_string: - url_full += "?" + request.query_string - url_attributes["url.query"] = request.query_string + if filtered_query_string: + url_attributes["url.query"] = filtered_query_string + url_attributes["url.full"] += "?" + filtered_query_string - url_attributes["url.full"] = url_full - url_attributes["url.path"] = request.path - - if request.remote: + if request.remote: + if client.options["data_collection"]["user_info"]: client_address_attributes["client.address"] = request.remote scope.set_attribute( SPANDATA.USER_IP_ADDRESS, request.remote @@ -347,43 +322,26 @@ async def on_request_start( "http.request.method": method, } if parsed_url is not None: - if has_data_collection_enabled(client.options): - url_full = parsed_url.url - attributes["url.path"] = params.url.path - - if parsed_url.query: - filtered_query = _apply_data_collection_filtering_to_query_string( - query_string=parsed_url.query, - behaviour=client.options["data_collection"]["url_query_params"], - ) - if filtered_query: - attributes["url.query"] = filtered_query - url_full += "?" + filtered_query - breadcrumb[SPANDATA.HTTP_QUERY] = filtered_query - - if parsed_url.fragment: - attributes["url.fragment"] = parsed_url.fragment - url_full += "#" + parsed_url.fragment - breadcrumb[SPANDATA.HTTP_FRAGMENT] = parsed_url.fragment - - attributes["url.full"] = url_full - breadcrumb["url"] = url_full - - elif should_send_default_pii(): - url_full = parsed_url.url - attributes["url.path"] = params.url.path - - if parsed_url.query: - url_full += "?" + parsed_url.query - attributes["url.query"] = parsed_url.query - breadcrumb[SPANDATA.HTTP_QUERY] = parsed_url.query - if parsed_url.fragment: - url_full += "#" + parsed_url.fragment - attributes["url.fragment"] = parsed_url.fragment - breadcrumb[SPANDATA.HTTP_FRAGMENT] = parsed_url.fragment - - attributes["url.full"] = url_full - breadcrumb["url"] = url_full + url_full = parsed_url.url + attributes["url.path"] = params.url.path + + if parsed_url.query: + filtered_query = _apply_data_collection_filtering_to_query_string( + query_string=parsed_url.query, + behaviour=client.options["data_collection"]["url_query_params"], + ) + if filtered_query: + attributes["url.query"] = filtered_query + url_full += "?" + filtered_query + breadcrumb[SPANDATA.HTTP_QUERY] = filtered_query + + if parsed_url.fragment: + attributes["url.fragment"] = parsed_url.fragment + url_full += "#" + parsed_url.fragment + breadcrumb[SPANDATA.HTTP_FRAGMENT] = parsed_url.fragment + + attributes["url.full"] = url_full + breadcrumb["url"] = url_full if sentry_sdk.get_current_span() is not None: span = sentry_sdk.start_span(name=span_name, attributes=attributes) @@ -480,6 +438,7 @@ async def on_request_end( with capture_internal_exceptions(): add_http_request_source(span) + span.end() trace_config = TraceConfig() @@ -511,44 +470,23 @@ def aiohttp_processor( request.path, ) - if has_data_collection_enabled(client_options): - if request.query_string: - filtered_query_string = ( - _apply_data_collection_filtering_to_query_string( - query_string=request.query_string, - behaviour=client_options["data_collection"][ - "url_query_params" - ], - ) + if request.query_string: + filtered_query_string = ( + _apply_data_collection_filtering_to_query_string( + query_string=request.query_string, + behaviour=client_options["data_collection"]["url_query_params"], ) - if filtered_query_string: - request_info["query_string"] = filtered_query_string - else: - request_info["query_string"] = request.query_string + ) + if filtered_query_string: + request_info["query_string"] = filtered_query_string request_info["method"] = request.method - - # REMOTE_ADDR was unconditionally set pre-data collection, so it - # continues to be set when data collection is not enabled. - if ( - not has_data_collection_enabled(client_options) - or client_options["data_collection"]["user_info"] - ): - request_info["env"] = {"REMOTE_ADDR": request.remote} request_info["headers"] = _filter_headers(dict(request.headers)) # Just attach raw data here if it is within bounds, if available. # Unfortunately there's no way to get structured data from aiohttp # without awaiting on some coroutine. - if has_data_collection_enabled(client_options): - if ( - "incoming_request" - in client_options["data_collection"]["http_bodies"] - ): - request_info["data"] = get_aiohttp_request_data(request) - else: - # We never gated this prior to data collection, so it should be attached - # when data collection is not enabled. + if "incoming_request" in client_options["data_collection"]["http_bodies"]: request_info["data"] = get_aiohttp_request_data(request) return event diff --git a/tests/integrations/aiohttp/test_aiohttp.py b/tests/integrations/aiohttp/test_aiohttp.py index 39be86896f..c2829f9b98 100644 --- a/tests/integrations/aiohttp/test_aiohttp.py +++ b/tests/integrations/aiohttp/test_aiohttp.py @@ -59,7 +59,6 @@ async def hello(request): request = event["request"] host = request["headers"]["Host"] - assert request["env"] == {"REMOTE_ADDR": "127.0.0.1"} assert request["method"] == "GET" assert request["query_string"] == "" assert request.get("data") is None @@ -99,7 +98,6 @@ async def hello(request): assert exception["type"] == "ZeroDivisionError" request = event["request"] - assert request["env"] == {"REMOTE_ADDR": "127.0.0.1"} assert request["method"] == "POST" assert request["data"] == BODY_NOT_READ_MESSAGE @@ -128,7 +126,6 @@ async def hello(request): assert exception["type"] == "ZeroDivisionError" request = event["request"] - assert request["env"] == {"REMOTE_ADDR": "127.0.0.1"} assert request["method"] == "POST" assert request["data"] == json.dumps(body) @@ -546,8 +543,6 @@ async def hello(request): "pii_options,url_expected,query_expected", [ ({}, False, False), - ({"send_default_pii": True}, True, True), - ({"send_default_pii": False}, False, False), ( { "data_collection": { @@ -638,8 +633,6 @@ async def handler(request): "pii_options,url_expected,query_expected", [ ({}, False, False), - ({"send_default_pii": True}, True, True), - ({"send_default_pii": False}, False, False), ( { "data_collection": { @@ -1479,44 +1472,18 @@ async def hello(request): @pytest.mark.parametrize( - "options,expected", + "data_collection,expected", [ pytest.param( { - "send_default_pii": True, - "data_collection": {}, - }, - { - "authorization": "[Filtered]", - "custom": "foobar", - "cookie": "[Filtered]", - }, - id="enabled_send_default_pii_redacts_auth_header_due_to_data_collection_default_settings", - ), - pytest.param( - { - "send_default_pii": False, - "data_collection": {}, - }, - { - "authorization": "[Filtered]", - "custom": "foobar", - "cookie": "[Filtered]", - }, - id="disabled_send_default_pii_redacts_auth_header_due_to_data_collection_default_settings", - ), - pytest.param( - { - "send_default_pii": False, - "data_collection": {"http_headers": {"request": {"mode": "off"}}}, + "http_headers": {"request": {"mode": "off"}}, }, None, id="data_collection_off_does_not_add_headers", ), pytest.param( { - "send_default_pii": False, - "data_collection": {"http_headers": {"request": {"mode": "allowlist"}}}, + "http_headers": {"request": {"mode": "allowlist"}}, }, { "authorization": "[Filtered]", @@ -1527,12 +1494,9 @@ async def hello(request): ), pytest.param( { - "send_default_pii": False, - "data_collection": { - "http_headers": { - "request": {"mode": "allowlist", "terms": ["Authorization"]} - } - }, + "http_headers": { + "request": {"mode": "allowlist", "terms": ["Authorization"]} + } }, { "authorization": "[Filtered]", @@ -1542,14 +1506,7 @@ async def hello(request): id="data_collection_allow_list_redacts_sensitive_terms_even_when_provided_by_user", ), pytest.param( - { - "send_default_pii": False, - "data_collection": { - "http_headers": { - "request": {"mode": "allowlist", "terms": ["custom"]} - } - }, - }, + {"http_headers": {"request": {"mode": "allowlist", "terms": ["custom"]}}}, { "authorization": "[Filtered]", "custom": "foobar", @@ -1558,14 +1515,7 @@ async def hello(request): id="data_collection_allow_list_does_not_redact_provided_term", ), pytest.param( - { - "send_default_pii": False, - "data_collection": { - "http_headers": { - "request": {"mode": "denylist", "terms": ["custom"]} - } - }, - }, + {"http_headers": {"request": {"mode": "denylist", "terms": ["custom"]}}}, { "authorization": "[Filtered]", "custom": "[Filtered]", @@ -1574,14 +1524,7 @@ async def hello(request): id="data_collection_deny_list_redacts_sensitive_terms_when_provided_by_user", ), pytest.param( - { - "send_default_pii": False, - "data_collection": { - "http_headers": { - "request": {"mode": "allowlist", "terms": ["cookie"]} - } - }, - }, + {"http_headers": {"request": {"mode": "allowlist", "terms": ["cookie"]}}}, { "authorization": "[Filtered]", "custom": "[Filtered]", @@ -1593,13 +1536,12 @@ async def hello(request): ) @pytest.mark.asyncio async def test_sensitive_header_passthrough_with_pii( - sentry_init, aiohttp_client, capture_items, options, expected, request + sentry_init, aiohttp_client, capture_items, data_collection, expected, request ): sentry_init( integrations=[AioHttpIntegration()], traces_sample_rate=1.0, - send_default_pii=options["send_default_pii"], - data_collection=options["data_collection"], + data_collection=data_collection, ) async def hello(request): @@ -1642,42 +1584,6 @@ async def hello(request): ) -@pytest.mark.asyncio -async def test_sensitive_header_passthrough_with_pii_without_data_collection( - sentry_init, aiohttp_client, capture_items -): - sentry_init( - integrations=[AioHttpIntegration()], - traces_sample_rate=1.0, - send_default_pii=True, - ) - - async def hello(request): - return web.Response(text="hello") - - app = web.Application() - app.router.add_get("/", hello) - - items = capture_items("span") - - client = await aiohttp_client(app) - await client.get("/", headers={"Authorization": "Bearer secret-token"}) - - sentry_sdk.flush() - - (server_span,) = [item.payload for item in items] - - # With send_default_pii=True, _filter_headers is a no-op and the original - # value reaches the span attribute. - assert ( - server_span["attributes"]["http.request.header.authorization"] - == "Bearer secret-token" - ) - # client.address and user.ip_address is captured under send_default_pii=True. - assert server_span["attributes"]["client.address"] == "127.0.0.1" - assert server_span["attributes"]["user.ip_address"] == "127.0.0.1" - - @pytest.mark.asyncio @pytest.mark.parametrize("send_pii", [True, False]) async def test_url_query_attribute( diff --git a/tests/integrations/utils.py b/tests/integrations/utils.py index 2f0cbbaff7..a98461b7df 100644 --- a/tests/integrations/utils.py +++ b/tests/integrations/utils.py @@ -46,8 +46,6 @@ # ``send_default_pii`` cases still expect it to be collected. DATA_COLLECTION_REMOTE_ADDR_CASES = [ pytest.param({}, True, id="defaults"), - pytest.param({"send_default_pii": True}, True, id="send_default_pii_true"), - pytest.param({"send_default_pii": False}, True, id="send_default_pii_false"), pytest.param({"data_collection": {}}, True, id="data_collection_default"), pytest.param( {"data_collection": {"user_info": True}}, @@ -59,14 +57,6 @@ False, id="data_collection_user_info_false", ), - pytest.param( - { - "send_default_pii": True, - "data_collection": {"user_info": False}, - }, - False, - id="data_collection_wins_over_send_default_pii", - ), ] # Shared parametrization test matrix exercising the interaction between the From 4e2d6f8f5e5a1d4e09c4e25c4575d4fb96d0f9b8 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Wed, 23 Sep 2026 11:25:21 +0200 Subject: [PATCH 2/6] . --- sentry_sdk/integrations/aiohttp.py | 3 +++ tests/integrations/aiohttp/test_aiohttp.py | 19 ------------------- tests/integrations/utils.py | 7 ++----- 3 files changed, 5 insertions(+), 24 deletions(-) diff --git a/sentry_sdk/integrations/aiohttp.py b/sentry_sdk/integrations/aiohttp.py index a2f9ace3d4..5c05a5b08b 100644 --- a/sentry_sdk/integrations/aiohttp.py +++ b/sentry_sdk/integrations/aiohttp.py @@ -483,6 +483,9 @@ def aiohttp_processor( request_info["method"] = request.method request_info["headers"] = _filter_headers(dict(request.headers)) + if client_options["data_collection"]["user_info"]: + request_info["env"] = {"REMOTE_ADDR": request.remote} + # Just attach raw data here if it is within bounds, if available. # Unfortunately there's no way to get structured data from aiohttp # without awaiting on some coroutine. diff --git a/tests/integrations/aiohttp/test_aiohttp.py b/tests/integrations/aiohttp/test_aiohttp.py index c2829f9b98..f8af7e0b4e 100644 --- a/tests/integrations/aiohttp/test_aiohttp.py +++ b/tests/integrations/aiohttp/test_aiohttp.py @@ -60,7 +60,6 @@ async def hello(request): host = request["headers"]["Host"] assert request["method"] == "GET" - assert request["query_string"] == "" assert request.get("data") is None assert request["url"] == "http://{host}/".format(host=host) assert request["headers"] == { @@ -1937,16 +1936,6 @@ async def hello(request): _QUERY_PARAM_DATA_COLLECTION_CASES = [ - pytest.param( - {"send_default_pii": True}, - "toy=tennisball&color=red&auth=secret", - id="send_default_pii_true", - ), - pytest.param( - {"send_default_pii": False}, - None, - id="send_default_pii_false", - ), pytest.param( {}, None, @@ -1989,14 +1978,6 @@ async def hello(request): None, id="data_collection_off", ), - pytest.param( - { - "send_default_pii": True, - "data_collection": {"url_query_params": {"mode": "off"}}, - }, - None, - id="data_collection_wins_over_send_default_pii", - ), ] diff --git a/tests/integrations/utils.py b/tests/integrations/utils.py index a98461b7df..9b11e1d877 100644 --- a/tests/integrations/utils.py +++ b/tests/integrations/utils.py @@ -39,11 +39,8 @@ ), ] -# Shared parametrization test matrix for ``REMOTE_ADDR`` on events in -# integrations that set it unconditionally pre-data collection (tornado, sanic, -# aiohttp). Each case is ``(init_kwargs, expect_remote_addr)``: the address is -# only gated once ``data_collection`` is enabled, so the legacy -# ``send_default_pii`` cases still expect it to be collected. +# Shared parametrization test matrix for ``REMOTE_ADDR`` on events. +# Each case is ``(init_kwargs, expect_remote_addr)``. DATA_COLLECTION_REMOTE_ADDR_CASES = [ pytest.param({}, True, id="defaults"), pytest.param({"data_collection": {}}, True, id="data_collection_default"), From 7c777522c17153fd19fe4408ca833fbbdf60f9fa Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Wed, 23 Sep 2026 11:39:28 +0200 Subject: [PATCH 3/6] . --- tests/integrations/aiohttp/test_aiohttp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integrations/aiohttp/test_aiohttp.py b/tests/integrations/aiohttp/test_aiohttp.py index f8af7e0b4e..b00f933e83 100644 --- a/tests/integrations/aiohttp/test_aiohttp.py +++ b/tests/integrations/aiohttp/test_aiohttp.py @@ -59,6 +59,7 @@ async def hello(request): request = event["request"] host = request["headers"]["Host"] + assert request["env"] == {"REMOTE_ADDR": "127.0.0.1"} assert request["method"] == "GET" assert request.get("data") is None assert request["url"] == "http://{host}/".format(host=host) From e8cd793b80f04d60dc5e379094c20e129c677c2c Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Wed, 23 Sep 2026 12:03:06 +0200 Subject: [PATCH 4/6] . --- tests/integrations/aiohttp/test_aiohttp.py | 55 +++++++++++++++++----- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/tests/integrations/aiohttp/test_aiohttp.py b/tests/integrations/aiohttp/test_aiohttp.py index b00f933e83..68d50d9df9 100644 --- a/tests/integrations/aiohttp/test_aiohttp.py +++ b/tests/integrations/aiohttp/test_aiohttp.py @@ -33,7 +33,7 @@ @pytest.mark.asyncio async def test_basic(sentry_init, aiohttp_client, capture_events): - sentry_init(integrations=[AioHttpIntegration()]) + sentry_init(integrations=[AioHttpIntegration()], data_collection={}) async def hello(request): 1 / 0 @@ -77,7 +77,7 @@ async def hello(request): async def test_post_body_not_read(sentry_init, aiohttp_client, capture_events): from sentry_sdk.integrations.aiohttp import BODY_NOT_READ_MESSAGE - sentry_init(integrations=[AioHttpIntegration()]) + sentry_init(integrations=[AioHttpIntegration()], data_collection={}) body = {"some": "value"} @@ -98,13 +98,14 @@ async def hello(request): assert exception["type"] == "ZeroDivisionError" request = event["request"] + assert request["env"] == {"REMOTE_ADDR": "127.0.0.1"} assert request["method"] == "POST" assert request["data"] == BODY_NOT_READ_MESSAGE @pytest.mark.asyncio async def test_post_body_read(sentry_init, aiohttp_client, capture_events): - sentry_init(integrations=[AioHttpIntegration()]) + sentry_init(integrations=[AioHttpIntegration()], data_collection={}) body = {"some": "value"} @@ -126,6 +127,7 @@ async def hello(request): assert exception["type"] == "ZeroDivisionError" request = event["request"] + assert request["env"] == {"REMOTE_ADDR": "127.0.0.1"} assert request["method"] == "POST" assert request["data"] == json.dumps(body) @@ -233,7 +235,7 @@ async def hello(request): @pytest.mark.asyncio async def test_403_not_captured(sentry_init, aiohttp_client, capture_events): - sentry_init(integrations=[AioHttpIntegration()]) + sentry_init(integrations=[AioHttpIntegration()], data_collection={}) async def hello(request): raise web.HTTPForbidden() @@ -254,7 +256,7 @@ async def hello(request): async def test_cancelled_error_not_captured( sentry_init, aiohttp_client, capture_events ): - sentry_init(integrations=[AioHttpIntegration()]) + sentry_init(integrations=[AioHttpIntegration()], data_collection={}) async def hello(request): raise asyncio.CancelledError() @@ -275,8 +277,7 @@ async def hello(request): @pytest.mark.asyncio async def test_half_initialized(sentry_init, aiohttp_client, capture_events): - sentry_init(integrations=[AioHttpIntegration()]) - sentry_init() + sentry_init(integrations=[AioHttpIntegration()], data_collection={}) async def hello(request): return web.Response(text="hello") @@ -299,6 +300,7 @@ async def test_tracing_unparseable_url(sentry_init, aiohttp_client, capture_item sentry_init( integrations=[AioHttpIntegration()], traces_sample_rate=1.0, + data_collection={}, ) async def hello(request): @@ -338,6 +340,7 @@ async def test_traces_sampler_gets_request_object_in_sampling_context( sentry_init( integrations=[AioHttpIntegration()], traces_sampler=traces_sampler, + data_collection={}, ) async def kangaroo_handler(request): @@ -367,6 +370,7 @@ async def test_has_trace_if_performance_enabled( sentry_init( integrations=[AioHttpIntegration()], traces_sample_rate=1.0, + data_collection={}, ) async def hello(request): @@ -417,7 +421,7 @@ async def hello(request): async def test_has_trace_if_performance_disabled( sentry_init, aiohttp_client, capture_events ): - sentry_init(integrations=[AioHttpIntegration()]) + sentry_init(integrations=[AioHttpIntegration()], data_collection={}) async def hello(request): capture_message("It's a good day to try dividing by 0") @@ -453,6 +457,7 @@ async def test_trace_from_headers_if_performance_enabled( sentry_init( integrations=[AioHttpIntegration()], traces_sample_rate=1.0, + data_collection={}, ) async def hello(request): @@ -506,7 +511,7 @@ async def hello(request): async def test_trace_from_headers_if_performance_disabled( sentry_init, aiohttp_client, capture_events ): - sentry_init(integrations=[AioHttpIntegration()]) + sentry_init(integrations=[AioHttpIntegration()], data_collection={}) async def hello(request): capture_message("It's a good day to try dividing by 0") @@ -716,6 +721,7 @@ async def test_outgoing_trace_headers_adds_missing_unsigned_propagation_headers( sentry_init( integrations=[AioHttpIntegration()], traces_sample_rate=1.0, + data_collection={}, ) async def handler(request): @@ -758,6 +764,7 @@ async def test_outgoing_trace_headers_appends_baggage_but_preserves_sentry_trace integrations=[AioHttpIntegration()], traces_sample_rate=1.0, release="d08ebdb9309e1b004c6f52202de58a09c2268e42", + data_collection={}, ) async def handler(request): @@ -791,6 +798,7 @@ async def test_outgoing_trace_headers_preserves_signed_propagation_headers( sentry_init( integrations=[AioHttpIntegration()], traces_sample_rate=1.0, + data_collection={}, ) async def handler(request): @@ -830,6 +838,7 @@ async def test_outgoing_trace_headers_preserves_query_signed_baggage( sentry_init( integrations=[AioHttpIntegration()], traces_sample_rate=1.0, + data_collection={}, ) async def handler(request): @@ -870,6 +879,7 @@ async def test_request_source_disabled( traces_sample_rate=1.0, enable_http_request_source=False, http_request_source_threshold_ms=0, + data_collection={}, ) # server for making span request @@ -920,6 +930,7 @@ async def test_request_source_enabled( integrations=[AioHttpIntegration()], traces_sample_rate=1.0, http_request_source_threshold_ms=0, + data_collection={}, **extra_options, ) @@ -963,6 +974,7 @@ async def test_request_source( traces_sample_rate=1.0, enable_http_request_source=True, http_request_source_threshold_ms=0, + data_collection={}, ) # server for making span request @@ -1023,6 +1035,7 @@ async def test_request_source_with_module_in_search_path( traces_sample_rate=1.0, enable_http_request_source=True, http_request_source_threshold_ms=0, + data_collection={}, ) # server for making span request @@ -1077,6 +1090,7 @@ async def test_no_request_source_if_duration_too_short( traces_sample_rate=1.0, enable_http_request_source=True, http_request_source_threshold_ms=10**10, + data_collection={}, ) # server for making span request @@ -1122,6 +1136,7 @@ async def test_request_source_if_duration_over_threshold( traces_sample_rate=1.0, enable_http_request_source=True, http_request_source_threshold_ms=0, + data_collection={}, ) # server for making span request @@ -1180,6 +1195,7 @@ async def test_span_origin( sentry_init( integrations=[AioHttpIntegration()], traces_sample_rate=1.0, + data_collection={}, ) # server for making span request @@ -1248,7 +1264,9 @@ async def test_failed_request_status_codes( exception_to_raise, should_capture, ): - sentry_init(integrations=[AioHttpIntegration(**integration_kwargs)]) + sentry_init( + integrations=[AioHttpIntegration(**integration_kwargs)], data_collection={} + ) events = capture_events() async def handle(_): @@ -1282,7 +1300,10 @@ async def test_failed_request_status_codes_with_returned_status( """ Returning a web.Response with a failed_request_status_code should not be reported to Sentry. """ - sentry_init(integrations=[AioHttpIntegration(failed_request_status_codes={500})]) + sentry_init( + integrations=[AioHttpIntegration(failed_request_status_codes={500})], + data_collection={}, + ) events = capture_events() async def handle(_): @@ -1306,7 +1327,10 @@ async def test_failed_request_status_codes_non_http_exception( If an exception, which is not an instance of HTTPException, is raised, it should be captured, even if failed_request_status_codes is empty. """ - sentry_init(integrations=[AioHttpIntegration(failed_request_status_codes=set())]) + sentry_init( + integrations=[AioHttpIntegration(failed_request_status_codes=set())], + data_collection={}, + ) events = capture_events() async def handle(_): @@ -1433,6 +1457,7 @@ async def test_sensitive_header_scrubbing(sentry_init, aiohttp_client, capture_i sentry_init( integrations=[AioHttpIntegration()], traces_sample_rate=1.0, + data_collection={}, ) async def hello(request): @@ -1649,6 +1674,7 @@ async def test_transaction_style( sentry_init( integrations=[AioHttpIntegration(transaction_style=transaction_style)], traces_sample_rate=1.0, + data_collection={}, ) async def hello(request): @@ -1690,6 +1716,7 @@ async def test_http_route( sentry_init( integrations=[AioHttpIntegration()], traces_sample_rate=1.0, + data_collection={}, ) async def hello(request): @@ -1713,6 +1740,7 @@ async def test_server_error(sentry_init, aiohttp_client, capture_items): sentry_init( integrations=[AioHttpIntegration()], traces_sample_rate=1.0, + data_collection={}, ) async def hello(request): @@ -1751,6 +1779,7 @@ async def test_http_exception(sentry_init, aiohttp_client, capture_items): sentry_init( integrations=[AioHttpIntegration()], traces_sample_rate=1.0, + data_collection={}, ) async def hello(request): @@ -1782,6 +1811,7 @@ async def test_http_exception_ok_status_not_overridden( sentry_init( integrations=[AioHttpIntegration()], traces_sample_rate=1.0, + data_collection={}, ) async def hello(request): @@ -1873,6 +1903,7 @@ async def test_outgoing_trace_headers( sentry_init( integrations=[AioHttpIntegration()], traces_sample_rate=1.0, + data_collection={}, ) async def handler(request): From 627b51d32f45eb976abc89ab067d7eb0c7286dab Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Wed, 23 Sep 2026 13:21:33 +0200 Subject: [PATCH 5/6] . --- tests/integrations/aiohttp/test_aiohttp.py | 66 +++------------------- tests/integrations/utils.py | 1 - 2 files changed, 9 insertions(+), 58 deletions(-) diff --git a/tests/integrations/aiohttp/test_aiohttp.py b/tests/integrations/aiohttp/test_aiohttp.py index 68d50d9df9..81bd87f9a2 100644 --- a/tests/integrations/aiohttp/test_aiohttp.py +++ b/tests/integrations/aiohttp/test_aiohttp.py @@ -1348,12 +1348,11 @@ async def handle(_): @pytest.mark.asyncio -@pytest.mark.parametrize("send_pii", [True, False]) -async def test_tracing(sentry_init, aiohttp_client, capture_items, send_pii): +async def test_tracing(sentry_init, aiohttp_client, capture_items): sentry_init( integrations=[AioHttpIntegration()], traces_sample_rate=1.0, - send_default_pii=send_pii, + data_collection={}, ) async def hello(request): @@ -1393,23 +1392,15 @@ async def hello(request): # Request attributes derived directly from the aiohttp request. assert server_span["attributes"]["http.request.method"] == "GET" - if send_pii: - assert "client.address" in server_span["attributes"] - assert "user.ip_address" in server_span["attributes"] + assert "client.address" in server_span["attributes"] + assert "user.ip_address" in server_span["attributes"] - url_full = server_span["attributes"]["url.full"] - assert url_full.startswith("http://127.0.0.1:") - assert url_full.endswith("/") + url_full = server_span["attributes"]["url.full"] + assert url_full.startswith("http://127.0.0.1:") + assert url_full.endswith("/") - url_path = server_span["attributes"]["url.path"] - assert url_path == "/" - else: - assert "url.full" not in server_span["attributes"] - assert "url.path" not in server_span["attributes"] - assert "url.query" not in server_span["attributes"] - - assert "client.address" not in server_span["attributes"] - assert "user.ip_address" not in server_span["attributes"] + url_path = server_span["attributes"]["url.path"] + assert url_path == "/" # aiohttp's test client always sends a Host header; we assert it propagates # into the span attributes via _filter_headers. @@ -1609,40 +1600,6 @@ async def hello(request): ) -@pytest.mark.asyncio -@pytest.mark.parametrize("send_pii", [True, False]) -async def test_url_query_attribute( - sentry_init, aiohttp_client, capture_items, send_pii -): - sentry_init( - integrations=[AioHttpIntegration()], - traces_sample_rate=1.0, - send_default_pii=send_pii, - ) - - async def hello(request): - return web.Response(text="hello") - - app = web.Application() - app.router.add_get("/", hello) - - items = capture_items("span") - - client = await aiohttp_client(app) - resp = await client.get("/?foo=bar&baz=qux") - assert resp.status == 200 - - sentry_sdk.flush() - - assert len(items) == 1 - (server_segment,) = [item.payload for item in items] - - if send_pii: - assert server_segment["attributes"]["url.query"] == "foo=bar&baz=qux" - else: - assert "url.query" not in server_segment["attributes"] - - @pytest.mark.asyncio @pytest.mark.parametrize( "url,transaction_style,expected_name,expected_source", @@ -1968,11 +1925,6 @@ async def hello(request): _QUERY_PARAM_DATA_COLLECTION_CASES = [ - pytest.param( - {}, - None, - id="defaults", - ), pytest.param( {"data_collection": {}}, "toy=tennisball&color=red&auth=%5BFiltered%5D", diff --git a/tests/integrations/utils.py b/tests/integrations/utils.py index 9b11e1d877..ab61d4955f 100644 --- a/tests/integrations/utils.py +++ b/tests/integrations/utils.py @@ -42,7 +42,6 @@ # Shared parametrization test matrix for ``REMOTE_ADDR`` on events. # Each case is ``(init_kwargs, expect_remote_addr)``. DATA_COLLECTION_REMOTE_ADDR_CASES = [ - pytest.param({}, True, id="defaults"), pytest.param({"data_collection": {}}, True, id="data_collection_default"), pytest.param( {"data_collection": {"user_info": True}}, From 697e3fe7e7a9e92c7115c9cd3b576a532cc55776 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Wed, 23 Sep 2026 13:40:27 +0200 Subject: [PATCH 6/6] . --- tests/integrations/aiohttp/test_aiohttp.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/integrations/aiohttp/test_aiohttp.py b/tests/integrations/aiohttp/test_aiohttp.py index 81bd87f9a2..e92992cb86 100644 --- a/tests/integrations/aiohttp/test_aiohttp.py +++ b/tests/integrations/aiohttp/test_aiohttp.py @@ -277,6 +277,8 @@ async def hello(request): @pytest.mark.asyncio async def test_half_initialized(sentry_init, aiohttp_client, capture_events): + # Note: the first sentry_init is intentional + sentry_init() sentry_init(integrations=[AioHttpIntegration()], data_collection={}) async def hello(request):