diff --git a/sentry_sdk/integrations/_asgi_common.py b/sentry_sdk/integrations/_asgi_common.py index 020189acea..79a0e627ca 100644 --- a/sentry_sdk/integrations/_asgi_common.py +++ b/sentry_sdk/integrations/_asgi_common.py @@ -126,19 +126,14 @@ def _get_request_data( request_data["headers"] = _filter_headers(headers) - if has_data_collection_enabled(client_options): - qs = _get_query(asgi_scope) - if qs: - filtered_query_string = ( - _apply_data_collection_filtering_to_query_string( - query_string=qs, - behaviour=client_options["data_collection"]["url_query_params"], - ) - ) - if filtered_query_string: - request_data["query_string"] = filtered_query_string - else: - request_data["query_string"] = _get_query(asgi_scope) + qs = _get_query(asgi_scope) + if qs: + filtered_query_string = _apply_data_collection_filtering_to_query_string( + query_string=qs, + behaviour=client_options["data_collection"]["url_query_params"], + ) + if filtered_query_string: + request_data["query_string"] = filtered_query_string request_data["url"] = _get_url( asgi_scope, @@ -149,10 +144,7 @@ def _get_request_data( client = asgi_scope.get("client") if client: - if has_data_collection_enabled(client_options): - if client_options["data_collection"]["user_info"]: - request_data["env"] = {"REMOTE_ADDR": _get_ip(asgi_scope)} - elif should_send_default_pii(): + if client_options["data_collection"]["user_info"]: request_data["env"] = {"REMOTE_ADDR": _get_ip(asgi_scope)} return request_data diff --git a/tests/integrations/asgi/test_asgi.py b/tests/integrations/asgi/test_asgi.py index be50b86ed7..0d565a6bb4 100644 --- a/tests/integrations/asgi/test_asgi.py +++ b/tests/integrations/asgi/test_asgi.py @@ -184,18 +184,13 @@ async def app(scope, receive, send): @pytest.mark.asyncio -@pytest.mark.parametrize( - "should_send_pii", - [True, False], -) async def test_capture_transaction( sentry_init, asgi3_app, capture_items, - should_send_pii, ): sentry_init( - send_default_pii=should_send_pii, + data_collection={}, traces_sample_rate=1.0, ) app = SentryAsgiMiddleware(asgi3_app) @@ -219,13 +214,7 @@ async def test_capture_transaction( assert span["attributes"]["http.request.method"] == "GET" assert span["attributes"]["http.request.header.host"] == ["localhost"] assert span["attributes"]["http.request.header.user-agent"] == ["ASGI-Test-Client"] - - if should_send_pii: - assert ( - span["attributes"]["url.full"] == "http://localhost/some_url?somevalue=123" - ) - assert span["attributes"]["url.path"] == "/some_url" - assert span["attributes"]["http.query"] == "somevalue=123" + assert span["attributes"]["url.full"] == "http://localhost/some_url?somevalue=123" @pytest.mark.asyncio @@ -235,7 +224,7 @@ async def test_capture_transaction_with_error( capture_items, ): sentry_init( - send_default_pii=True, + data_collection={}, traces_sample_rate=1.0, ) @@ -414,7 +403,7 @@ async def test_websocket( request, ): sentry_init( - send_default_pii=True, + data_collection={}, traces_sample_rate=1.0, ) @@ -455,7 +444,7 @@ async def test_auto_session_tracking_with_aggregates( sentry_init, asgi3_app, capture_envelopes ): sentry_init( - send_default_pii=True, + data_collection={}, traces_sample_rate=1.0, ) app = SentryAsgiMiddleware(asgi3_app) @@ -501,7 +490,7 @@ async def test_fallback_segment_name_and_source( capture_items, ): sentry_init( - send_default_pii=True, + data_collection={}, traces_sample_rate=1.0, ) app = SentryAsgiMiddleware(asgi3_app) @@ -779,7 +768,6 @@ async def test_get_request_attributes_url_with_filtered_host( # the host header value, but "url.full" must still resolve rather than embedding # the substituted value. sentry_init( - send_default_pii=True, traces_sample_rate=1.0, data_collection={ "http_headers": {"request": {"mode": "allowlist", "terms": []}} @@ -838,20 +826,6 @@ def _http_scope(): @pytest.mark.parametrize( "init_kwargs, request_url, expected_query, expected_url_full", [ - pytest.param( - {"send_default_pii": True}, - "/foo?" + QUERY_STRING, - QUERY_STRING, - "http://example.com/foo?" + QUERY_STRING, - id="send_default_pii_true", - ), - pytest.param( - {"send_default_pii": False}, - "/foo?" + QUERY_STRING, - None, - None, - id="send_default_pii_false", - ), pytest.param( {}, "/foo?" + QUERY_STRING, @@ -884,16 +858,6 @@ def _http_scope(): "http://example.com/foo", id="data_collection_off", ), - pytest.param( - { - "send_default_pii": True, - "data_collection": {"url_query_params": {"mode": "off"}}, - }, - "/foo?" + QUERY_STRING, - None, - "http://example.com/foo", - id="data_collection_wins_over_send_default_pii", - ), pytest.param( {"_experiments": {"data_collection": {}}}, "/foo", @@ -953,27 +917,6 @@ async def test_get_request_attributes_query_data_collection( True, id="dc_default_user_info", ), - pytest.param( - { - "send_default_pii": True, - "data_collection": {"user_info": False}, - }, - True, - False, - id="dc_wins_over_pii", - ), - pytest.param( - {"send_default_pii": True}, - True, - True, - id="legacy_pii_true", - ), - pytest.param( - {"send_default_pii": False}, - True, - False, - id="legacy_pii_false", - ), pytest.param( {"data_collection": {}}, False, @@ -1096,8 +1039,6 @@ async def test_custom_transaction_name( @pytest.mark.parametrize( "init_kwargs, expect_ip", [ - pytest.param({"send_default_pii": True}, True, id="legacy_pii_true"), - pytest.param({"send_default_pii": False}, False, id="legacy_pii_false"), pytest.param( {"data_collection": {}}, True, @@ -1113,14 +1054,6 @@ async def test_custom_transaction_name( False, id="dc_user_info_false", ), - pytest.param( - { - "send_default_pii": True, - "data_collection": {"user_info": False}, - }, - False, - id="dc_wins_over_pii", - ), ], ) async def test_user_ip_address_on_all_spans( diff --git a/tests/integrations/django/asgi/test_asgi.py b/tests/integrations/django/asgi/test_asgi.py index 3a402ec7b4..50608d1a25 100644 --- a/tests/integrations/django/asgi/test_asgi.py +++ b/tests/integrations/django/asgi/test_asgi.py @@ -52,7 +52,7 @@ async def test_basic( ): sentry_init( integrations=[DjangoIntegration()], - send_default_pii=True, + data_collection={}, ) import channels # type: ignore[import-not-found] @@ -171,7 +171,7 @@ async def test_async_views_concurrent_execution( settings.MIDDLEWARE = [] sentry_init( integrations=[DjangoIntegration()], - send_default_pii=True, + data_collection={}, ) application = make_asgi_application() @@ -211,7 +211,7 @@ async def test_async_middleware_that_is_function_concurrent_execution( ] sentry_init( integrations=[DjangoIntegration()], - send_default_pii=True, + data_collection={}, ) application = make_asgi_application() diff --git a/tests/integrations/fastapi/test_fastapi.py b/tests/integrations/fastapi/test_fastapi.py index 164f1941e8..ae4777f448 100644 --- a/tests/integrations/fastapi/test_fastapi.py +++ b/tests/integrations/fastapi/test_fastapi.py @@ -128,7 +128,7 @@ async def body_form( async def test_request_info_json_body(sentry_init, capture_items): sentry_init( traces_sample_rate=1.0, - send_default_pii=True, + data_collection={}, integrations=[StarletteIntegration()], ) @@ -214,7 +214,7 @@ async def test_formdata_request_body(sentry_init, capture_items): async def test_request_body_too_big(sentry_init, capture_items): sentry_init( traces_sample_rate=1.0, - send_default_pii=True, + data_collection={}, integrations=[StarletteIntegration()], ) @@ -343,7 +343,7 @@ async def test_response(sentry_init, capture_events): sentry_init( integrations=[StarletteIntegration(), FastApiIntegration()], traces_sample_rate=1.0, - send_default_pii=True, + data_collection={}, ) app = fastapi_app_factory() @@ -728,7 +728,7 @@ def test_transaction_http_method_custom(sentry_init, capture_items): def test_request_url(sentry_init, capture_items): sentry_init( traces_sample_rate=1.0, - send_default_pii=True, + data_collection={}, integrations=[ StarletteIntegration(), ],