diff --git a/tests/integrations/asgi/test_asgi.py b/tests/integrations/asgi/test_asgi.py index 9939b3f4f4..996c9e2eb7 100644 --- a/tests/integrations/asgi/test_asgi.py +++ b/tests/integrations/asgi/test_asgi.py @@ -11,6 +11,7 @@ ) from sentry_sdk.integrations.asgi import SentryAsgiMiddleware, _looks_like_asgi3 from sentry_sdk.traces import SegmentNameSource +from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES @pytest.fixture @@ -1029,36 +1030,17 @@ async def test_custom_transaction_name( @pytest.mark.asyncio -@pytest.mark.parametrize( - "init_kwargs, expect_ip", - [ - pytest.param( - {"data_collection": {}}, - True, - id="dc_default_user_info", - ), - pytest.param( - {"data_collection": {"user_info": True}}, - True, - id="dc_user_info_true", - ), - pytest.param( - {"data_collection": {"user_info": False}}, - False, - id="dc_user_info_false", - ), - ], -) +@pytest.mark.parametrize("data_collection, expect_ip", DATA_COLLECTION_USER_INFO_CASES) async def test_user_ip_address_on_all_spans( sentry_init, capture_items, - init_kwargs, + data_collection, expect_ip, asgi3_app_with_span, ): sentry_init( traces_sample_rate=1.0, - **init_kwargs, + data_collection=data_collection, ) app = SentryAsgiMiddleware(asgi3_app_with_span) diff --git a/tests/integrations/django/asgi/test_asgi.py b/tests/integrations/django/asgi/test_asgi.py index 50608d1a25..4c49694e1a 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_LEGACY +from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES try: from django.urls import reverse @@ -887,13 +887,13 @@ async def test_async_middleware_process_exception_is_awaited( django.VERSION < (3, 0), reason="Django ASGI support shipped in 3.0" ) @pytest.mark.parametrize( - "init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY + "data_collection, expect_user", DATA_COLLECTION_USER_INFO_CASES ) @pytest_mark_django_db_decorator() async def test_user_identity_error_event_data_collection( - sentry_init, capture_events, application, init_kwargs, expect_user + sentry_init, capture_events, application, data_collection, expect_user ): - sentry_init(integrations=[DjangoIntegration()], **init_kwargs) + sentry_init(integrations=[DjangoIntegration()], data_collection=data_collection) events = capture_events() comm = HttpCommunicator(application, "GET", "/mylogin-with-exception") diff --git a/tests/integrations/django/test_data_scrubbing.py b/tests/integrations/django/test_data_scrubbing.py index 088bc77306..52b16a1922 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_LEGACY +from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES try: from django.urls import reverse @@ -269,16 +269,14 @@ 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_LEGACY -) +@pytest.mark.parametrize("data_collection, expect_ip", DATA_COLLECTION_USER_INFO_CASES) def test_user_info_span_attributes_data_collection( - sentry_init, client, capture_items, init_kwargs, expect_ip + sentry_init, client, capture_items, data_collection, expect_ip ): sentry_init( integrations=[DjangoIntegration()], traces_sample_rate=1.0, - **init_kwargs, + data_collection=data_collection, ) items = capture_items("span") @@ -303,15 +301,15 @@ 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_LEGACY + "data_collection, expect_user", DATA_COLLECTION_USER_INFO_CASES ) def test_user_identity_span_attributes_data_collection( - sentry_init, client, capture_items, init_kwargs, expect_user + sentry_init, client, capture_items, data_collection, expect_user ): sentry_init( integrations=[DjangoIntegration()], traces_sample_rate=1.0, - **init_kwargs, + data_collection=data_collection, ) unpack_werkzeug_response(client.get(reverse("mylogin"))) @@ -335,13 +333,11 @@ 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_LEGACY -) +@pytest.mark.parametrize("data_collection, expect_ip", DATA_COLLECTION_USER_INFO_CASES) def test_user_info_error_event_data_collection( - sentry_init, client, capture_events, init_kwargs, expect_ip + sentry_init, client, capture_events, data_collection, expect_ip ): - sentry_init(integrations=[DjangoIntegration()], **init_kwargs) + sentry_init(integrations=[DjangoIntegration()], data_collection=data_collection) events = capture_events() client.get(reverse("view_exc"), environ_base={"REMOTE_ADDR": "127.0.0.1"}) @@ -359,12 +355,12 @@ 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_LEGACY + "data_collection, expect_user", DATA_COLLECTION_USER_INFO_CASES ) def test_user_identity_error_event_data_collection( - sentry_init, client, capture_events, init_kwargs, expect_user + sentry_init, client, capture_events, data_collection, expect_user ): - sentry_init(integrations=[DjangoIntegration()], **init_kwargs) + sentry_init(integrations=[DjangoIntegration()], data_collection=data_collection) events = capture_events() client.get(reverse("mylogin")) diff --git a/tests/integrations/flask/test_flask.py b/tests/integrations/flask/test_flask.py index ea7e01b6b3..667e4ad6eb 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_LEGACY +from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES # 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. @@ -1235,16 +1235,14 @@ 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_LEGACY -) +@pytest.mark.parametrize("data_collection, expect_ip", DATA_COLLECTION_USER_INFO_CASES) def test_user_info_span_attributes_data_collection( - sentry_init, app, capture_items, monkeypatch, init_kwargs, expect_ip + sentry_init, app, capture_items, monkeypatch, data_collection, expect_ip ): sentry_init( integrations=[flask_sentry.FlaskIntegration()], traces_sample_rate=1.0, - **init_kwargs, + data_collection=data_collection, ) # This test is about user IP collection, not flask_login. Disable # flask_login so the module-level login manager does not interfere. @@ -1268,13 +1266,13 @@ 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_LEGACY -) +@pytest.mark.parametrize("data_collection, expect_ip", DATA_COLLECTION_USER_INFO_CASES) def test_user_info_error_event_data_collection( - sentry_init, app, capture_events, monkeypatch, init_kwargs, expect_ip + sentry_init, app, capture_events, monkeypatch, data_collection, expect_ip ): - sentry_init(integrations=[flask_sentry.FlaskIntegration()], **init_kwargs) + sentry_init( + integrations=[flask_sentry.FlaskIntegration()], data_collection=data_collection + ) monkeypatch.setattr(flask_sentry, "flask_login", None) @app.route("/crash") @@ -1322,12 +1320,14 @@ def crash(): @pytest.mark.parametrize( - "init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY + "data_collection, expect_user", DATA_COLLECTION_USER_INFO_CASES ) def test_flask_login_user_identity_error_event_data_collection( - sentry_init, app, capture_events, init_kwargs, expect_user + sentry_init, app, capture_events, data_collection, expect_user ): - sentry_init(integrations=[flask_sentry.FlaskIntegration()], **init_kwargs) + sentry_init( + integrations=[flask_sentry.FlaskIntegration()], data_collection=data_collection + ) class User: is_authenticated = is_active = True @@ -1372,15 +1372,15 @@ def crash(): @pytest.mark.parametrize( - "init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY + "data_collection, expect_user", DATA_COLLECTION_USER_INFO_CASES ) def test_flask_login_user_identity_span_attributes_data_collection( - sentry_init, app, capture_items, init_kwargs, expect_user + sentry_init, app, capture_items, data_collection, expect_user ): sentry_init( integrations=[flask_sentry.FlaskIntegration()], traces_sample_rate=1.0, - **init_kwargs, + data_collection=data_collection, ) class User: diff --git a/tests/integrations/pyramid/test_pyramid.py b/tests/integrations/pyramid/test_pyramid.py index 1ec8aed657..88dd704af7 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_LEGACY +from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES def hi(request): @@ -65,7 +65,7 @@ def inner(): def test_view_exceptions( get_client, route, sentry_init, capture_events, capture_exceptions ): - sentry_init(integrations=[PyramidIntegration()]) + sentry_init(integrations=[PyramidIntegration()], data_collection={}) events = capture_events() exceptions = capture_exceptions() @@ -133,6 +133,7 @@ def test_segment_name_and_source( sentry_init( integrations=[PyramidIntegration()], traces_sample_rate=1.0, + data_collection={}, ) items = capture_items("event", "span") @@ -157,6 +158,7 @@ def test_http_route( sentry_init( integrations=[PyramidIntegration()], traces_sample_rate=1.0, + data_collection={}, ) items = capture_items("span") @@ -308,7 +310,7 @@ def test_bad_request_not_captured( ): import pyramid.httpexceptions as exc - sentry_init(integrations=[PyramidIntegration()]) + sentry_init(integrations=[PyramidIntegration()], data_collection={}) events = capture_events() @route("/") @@ -329,7 +331,7 @@ def errorhandler(exc, request): def test_errorhandler_ok( sentry_init, pyramid_config, capture_exceptions, route, get_client ): - sentry_init(integrations=[PyramidIntegration()]) + sentry_init(integrations=[PyramidIntegration()], data_collection={}) errors = capture_exceptions() @route("/") @@ -350,7 +352,7 @@ def errorhandler(exc, request): def test_errorhandler_500( sentry_init, pyramid_config, capture_exceptions, route, get_client ): - sentry_init(integrations=[PyramidIntegration()]) + sentry_init(integrations=[PyramidIntegration()], data_collection={}) errors = capture_exceptions() @route("/") @@ -375,7 +377,7 @@ def errorhandler(exc, request): def test_error_in_errorhandler( sentry_init, pyramid_config, capture_events, route, get_client ): - sentry_init(integrations=[PyramidIntegration()]) + sentry_init(integrations=[PyramidIntegration()], data_collection={}) @route("/") def index(request): @@ -452,7 +454,7 @@ def tween(request): def test_tween_ok(sentry_init, pyramid_config, capture_exceptions, route, get_client): - sentry_init(integrations=[PyramidIntegration()]) + sentry_init(integrations=[PyramidIntegration()], data_collection={}) errors = capture_exceptions() @route("/") @@ -479,6 +481,7 @@ def test_tracing_error( sentry_init( integrations=[PyramidIntegration()], traces_sample_rate=1.0, + data_collection={}, ) items = capture_items("event", "span") @@ -518,6 +521,7 @@ def test_span_origin( sentry_init( integrations=[PyramidIntegration()], traces_sample_rate=1.0, + data_collection={}, ) items = capture_items("event", "span") @@ -534,20 +538,20 @@ def test_span_origin( @pytest.mark.parametrize( - "init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY + "data_collection, expect_user", DATA_COLLECTION_USER_INFO_CASES ) def test_span_sets_user_id_on_segment( sentry_init, pyramid_config, capture_items, get_client, - init_kwargs, + data_collection, expect_user, ): sentry_init( integrations=[PyramidIntegration()], traces_sample_rate=1.0, - **init_kwargs, + data_collection=data_collection, ) class AuthenticationPolicy: @@ -575,7 +579,7 @@ def authenticated_userid(self, request): @pytest.mark.parametrize( - "init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY + "data_collection, expect_user", DATA_COLLECTION_USER_INFO_CASES ) def test_user_id_error_event_data_collection( sentry_init, @@ -583,10 +587,10 @@ def test_user_id_error_event_data_collection( capture_events, route, get_client, - init_kwargs, + data_collection, expect_user, ): - sentry_init(integrations=[PyramidIntegration()], **init_kwargs) + sentry_init(integrations=[PyramidIntegration()], data_collection=data_collection) events = capture_events() class AuthenticationPolicy: diff --git a/tests/integrations/utils.py b/tests/integrations/utils.py index 4fd3dec490..1f2d469514 100644 --- a/tests/integrations/utils.py +++ b/tests/integrations/utils.py @@ -56,22 +56,3 @@ 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 729d067bb4..efa9871d7e 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_LEGACY +from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES @pytest.fixture @@ -977,11 +977,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_LEGACY -) +@pytest.mark.parametrize("data_collection, expect_ip", DATA_COLLECTION_USER_INFO_CASES) def test_user_info_span_attributes_data_collection( - sentry_init, capture_items, init_kwargs, expect_ip + sentry_init, capture_items, data_collection, expect_ip ): def dogpark(environ, start_response): with sentry_sdk.start_span(name="child-span"): @@ -989,11 +987,9 @@ def dogpark(environ, start_response): start_response("200 OK", []) return ["Go get the ball! Good dog!"] - init_kwargs = dict(init_kwargs) # shallow copy so we can mutate - sentry_init( traces_sample_rate=1.0, - **init_kwargs, + data_collection=data_collection, ) app = SentryWsgiMiddleware(dogpark) client = Client(app) @@ -1016,13 +1012,11 @@ 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_LEGACY -) +@pytest.mark.parametrize("data_collection, expect_ip", DATA_COLLECTION_USER_INFO_CASES) def test_user_info_error_event_data_collection( - sentry_init, crashing_app, capture_events, init_kwargs, expect_ip + sentry_init, crashing_app, capture_events, data_collection, expect_ip ): - sentry_init(**init_kwargs) + sentry_init(data_collection=data_collection) app = SentryWsgiMiddleware(crashing_app) client = Client(app) events = capture_events()