From 5bd073455455d278bb1d2c6cfe166755fb985b7f Mon Sep 17 00:00:00 2001 From: Pablo Deputter Date: Thu, 24 Sep 2026 13:34:02 +0200 Subject: [PATCH 1/7] ref(sanic): Drop `send_default_pii` support --- sentry_sdk/integrations/sanic.py | 74 +++++++++++--------------------- 1 file changed, 24 insertions(+), 50 deletions(-) diff --git a/sentry_sdk/integrations/sanic.py b/sentry_sdk/integrations/sanic.py index be536b2a4f..8b80eb7364 100644 --- a/sentry_sdk/integrations/sanic.py +++ b/sentry_sdk/integrations/sanic.py @@ -11,13 +11,11 @@ ) from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version from sentry_sdk.integrations._wsgi_common import RequestExtractor, _filter_headers -from sentry_sdk.scope import should_send_default_pii from sentry_sdk.traces import SegmentNameSource from sentry_sdk.utils import ( capture_internal_exceptions, ensure_integration_enabled, event_from_exception, - has_data_collection_enabled, parse_version, reraise, ) @@ -135,12 +133,8 @@ async def _context_enter(request: "Request") -> None: sentry_sdk.continue_trace(dict(request.headers)) scope.set_custom_sampling_context({"sanic_request": request}) - if request.remote_addr: - if has_data_collection_enabled(client.options): - if client.options["data_collection"]["user_info"]: - scope.set_attribute(SPANDATA.USER_IP_ADDRESS, request.remote_addr) - elif should_send_default_pii(): - scope.set_attribute(SPANDATA.USER_IP_ADDRESS, request.remote_addr) + if request.remote_addr and client.options["data_collection"]["user_info"]: + scope.set_attribute(SPANDATA.USER_IP_ADDRESS, request.remote_addr) span = sentry_sdk.start_span( # Unless the request results in a 404 error, the name and source @@ -258,35 +252,23 @@ def _get_request_attributes(request: "Request") -> "Dict[str, Any]": urlparts = urlsplit(request.url) client_options = sentry_sdk.get_client().options - if has_data_collection_enabled(client_options): - attributes["url.path"] = urlparts.path + attributes["url.path"] = urlparts.path - filtered_query = None - if urlparts.query: - filtered_query = _apply_data_collection_filtering_to_query_string( - query_string=urlparts.query, - behaviour=client_options["data_collection"]["url_query_params"], - ) - if filtered_query: - attributes[SPANDATA.HTTP_QUERY] = filtered_query - - attributes[SPANDATA.URL_FULL] = urlparts._replace( - query=filtered_query or "" - ).geturl() - - if request.remote_addr: - if client_options["data_collection"]["user_info"]: - attributes[SPANDATA.CLIENT_ADDRESS] = request.remote_addr - - elif should_send_default_pii(): - attributes[SPANDATA.URL_FULL] = request.url - attributes["url.path"] = urlparts.path + filtered_query = None + if urlparts.query: + filtered_query = _apply_data_collection_filtering_to_query_string( + query_string=urlparts.query, + behaviour=client_options["data_collection"]["url_query_params"], + ) + if filtered_query: + attributes[SPANDATA.HTTP_QUERY] = filtered_query - if urlparts.query: - attributes[SPANDATA.HTTP_QUERY] = urlparts.query + attributes[SPANDATA.URL_FULL] = urlparts._replace( + query=filtered_query or "" + ).geturl() - if request.remote_addr: - attributes[SPANDATA.CLIENT_ADDRESS] = request.remote_addr + if request.remote_addr and client_options["data_collection"]["user_info"]: + attributes[SPANDATA.CLIENT_ADDRESS] = request.remote_addr if urlparts.scheme: attributes[SPANDATA.NETWORK_PROTOCOL_NAME] = urlparts.scheme @@ -320,25 +302,17 @@ def sanic_processor(event: "Event", hint: "Optional[Hint]") -> "Optional[Event]" ) client_options = sentry_sdk.get_client().options - if has_data_collection_enabled(client_options): - if urlparts.query: - filtered_query = _apply_data_collection_filtering_to_query_string( - query_string=urlparts.query, - behaviour=client_options["data_collection"]["url_query_params"], - ) - if filtered_query: - request_info["query_string"] = filtered_query - else: - request_info["query_string"] = urlparts.query + if urlparts.query: + filtered_query = _apply_data_collection_filtering_to_query_string( + query_string=urlparts.query, + behaviour=client_options["data_collection"]["url_query_params"], + ) + if filtered_query: + request_info["query_string"] = filtered_query 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"] - ): + if client_options["data_collection"]["user_info"]: request_info["env"] = {"REMOTE_ADDR": request.remote_addr} request_info["headers"] = _filter_headers(dict(request.headers)) From a6bb2c32231ec6b56ef1e3dd546bc547effcf3fc Mon Sep 17 00:00:00 2001 From: Pablo Deputter Date: Thu, 24 Sep 2026 14:33:50 +0200 Subject: [PATCH 2/7] tests --- tests/integrations/sanic/test_sanic.py | 62 ++++---------------------- 1 file changed, 9 insertions(+), 53 deletions(-) diff --git a/tests/integrations/sanic/test_sanic.py b/tests/integrations/sanic/test_sanic.py index 6ca80edd4b..854fd794b4 100644 --- a/tests/integrations/sanic/test_sanic.py +++ b/tests/integrations/sanic/test_sanic.py @@ -104,7 +104,7 @@ def reusable_client(app): def test_request_data(sentry_init, app, capture_events): - sentry_init(integrations=[SanicIntegration()]) + sentry_init(integrations=[SanicIntegration()], data_collection={}) events = capture_events() c = get_client(app) @@ -368,7 +368,6 @@ def __init__( self.expected_source = expected_source -@pytest.mark.parametrize("send_pii", [True, False]) @pytest.mark.parametrize( "test_config", [ @@ -407,13 +406,12 @@ def test_transactions( sentry_init: "Any", app: "Any", capture_items: "Any", - send_pii: bool, ) -> None: # Init the SanicIntegration with the desired arguments sentry_init( integrations=[SanicIntegration()], traces_sample_rate=1.0, - send_default_pii=send_pii, + data_collection={}, ) items = capture_items("span") @@ -458,16 +456,10 @@ def test_transactions( "error" if test_config.expected_status >= 400 else "ok" ) - if send_pii: - assert attrs["url.full"].endswith(test_config.url) - assert attrs["url.path"] == test_config.url.split("?")[0] - if "?" in test_config.url: - assert attrs["http.query"] == test_config.url.split("?", 1)[1] - - else: - assert "url.full" not in attrs - assert "url.path" not in attrs - assert "http.query" not in attrs + assert attrs["url.full"].endswith(test_config.url) + assert attrs["url.path"] == test_config.url.split("?")[0] + if "?" in test_config.url: + assert attrs["http.query"] == test_config.url.split("?", 1)[1] def test_span_origin(sentry_init, app, capture_items): @@ -569,21 +561,6 @@ def test_client_address_span_attribute_data_collection( _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, - id="defaults", - ), pytest.param( {"data_collection": {}}, "toy=tennisball&color=red&auth=%5BFiltered%5D", @@ -621,14 +598,6 @@ def test_client_address_span_attribute_data_collection( 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", - ), ] @@ -660,19 +629,10 @@ def test_url_query_data_collection( and i.payload["is_segment"] ] - data_collection_enabled = "data_collection" in init_kwargs - url_attrs_expected = data_collection_enabled or init_kwargs.get( - "send_default_pii", False - ) - if expected_query is None: assert "http.query" not in server_span["attributes"] - if url_attrs_expected: - assert server_span["attributes"]["url.full"].endswith("/message") - assert server_span["attributes"]["url.path"].endswith("/message") - else: - assert "url.full" not in server_span["attributes"] - assert "url.path" not in server_span["attributes"] + assert server_span["attributes"]["url.full"].endswith("/message") + assert server_span["attributes"]["url.path"].endswith("/message") else: assert server_span["attributes"]["http.query"] == expected_query assert server_span["attributes"]["url.full"].endswith( @@ -700,11 +660,7 @@ def test_url_query_data_collection_event_processor( assert event["request"]["url"].endswith("/message") assert event["request"]["method"] == "GET" - if "data_collection" not in init_kwargs: - assert ( - event["request"]["query_string"] == "toy=tennisball&color=red&auth=secret" - ) - elif expected_query is None: + if expected_query is None: assert "query_string" not in event["request"] else: assert event["request"]["query_string"] == expected_query From e893c4174f6bd74236a58e6399e613bdf12529b9 Mon Sep 17 00:00:00 2001 From: Pablo Deputter Date: Thu, 24 Sep 2026 14:43:13 +0200 Subject: [PATCH 3/7] tests --- tests/integrations/sanic/test_sanic.py | 40 ++++++++++++++++++++------ 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/tests/integrations/sanic/test_sanic.py b/tests/integrations/sanic/test_sanic.py index 854fd794b4..4aa0e995b3 100644 --- a/tests/integrations/sanic/test_sanic.py +++ b/tests/integrations/sanic/test_sanic.py @@ -368,6 +368,17 @@ def __init__( self.expected_source = expected_source +@pytest.mark.parametrize( + "data_collection, expect_query", + [ + pytest.param({}, True, id="data_collection_default"), + pytest.param( + {"url_query_params": {"mode": "off"}}, + False, + id="data_collection_url_query_params_off", + ), + ], +) @pytest.mark.parametrize( "test_config", [ @@ -406,12 +417,14 @@ def test_transactions( sentry_init: "Any", app: "Any", capture_items: "Any", + data_collection: "Any", + expect_query: bool, ) -> None: # Init the SanicIntegration with the desired arguments sentry_init( integrations=[SanicIntegration()], traces_sample_rate=1.0, - data_collection={}, + data_collection=data_collection, ) items = capture_items("span") @@ -456,10 +469,16 @@ def test_transactions( "error" if test_config.expected_status >= 400 else "ok" ) - assert attrs["url.full"].endswith(test_config.url) + expected_url = ( + test_config.url if expect_query else test_config.url.split("?", 1)[0] + ) + assert attrs["url.full"].endswith(expected_url) assert attrs["url.path"] == test_config.url.split("?")[0] if "?" in test_config.url: - assert attrs["http.query"] == test_config.url.split("?", 1)[1] + if expect_query: + assert attrs["http.query"] == test_config.url.split("?", 1)[1] + else: + assert "http.query" not in attrs def test_span_origin(sentry_init, app, capture_items): @@ -561,6 +580,16 @@ def test_client_address_span_attribute_data_collection( _QUERY_PARAM_DATA_COLLECTION_CASES = [ + pytest.param( + {"data_collection": {"url_query_params": {"mode": "denylist", "terms": []}}}, + "toy=tennisball&color=red&auth=%5BFiltered%5D", + id="data_collection_denylist_empty_terms", + ), + pytest.param( + {"data_collection": {"url_query_params": {"mode": "off"}}}, + None, + id="data_collection_off", + ), pytest.param( {"data_collection": {}}, "toy=tennisball&color=red&auth=%5BFiltered%5D", @@ -593,11 +622,6 @@ def test_client_address_span_attribute_data_collection( "toy=%5BFiltered%5D&color=%5BFiltered%5D&auth=%5BFiltered%5D", id="data_collection_allowlist_sensitive_term", ), - pytest.param( - {"data_collection": {"url_query_params": {"mode": "off"}}}, - None, - id="data_collection_off", - ), ] From 97dd890edd98d0dbba2c275de6a07d50cb5cc170 Mon Sep 17 00:00:00 2001 From: Pablo Deputter Date: Thu, 24 Sep 2026 17:26:01 +0200 Subject: [PATCH 4/7] remove outer test param --- tests/integrations/sanic/test_sanic.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/integrations/sanic/test_sanic.py b/tests/integrations/sanic/test_sanic.py index 4aa0e995b3..aa8116ae0e 100644 --- a/tests/integrations/sanic/test_sanic.py +++ b/tests/integrations/sanic/test_sanic.py @@ -580,11 +580,6 @@ def test_client_address_span_attribute_data_collection( _QUERY_PARAM_DATA_COLLECTION_CASES = [ - pytest.param( - {"data_collection": {"url_query_params": {"mode": "denylist", "terms": []}}}, - "toy=tennisball&color=red&auth=%5BFiltered%5D", - id="data_collection_denylist_empty_terms", - ), pytest.param( {"data_collection": {"url_query_params": {"mode": "off"}}}, None, From e684644f4f4a6a2c5d759d252cecd6e39e16ed05 Mon Sep 17 00:00:00 2001 From: Pablo Deputter Date: Fri, 25 Sep 2026 10:13:00 +0200 Subject: [PATCH 5/7] ref(tests): Refactor test cases --- tests/integrations/django/asgi/test_asgi.py | 6 ++- .../django/test_data_scrubbing.py | 18 +++++-- tests/integrations/flask/test_flask.py | 18 +++++-- tests/integrations/huey/test_huey.py | 4 +- tests/integrations/litestar/test_litestar.py | 6 ++- tests/integrations/pyramid/test_pyramid.py | 10 ++-- tests/integrations/rq/test_rq.py | 4 +- tests/integrations/sanic/test_sanic.py | 52 +++++++------------ tests/integrations/starlite/test_starlite.py | 6 ++- tests/integrations/tornado/test_tornado.py | 18 ++++--- tests/integrations/utils.py | 41 +++++++++++---- tests/integrations/wsgi/test_wsgi.py | 10 ++-- 12 files changed, 118 insertions(+), 75 deletions(-) diff --git a/tests/integrations/django/asgi/test_asgi.py b/tests/integrations/django/asgi/test_asgi.py index e5b6775c99..6b4f8a436a 100644 --- a/tests/integrations/django/asgi/test_asgi.py +++ b/tests/integrations/django/asgi/test_asgi.py @@ -16,7 +16,7 @@ from sentry_sdk.integrations.django.asgi import _asgi_middleware_mixin_factory from tests.integrations.django.myapp.asgi import channels_application from tests.integrations.django.utils import pytest_mark_django_db_decorator -from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES +from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY try: from django.urls import reverse @@ -941,7 +941,9 @@ async def test_async_middleware_process_exception_is_awaited( @pytest.mark.skipif( django.VERSION < (3, 0), reason="Django ASGI support shipped in 3.0" ) -@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) @pytest_mark_django_db_decorator() async def test_user_identity_error_event_data_collection( sentry_init, capture_events, application, init_kwargs, expect_user diff --git a/tests/integrations/django/test_data_scrubbing.py b/tests/integrations/django/test_data_scrubbing.py index 6d452ea8b2..9fa4919637 100644 --- a/tests/integrations/django/test_data_scrubbing.py +++ b/tests/integrations/django/test_data_scrubbing.py @@ -7,7 +7,7 @@ from tests.conftest import unpack_werkzeug_response, werkzeug_set_cookie from tests.integrations.django.myapp.wsgi import application from tests.integrations.django.utils import pytest_mark_django_db_decorator -from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES +from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY try: from django.urls import reverse @@ -370,7 +370,9 @@ def test_empty_query_string_is_dropped_with_data_collection( @pytest.mark.forked @pytest_mark_django_db_decorator() -@pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) def test_user_info_span_attributes_data_collection( sentry_init, client, capture_items, init_kwargs, expect_ip ): @@ -401,7 +403,9 @@ def test_user_info_span_attributes_data_collection( @pytest.mark.forked @pytest_mark_django_db_decorator() -@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) def test_user_identity_span_attributes_data_collection( sentry_init, client, capture_items, init_kwargs, expect_user ): @@ -432,7 +436,9 @@ def test_user_identity_span_attributes_data_collection( @pytest.mark.forked @pytest_mark_django_db_decorator() -@pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) def test_user_info_error_event_data_collection( sentry_init, client, capture_events, init_kwargs, expect_ip ): @@ -453,7 +459,9 @@ def test_user_info_error_event_data_collection( @pytest.mark.forked @pytest_mark_django_db_decorator() -@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) def test_user_identity_error_event_data_collection( sentry_init, client, capture_events, init_kwargs, expect_user ): diff --git a/tests/integrations/flask/test_flask.py b/tests/integrations/flask/test_flask.py index 53898543e5..400a42dc33 100644 --- a/tests/integrations/flask/test_flask.py +++ b/tests/integrations/flask/test_flask.py @@ -32,7 +32,7 @@ from sentry_sdk.consts import SPANDATA from sentry_sdk.integrations.logging import LoggingIntegration from sentry_sdk.serializer import MAX_DATABAG_BREADTH -from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES +from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY # Query string used across the query-param filtering tests below. ``auth`` is a # built-in sensitive term, so it is redacted by the default denylist. @@ -1234,7 +1234,9 @@ def test_empty_query_string_is_dropped_with_data_collection( assert "query_string" not in event["request"] -@pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) def test_user_info_span_attributes_data_collection( sentry_init, app, capture_items, monkeypatch, init_kwargs, expect_ip ): @@ -1265,7 +1267,9 @@ def test_user_info_span_attributes_data_collection( assert "client.address" not in segment["attributes"] -@pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) def test_user_info_error_event_data_collection( sentry_init, app, capture_events, monkeypatch, init_kwargs, expect_ip ): @@ -1316,7 +1320,9 @@ def crash(): assert "ip_address" not in event.get("user", {}) -@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) def test_flask_login_user_identity_error_event_data_collection( sentry_init, app, capture_events, init_kwargs, expect_user ): @@ -1364,7 +1370,9 @@ def crash(): assert "username" not in user -@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) def test_flask_login_user_identity_span_attributes_data_collection( sentry_init, app, capture_items, init_kwargs, expect_user ): diff --git a/tests/integrations/huey/test_huey.py b/tests/integrations/huey/test_huey.py index d528307033..5c37081cc4 100644 --- a/tests/integrations/huey/test_huey.py +++ b/tests/integrations/huey/test_huey.py @@ -10,7 +10,7 @@ from sentry_sdk.integrations.huey import HueyIntegration from sentry_sdk.traces import SegmentNameSource, SpanStatus from sentry_sdk.utils import parse_version -from tests.integrations.utils import DATA_COLLECTION_QUEUES_CASES +from tests.integrations.utils import DATA_COLLECTION_QUEUES_CASES_LEGACY HUEY_VERSION = parse_version(HUEY_VERSION) @@ -205,7 +205,7 @@ def maybe_locked_task(): @pytest.mark.parametrize( "init_kwargs,expected_args,expected_kwargs", - DATA_COLLECTION_QUEUES_CASES, + DATA_COLLECTION_QUEUES_CASES_LEGACY, ) def test_task_args_kwargs_data_collection( capture_items, diff --git a/tests/integrations/litestar/test_litestar.py b/tests/integrations/litestar/test_litestar.py index 363b83fdab..8e4b7d26c6 100644 --- a/tests/integrations/litestar/test_litestar.py +++ b/tests/integrations/litestar/test_litestar.py @@ -19,7 +19,7 @@ from sentry_sdk.utils import SENSITIVE_DATA_SUBSTITUTE from tests.conftest import ApproxDict from tests.integrations.conftest import parametrize_test_configurable_status_codes -from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES +from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY def litestar_app_factory(middleware=None, debug=True, exception_handlers=None): @@ -448,7 +448,9 @@ def test_span_origin( assert span["attributes"]["sentry.origin"] == "auto.http.litestar" -@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) def test_litestar_scope_user_on_exception_event( sentry_init, capture_exceptions, diff --git a/tests/integrations/pyramid/test_pyramid.py b/tests/integrations/pyramid/test_pyramid.py index 57548b4620..6f68708b44 100644 --- a/tests/integrations/pyramid/test_pyramid.py +++ b/tests/integrations/pyramid/test_pyramid.py @@ -15,7 +15,7 @@ from sentry_sdk.serializer import MAX_DATABAG_BREADTH from sentry_sdk.traces import SpanStatus from tests.conftest import unpack_werkzeug_response -from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES +from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY def hi(request): @@ -536,7 +536,9 @@ def test_span_origin( assert segment["attributes"]["sentry.origin"] == "auto.http.pyramid" -@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) def test_span_sets_user_id_on_segment( sentry_init, pyramid_config, @@ -575,7 +577,9 @@ def authenticated_userid(self, request): assert "user.id" not in segment["attributes"] -@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) def test_user_id_error_event_data_collection( sentry_init, pyramid_config, diff --git a/tests/integrations/rq/test_rq.py b/tests/integrations/rq/test_rq.py index 68a3afae3b..dc566a3e26 100644 --- a/tests/integrations/rq/test_rq.py +++ b/tests/integrations/rq/test_rq.py @@ -8,7 +8,7 @@ from sentry_sdk.consts import SPANDATA from sentry_sdk.integrations.rq import RqIntegration from sentry_sdk.utils import SENSITIVE_DATA_SUBSTITUTE, parse_version -from tests.integrations.utils import DATA_COLLECTION_QUEUES_CASES +from tests.integrations.utils import DATA_COLLECTION_QUEUES_CASES_LEGACY @pytest.fixture(autouse=True) @@ -91,7 +91,7 @@ def test_basic( @pytest.mark.parametrize( "init_kwargs,expected_args,expected_kwargs", - DATA_COLLECTION_QUEUES_CASES, + DATA_COLLECTION_QUEUES_CASES_LEGACY, ) def test_job_args_kwargs_data_collection( sentry_init, diff --git a/tests/integrations/sanic/test_sanic.py b/tests/integrations/sanic/test_sanic.py index aa8116ae0e..e25dce66d0 100644 --- a/tests/integrations/sanic/test_sanic.py +++ b/tests/integrations/sanic/test_sanic.py @@ -503,9 +503,9 @@ def test_span_origin(sentry_init, app, capture_items): assert segment["attributes"]["sentry.origin"] == "auto.http.sanic" -@pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize("data_collection, expect_ip", DATA_COLLECTION_USER_INFO_CASES) def test_user_ip_address_on_all_spans( - sentry_init, app, capture_items, init_kwargs, expect_ip + sentry_init, app, capture_items, data_collection, expect_ip ): app.config.FORWARDED_SECRET = "test" @@ -519,7 +519,7 @@ def child_span_handler(request): integrations=[SanicIntegration()], default_integrations=False, traces_sample_rate=1.0, - **init_kwargs, + data_collection=data_collection, ) items = capture_items("span") @@ -543,9 +543,9 @@ def child_span_handler(request): assert "user.ip_address" not in child_span["attributes"] -@pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize("data_collection, expect_ip", DATA_COLLECTION_USER_INFO_CASES) def test_client_address_span_attribute_data_collection( - sentry_init, app, capture_items, init_kwargs, expect_ip + sentry_init, app, capture_items, data_collection, expect_ip ): app.config.FORWARDED_SECRET = "test" @@ -553,7 +553,7 @@ def test_client_address_span_attribute_data_collection( integrations=[SanicIntegration()], default_integrations=False, traces_sample_rate=1.0, - **init_kwargs, + data_collection=data_collection, ) items = capture_items("span") @@ -581,39 +581,27 @@ def test_client_address_span_attribute_data_collection( _QUERY_PARAM_DATA_COLLECTION_CASES = [ pytest.param( - {"data_collection": {"url_query_params": {"mode": "off"}}}, + {"url_query_params": {"mode": "off"}}, None, id="data_collection_off", ), pytest.param( - {"data_collection": {}}, + {}, "toy=tennisball&color=red&auth=%5BFiltered%5D", id="data_collection_denylist_default", ), pytest.param( - { - "data_collection": { - "url_query_params": {"mode": "denylist", "terms": ["toy"]} - } - }, + {"url_query_params": {"mode": "denylist", "terms": ["toy"]}}, "toy=%5BFiltered%5D&color=red&auth=%5BFiltered%5D", id="data_collection_denylist_custom_terms", ), pytest.param( - { - "data_collection": { - "url_query_params": {"mode": "allowlist", "terms": ["toy"]} - } - }, + {"url_query_params": {"mode": "allowlist", "terms": ["toy"]}}, "toy=tennisball&color=%5BFiltered%5D&auth=%5BFiltered%5D", id="data_collection_allowlist", ), pytest.param( - { - "data_collection": { - "url_query_params": {"mode": "allowlist", "terms": ["auth"]} - } - }, + {"url_query_params": {"mode": "allowlist", "terms": ["auth"]}}, "toy=%5BFiltered%5D&color=%5BFiltered%5D&auth=%5BFiltered%5D", id="data_collection_allowlist_sensitive_term", ), @@ -621,15 +609,15 @@ def test_client_address_span_attribute_data_collection( @pytest.mark.parametrize( - "init_kwargs, expected_query", _QUERY_PARAM_DATA_COLLECTION_CASES + "data_collection, expected_query", _QUERY_PARAM_DATA_COLLECTION_CASES ) def test_url_query_data_collection( - sentry_init, app, capture_items, init_kwargs, expected_query + sentry_init, app, capture_items, data_collection, expected_query ): sentry_init( integrations=[SanicIntegration()], traces_sample_rate=1.0, - **init_kwargs, + data_collection=data_collection, ) items = capture_items("span") @@ -661,12 +649,12 @@ def test_url_query_data_collection( @pytest.mark.parametrize( - "init_kwargs, expected_query", _QUERY_PARAM_DATA_COLLECTION_CASES + "data_collection, expected_query", _QUERY_PARAM_DATA_COLLECTION_CASES ) def test_url_query_data_collection_event_processor( - sentry_init, app, capture_events, init_kwargs, expected_query + sentry_init, app, capture_events, data_collection, expected_query ): - sentry_init(integrations=[SanicIntegration()], **init_kwargs) + sentry_init(integrations=[SanicIntegration()], data_collection=data_collection) events = capture_events() @@ -766,12 +754,12 @@ def oversized_handler(request): @pytest.mark.parametrize( - "init_kwargs, expect_remote_addr", DATA_COLLECTION_REMOTE_ADDR_CASES + "data_collection, expect_remote_addr", DATA_COLLECTION_REMOTE_ADDR_CASES ) def test_remote_addr_data_collection( - sentry_init, app, capture_events, init_kwargs, expect_remote_addr + sentry_init, app, capture_events, data_collection, expect_remote_addr ): - sentry_init(integrations=[SanicIntegration()], **init_kwargs) + sentry_init(integrations=[SanicIntegration()], data_collection=data_collection) events = capture_events() c = get_client(app) diff --git a/tests/integrations/starlite/test_starlite.py b/tests/integrations/starlite/test_starlite.py index 6693b6a40f..a6d5be2018 100644 --- a/tests/integrations/starlite/test_starlite.py +++ b/tests/integrations/starlite/test_starlite.py @@ -13,7 +13,7 @@ from sentry_sdk import capture_message from sentry_sdk._types import SENSITIVE_DATA_SUBSTITUTE from sentry_sdk.integrations.starlite import StarliteIntegration -from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES +from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY def starlite_app_factory(middleware=None, debug=True, exception_handlers=None): @@ -398,7 +398,9 @@ def test_span_origin(sentry_init, capture_items): assert item.payload["attributes"]["sentry.origin"] == "auto.http.starlite" -@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) def test_starlite_scope_user_on_exception_event( sentry_init, capture_exceptions, capture_events, init_kwargs, expect_user ): diff --git a/tests/integrations/tornado/test_tornado.py b/tests/integrations/tornado/test_tornado.py index 0750d49747..bfe0f0873f 100644 --- a/tests/integrations/tornado/test_tornado.py +++ b/tests/integrations/tornado/test_tornado.py @@ -9,8 +9,8 @@ from sentry_sdk._types import SENSITIVE_DATA_SUBSTITUTE from sentry_sdk.integrations.tornado import TornadoIntegration from tests.integrations.utils import ( - DATA_COLLECTION_REMOTE_ADDR_CASES, - DATA_COLLECTION_USER_INFO_CASES, + DATA_COLLECTION_REMOTE_ADDR_CASES_LEGACY, + DATA_COLLECTION_USER_INFO_CASES_LEGACY, ) @@ -602,7 +602,9 @@ def get(self): assert "user" not in event -@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) def test_user_auth_data_collection( tornado_testcase, sentry_init, capture_events, init_kwargs, expect_user ): @@ -845,7 +847,9 @@ def test_span_origin( assert segment["attributes"]["sentry.origin"] == "auto.http.tornado" -@pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) def test_user_ip_address_on_all_spans( tornado_testcase, sentry_init, capture_items, init_kwargs, expect_ip ): @@ -872,7 +876,9 @@ def test_user_ip_address_on_all_spans( assert "user.ip_address" not in child_span["attributes"] -@pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) def test_client_address_span_attribute_data_collection( tornado_testcase, sentry_init, capture_items, init_kwargs, expect_ip ): @@ -902,7 +908,7 @@ def test_client_address_span_attribute_data_collection( @pytest.mark.parametrize( - "init_kwargs, expect_remote_addr", DATA_COLLECTION_REMOTE_ADDR_CASES + "init_kwargs, expect_remote_addr", DATA_COLLECTION_REMOTE_ADDR_CASES_LEGACY ) def test_remote_addr_data_collection( tornado_testcase, sentry_init, capture_events, init_kwargs, expect_remote_addr diff --git a/tests/integrations/utils.py b/tests/integrations/utils.py index 5f5999089f..4fd3dec490 100644 --- a/tests/integrations/utils.py +++ b/tests/integrations/utils.py @@ -1,32 +1,32 @@ import pytest # Shared parametrization test matrix for ``data_collection.user_info`` setting. -# Each case is ``(init_kwargs, expect_user_info)`` where the second element indicates +# Each case is ``(data_collection, expect_user_info)`` where the second element indicates # whether user info (IP address, user identity, etc.) is expected to be collected. DATA_COLLECTION_USER_INFO_CASES = [ pytest.param( - {"data_collection": {"user_info": True}}, + {"user_info": True}, True, id="data_collection_user_info_true", ), pytest.param( - {"data_collection": {"user_info": False}}, + {"user_info": False}, False, id="data_collection_user_info_false", ), ] # Shared parametrization test matrix for ``REMOTE_ADDR`` on events. -# Each case is ``(init_kwargs, expect_remote_addr)``. +# Each case is ``(data_collection, expect_remote_addr)``. DATA_COLLECTION_REMOTE_ADDR_CASES = [ - pytest.param({"data_collection": {}}, True, id="data_collection_default"), + pytest.param({}, True, id="data_collection_default"), pytest.param( - {"data_collection": {"user_info": True}}, + {"user_info": True}, True, id="data_collection_user_info_true", ), pytest.param( - {"data_collection": {"user_info": False}}, + {"user_info": False}, False, id="data_collection_user_info_false", ), @@ -34,25 +34,44 @@ # Shared parametrization test matrix for ``data_collection.queues`` setting. -# Each case is ``(init_kwargs, expected_args, expected_kwargs)`` where ``None`` for +# Each case is ``(data_collection, expected_args, expected_kwargs)`` where ``None`` for # the expected values means args/kwargs are not collected at all. DATA_COLLECTION_QUEUES_CASES = [ pytest.param( - {"data_collection": {}}, + {}, [1], {"b": 0}, id="data_collection_default", ), pytest.param( - {"data_collection": {"queues": True}}, + {"queues": True}, [1], {"b": 0}, id="data_collection_queues_on", ), pytest.param( - {"data_collection": {"queues": False}}, + {"queues": False}, None, None, id="data_collection_queues_off", ), ] + + +DATA_COLLECTION_USER_INFO_CASES_LEGACY = [ + pytest.param({"data_collection": case.values[0]}, case.values[1], id=case.id) + for case in DATA_COLLECTION_USER_INFO_CASES +] +DATA_COLLECTION_REMOTE_ADDR_CASES_LEGACY = [ + pytest.param({"data_collection": case.values[0]}, case.values[1], id=case.id) + for case in DATA_COLLECTION_REMOTE_ADDR_CASES +] +DATA_COLLECTION_QUEUES_CASES_LEGACY = [ + pytest.param( + {"data_collection": case.values[0]}, + case.values[1], + case.values[2], + id=case.id, + ) + for case in DATA_COLLECTION_QUEUES_CASES +] diff --git a/tests/integrations/wsgi/test_wsgi.py b/tests/integrations/wsgi/test_wsgi.py index 12fed06ff8..c71a78c44e 100644 --- a/tests/integrations/wsgi/test_wsgi.py +++ b/tests/integrations/wsgi/test_wsgi.py @@ -11,7 +11,7 @@ _ScopedResponse, get_request_url, ) -from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES +from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY @pytest.fixture @@ -1114,7 +1114,9 @@ def dogpark(environ, start_response): assert "user.ip_address" not in child_span["attributes"] -@pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) def test_user_info_span_attributes_data_collection( sentry_init, capture_items, init_kwargs, expect_ip ): @@ -1151,7 +1153,9 @@ def dogpark(environ, start_response): assert "client.address" not in server_span["attributes"] -@pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES_LEGACY +) def test_user_info_error_event_data_collection( sentry_init, crashing_app, capture_events, init_kwargs, expect_ip ): From 1d8733a5fb8e314142127efd8c75e6abf2f7e834 Mon Sep 17 00:00:00 2001 From: Pablo Deputter Date: Fri, 25 Sep 2026 11:13:12 +0200 Subject: [PATCH 6/7] aiohttp fix --- tests/integrations/aiohttp/test_aiohttp.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/integrations/aiohttp/test_aiohttp.py b/tests/integrations/aiohttp/test_aiohttp.py index e92992cb86..6fa520e590 100644 --- a/tests/integrations/aiohttp/test_aiohttp.py +++ b/tests/integrations/aiohttp/test_aiohttp.py @@ -1410,14 +1410,14 @@ async def hello(request): @pytest.mark.asyncio -@pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize("data_collection, expect_ip", DATA_COLLECTION_USER_INFO_CASES) async def test_user_address_with_data_collection( - sentry_init, aiohttp_client, capture_items, init_kwargs, expect_ip + sentry_init, aiohttp_client, capture_items, data_collection, expect_ip ): sentry_init( integrations=[AioHttpIntegration()], traces_sample_rate=1.0, - **init_kwargs, + data_collection=data_collection, ) async def hello(request): @@ -2090,12 +2090,12 @@ async def hello(request): @pytest.mark.asyncio @pytest.mark.parametrize( - "init_kwargs, expect_remote_addr", DATA_COLLECTION_REMOTE_ADDR_CASES + "data_collection, expect_remote_addr", DATA_COLLECTION_REMOTE_ADDR_CASES ) async def test_remote_addr_data_collection( - sentry_init, aiohttp_client, capture_events, init_kwargs, expect_remote_addr + sentry_init, aiohttp_client, capture_events, data_collection, expect_remote_addr ): - sentry_init(integrations=[AioHttpIntegration()], **init_kwargs) + sentry_init(integrations=[AioHttpIntegration()], data_collection=data_collection) async def hello(request): capture_message("hi") From 2d3ee8d98b5f7cf7c88b25b3eea8a7f3a9d84e28 Mon Sep 17 00:00:00 2001 From: Pablo Deputter Date: Fri, 25 Sep 2026 11:17:13 +0200 Subject: [PATCH 7/7] fix arq --- tests/integrations/arq/test_arq.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integrations/arq/test_arq.py b/tests/integrations/arq/test_arq.py index cdf1723390..8f15e48d0f 100644 --- a/tests/integrations/arq/test_arq.py +++ b/tests/integrations/arq/test_arq.py @@ -346,14 +346,14 @@ async def division(_, a, b=0): @pytest.mark.parametrize( - "init_kwargs,expected_args,expected_kwargs", + "data_collection,expected_args,expected_kwargs", DATA_COLLECTION_QUEUES_CASES, ) @pytest.mark.asyncio async def test_job_args_kwargs_data_collection( capture_items, init_arq, - init_kwargs, + data_collection, expected_args, expected_kwargs, ): @@ -364,7 +364,7 @@ async def division(_, a, b=1): pool, worker = init_arq( cls_functions=[division], - init_kwargs=init_kwargs, + init_kwargs={"data_collection": data_collection}, ) job = await pool.enqueue_job("division", 1, b=0)