From 81a1362f5e16884bb127c57d5f995c8394da0c25 Mon Sep 17 00:00:00 2001 From: Erica Pisani Date: Tue, 6 Oct 2026 15:16:38 -0400 Subject: [PATCH] test(data-collection): Remove redundant empty `data_collection` from sentry_init An empty `data_collection` dict is equivalent to the default, so passing it to `sentry_init` is redundant. Drop it from the aiomysql, clickhouse_driver, django, pyreqwest and tornado tests. Refs PY-2936 --- tests/integrations/aiomysql/test_aiomysql.py | 41 ------- .../test_clickhouse_driver.py | 108 +----------------- tests/integrations/django/asgi/test_asgi.py | 8 +- tests/integrations/django/test_basic.py | 18 +-- .../django/test_data_scrubbing.py | 1 - .../integrations/django/test_db_query_data.py | 6 - .../django/test_db_transactions.py | 5 - .../integrations/pyreqwest/test_pyreqwest.py | 18 --- tests/integrations/tornado/test_tornado.py | 6 +- 9 files changed, 13 insertions(+), 198 deletions(-) diff --git a/tests/integrations/aiomysql/test_aiomysql.py b/tests/integrations/aiomysql/test_aiomysql.py index fe4511624b..e3ffe60329 100644 --- a/tests/integrations/aiomysql/test_aiomysql.py +++ b/tests/integrations/aiomysql/test_aiomysql.py @@ -361,47 +361,6 @@ async def test_execute_record_params(sentry_init, capture_events) -> None: ] -@pytest.mark.asyncio -async def test_execute_record_params_with_data_collection_default( - sentry_init, capture_events -) -> None: - sentry_init( - integrations=[AioMySQLIntegration()], - data_collection={}, - ) - events = capture_events() - - conn = await aiomysql.connect(**_connect_args()) - - async with conn.cursor() as cur: - await cur.execute( - "INSERT INTO users(name, password, dob) VALUES (%s, %s, %s)", - ("Bob", "secret_pw", datetime.date(1984, 3, 1)), - ) - - conn.close() - - capture_message("hi") - - (event,) = events - - for crumb in event["breadcrumbs"]["values"]: - del crumb["timestamp"] - - assert event["breadcrumbs"]["values"] == [ - CRUMBS_CONNECT, - { - "category": "query", - "data": { - "db.params": ["Bob", "secret_pw", "datetime.date(1984, 3, 1)"], - "db.paramstyle": "format", - }, - "message": "INSERT INTO users(name, password, dob) VALUES (%s, %s, %s)", - "type": "default", - }, - ] - - @pytest.mark.asyncio async def test_cursor_context_manager(sentry_init, capture_events) -> None: sentry_init( diff --git a/tests/integrations/clickhouse_driver/test_clickhouse_driver.py b/tests/integrations/clickhouse_driver/test_clickhouse_driver.py index ebfe990132..aca5ad5b47 100644 --- a/tests/integrations/clickhouse_driver/test_clickhouse_driver.py +++ b/tests/integrations/clickhouse_driver/test_clickhouse_driver.py @@ -322,109 +322,7 @@ def test_clickhouse_client_breadcrumbs_with_data_collection_disabled( assert event["breadcrumbs"]["values"] == expected_breadcrumbs -def test_clickhouse_client_breadcrumbs_with_data_collection_default( - sentry_init, capture_events -) -> None: - sentry_init( - integrations=[ClickhouseDriverIntegration()], - data_collection={}, - ) - events = capture_events() - - client = Client("localhost") - client.execute("DROP TABLE IF EXISTS test") - client.execute("CREATE TABLE test (x Int32) ENGINE = Memory") - client.execute("INSERT INTO test (x) VALUES", [{"x": 100}]) - client.execute("INSERT INTO test (x) VALUES", [[170], [200]]) - - res = client.execute("SELECT sum(x) FROM test WHERE x > %(minv)i", {"minv": 150}) - assert res[0][0] == 370 - - capture_message("hi") - - (event,) = events - - expected_breadcrumbs = [ - { - "category": "query", - "data": { - "db.system": "clickhouse", - "db.driver.name": "clickhouse-driver", - "db.name": "", - "db.user": "default", - "server.address": "localhost", - "server.port": 9000, - "db.result": [], - }, - "message": "DROP TABLE IF EXISTS test", - "type": "default", - }, - { - "category": "query", - "data": { - "db.system": "clickhouse", - "db.driver.name": "clickhouse-driver", - "db.name": "", - "db.user": "default", - "server.address": "localhost", - "server.port": 9000, - "db.result": [], - }, - "message": "CREATE TABLE test (x Int32) ENGINE = Memory", - "type": "default", - }, - { - "category": "query", - "data": { - "db.system": "clickhouse", - "db.driver.name": "clickhouse-driver", - "db.name": "", - "db.user": "default", - "server.address": "localhost", - "server.port": 9000, - }, - "message": "INSERT INTO test (x) VALUES", - "type": "default", - }, - { - "category": "query", - "data": { - "db.system": "clickhouse", - "db.driver.name": "clickhouse-driver", - "db.name": "", - "db.user": "default", - "server.address": "localhost", - "server.port": 9000, - }, - "message": "INSERT INTO test (x) VALUES", - "type": "default", - }, - { - "category": "query", - "data": { - "db.system": "clickhouse", - "db.driver.name": "clickhouse-driver", - "db.name": "", - "db.user": "default", - "server.address": "localhost", - "server.port": 9000, - "db.result": [[370]], - }, - "message": "SELECT sum(x) FROM test WHERE x > 150", - "type": "default", - }, - ] - - for crumb in expected_breadcrumbs: - crumb["data"] = ApproxDict(crumb["data"]) - - for crumb in event["breadcrumbs"]["values"]: - crumb.pop("timestamp", None) - - assert event["breadcrumbs"]["values"] == expected_breadcrumbs - - -def test_clickhouse_client_with_data_collection(sentry_init, capture_items) -> None: +def test_clickhouse_client(sentry_init, capture_items) -> None: sentry_init( integrations=[ClickhouseDriverIntegration()], traces_sample_rate=1.0, @@ -455,9 +353,7 @@ def test_clickhouse_client_with_data_collection(sentry_init, capture_items) -> N assert "db.result" not in attribute_keys -def test_clickhouse_client_send_data_generator_with_data_collection( - sentry_init, capture_events -) -> None: +def test_clickhouse_client_send_data_generator(sentry_init, capture_events) -> None: sentry_init( integrations=[ClickhouseDriverIntegration()], data_collection={"database_query_data": True}, diff --git a/tests/integrations/django/asgi/test_asgi.py b/tests/integrations/django/asgi/test_asgi.py index 297cd6a940..df62d35288 100644 --- a/tests/integrations/django/asgi/test_asgi.py +++ b/tests/integrations/django/asgi/test_asgi.py @@ -52,7 +52,6 @@ async def test_basic( ): sentry_init( integrations=[DjangoIntegration()], - data_collection={}, ) import channels # type: ignore[import-not-found] @@ -112,7 +111,6 @@ async def test_async_views( ): sentry_init( integrations=[DjangoIntegration()], - data_collection={}, ) comm = HttpCommunicator(application, "GET", "/async_message") @@ -171,7 +169,6 @@ async def test_async_views_concurrent_execution( settings.MIDDLEWARE = [] sentry_init( integrations=[DjangoIntegration()], - data_collection={}, ) application = make_asgi_application() @@ -211,7 +208,6 @@ async def test_async_middleware_that_is_function_concurrent_execution( ] sentry_init( integrations=[DjangoIntegration()], - data_collection={}, ) application = make_asgi_application() @@ -507,7 +503,9 @@ async def test_asgi_request_body( body, expected_data, ): - sentry_init(integrations=[DjangoIntegration()], data_collection={}) + sentry_init( + integrations=[DjangoIntegration()], + ) comm = HttpCommunicator( application, diff --git a/tests/integrations/django/test_basic.py b/tests/integrations/django/test_basic.py index 9b875e4694..44d604fe75 100644 --- a/tests/integrations/django/test_basic.py +++ b/tests/integrations/django/test_basic.py @@ -56,7 +56,6 @@ def test_view_exceptions( ): sentry_init( integrations=[DjangoIntegration()], - data_collection={}, ) exceptions = capture_exceptions() items = capture_items("event") @@ -85,7 +84,6 @@ def test_ensures_x_forwarded_header_is_honored_in_sdk_when_enabled_in_django( sentry_init( integrations=[DjangoIntegration()], - data_collection={}, ) exceptions = capture_exceptions() items = capture_items("event") @@ -111,7 +109,6 @@ def test_ensures_x_forwarded_header_is_not_honored_when_unenabled_in_django( """ sentry_init( integrations=[DjangoIntegration()], - data_collection={}, ) exceptions = capture_exceptions() items = capture_items("event") @@ -125,7 +122,9 @@ def test_ensures_x_forwarded_header_is_not_honored_when_unenabled_in_django( def test_middleware_exceptions(sentry_init, client, capture_exceptions): - sentry_init(integrations=[DjangoIntegration()], data_collection={}) + sentry_init( + integrations=[DjangoIntegration()], + ) exceptions = capture_exceptions() client.get(reverse("middleware_exc")) @@ -140,7 +139,6 @@ def test_request_captured( ): sentry_init( integrations=[DjangoIntegration()], - data_collection={}, ) items = capture_items("event") content, status, headers = unpack_werkzeug_response(client.get(reverse("message"))) @@ -313,7 +311,6 @@ def test_user_captured( ): sentry_init( integrations=[DjangoIntegration()], - data_collection={}, ) items = capture_items("event") content, status, headers = unpack_werkzeug_response(client.get(reverse("mylogin"))) @@ -343,7 +340,6 @@ def test_materialized_user_captured( ): sentry_init( integrations=[DjangoIntegration()], - data_collection={}, traces_sample_rate=1.0, ) @@ -445,7 +441,9 @@ def test_custom_error_handler_request_context( def test_500(sentry_init, client): - sentry_init(integrations=[DjangoIntegration()], data_collection={}) + sentry_init( + integrations=[DjangoIntegration()], + ) content, status, headers = unpack_werkzeug_response(client.get("/view-exc")) assert status.lower() == "500 internal server error" @@ -686,7 +684,6 @@ def test_django_connect_trace( """ sentry_init( integrations=[DjangoIntegration()], - data_collection={}, traces_sample_rate=1.0, ) @@ -847,7 +844,6 @@ def test_segment_name( sentry_init( integrations=[DjangoIntegration()], traces_sample_rate=1.0, - data_collection={}, ) items = capture_items("event", "span") @@ -883,7 +879,6 @@ def test_segment_name_tracing_disabled( ): sentry_init( integrations=[DjangoIntegration()], - data_collection={}, ) items = capture_items("event") @@ -1217,7 +1212,6 @@ def test_rest_framework_basic( pytest.importorskip("rest_framework") sentry_init( integrations=[DjangoIntegration()], - data_collection={}, ) exceptions = capture_exceptions() items = capture_items("event") diff --git a/tests/integrations/django/test_data_scrubbing.py b/tests/integrations/django/test_data_scrubbing.py index 1202ca300f..baf11ae640 100644 --- a/tests/integrations/django/test_data_scrubbing.py +++ b/tests/integrations/django/test_data_scrubbing.py @@ -215,7 +215,6 @@ def test_empty_query_string_is_dropped_with_data_collection( # reduce envelope size, so the ``query_string`` key is absent. sentry_init( integrations=[DjangoIntegration()], - data_collection={}, ) events = capture_events() diff --git a/tests/integrations/django/test_db_query_data.py b/tests/integrations/django/test_db_query_data.py index 0435d8ef1c..d40c261e24 100644 --- a/tests/integrations/django/test_db_query_data.py +++ b/tests/integrations/django/test_db_query_data.py @@ -134,7 +134,6 @@ def test_query_source( ): sentry_init( integrations=[DjangoIntegration()], - data_collection={}, traces_sample_rate=1.0, enable_db_query_source=True, db_query_source_threshold_ms=0, @@ -199,7 +198,6 @@ def test_query_source_with_module_in_search_path( sentry_init( integrations=[DjangoIntegration()], - data_collection={}, traces_sample_rate=1.0, enable_db_query_source=True, db_query_source_threshold_ms=0, @@ -255,7 +253,6 @@ def test_query_source_with_in_app_exclude( ): sentry_init( integrations=[DjangoIntegration()], - data_collection={}, traces_sample_rate=1.0, enable_db_query_source=True, db_query_source_threshold_ms=0, @@ -325,7 +322,6 @@ def test_query_source_with_in_app_include( ): sentry_init( integrations=[DjangoIntegration()], - data_collection={}, traces_sample_rate=1.0, enable_db_query_source=True, db_query_source_threshold_ms=0, @@ -382,7 +378,6 @@ def test_no_query_source_if_duration_too_short( ): sentry_init( integrations=[DjangoIntegration()], - data_collection={}, traces_sample_rate=1.0, enable_db_query_source=True, db_query_source_threshold_ms=100, @@ -451,7 +446,6 @@ def test_query_source_if_duration_over_threshold( ): sentry_init( integrations=[DjangoIntegration()], - data_collection={}, traces_sample_rate=1.0, enable_db_query_source=True, db_query_source_threshold_ms=100, diff --git a/tests/integrations/django/test_db_transactions.py b/tests/integrations/django/test_db_transactions.py index c7c6febacf..17bed097eb 100644 --- a/tests/integrations/django/test_db_transactions.py +++ b/tests/integrations/django/test_db_transactions.py @@ -645,7 +645,6 @@ def test_db_atomic_executemany( ): sentry_init( integrations=[DjangoIntegration(db_transaction_spans=True)], - data_collection={}, traces_sample_rate=1.0, ) items = capture_items("span") @@ -729,7 +728,6 @@ def test_db_atomic_rollback_execute( ): sentry_init( integrations=[DjangoIntegration(db_transaction_spans=True)], - data_collection={}, traces_sample_rate=1.0, ) @@ -793,7 +791,6 @@ def test_db_atomic_rollback_executemany( ): sentry_init( integrations=[DjangoIntegration(db_transaction_spans=True)], - data_collection={}, traces_sample_rate=1.0, ) items = capture_items("span") @@ -879,7 +876,6 @@ def test_db_atomic_execute_exception( ): sentry_init( integrations=[DjangoIntegration(db_transaction_spans=True)], - data_collection={}, traces_sample_rate=1.0, ) @@ -942,7 +938,6 @@ def test_db_atomic_executemany_exception( ): sentry_init( integrations=[DjangoIntegration(db_transaction_spans=True)], - data_collection={}, traces_sample_rate=1.0, ) items = capture_items("span") diff --git a/tests/integrations/pyreqwest/test_pyreqwest.py b/tests/integrations/pyreqwest/test_pyreqwest.py index eccbedaaf8..3094e25b42 100644 --- a/tests/integrations/pyreqwest/test_pyreqwest.py +++ b/tests/integrations/pyreqwest/test_pyreqwest.py @@ -63,7 +63,6 @@ def test_sync_client_spans(sentry_init, capture_items, server_port): sentry_init( integrations=[PyreqwestIntegration()], traces_sample_rate=1.0, - data_collection={}, ) url = f"http://localhost:{server_port}/hello?q=test#frag" @@ -97,7 +96,6 @@ async def test_async_client_spans(sentry_init, capture_items, server_port): sentry_init( integrations=[PyreqwestIntegration()], traces_sample_rate=1.0, - data_collection={}, ) url = f"http://localhost:{server_port}/hello" @@ -125,7 +123,6 @@ def test_sync_simple_request_spans(sentry_init, capture_items, server_port): sentry_init( integrations=[PyreqwestIntegration()], traces_sample_rate=1.0, - data_collection={}, ) url = f"http://localhost:{server_port}/hello-simple" @@ -152,7 +149,6 @@ async def test_async_simple_request_spans(sentry_init, capture_items, server_por sentry_init( integrations=[PyreqwestIntegration()], traces_sample_rate=1.0, - data_collection={}, ) url = f"http://localhost:{server_port}/hello-simple-async" @@ -183,7 +179,6 @@ def test_span_origin( sentry_init( integrations=[PyreqwestIntegration()], traces_sample_rate=1.0, - data_collection={}, ) url = f"http://localhost:{server_port}/origin" @@ -207,7 +202,6 @@ def test_outgoing_trace_headers( integrations=[PyreqwestIntegration()], traces_sample_rate=1.0, trace_propagation_targets=["localhost"], - data_collection={}, ) url = f"http://localhost:{server_port}/trace" @@ -245,7 +239,6 @@ def test_outgoing_trace_headers_append_to_baggage( traces_sample_rate=1.0, trace_propagation_targets=["localhost"], release="d08ebdb9309e1b004c6f52202de58a09c2268e42", - data_collection={}, ) url = f"http://localhost:{server_port}/baggage" @@ -302,7 +295,6 @@ def test_trace_propagation_targets( integrations=[PyreqwestIntegration()], trace_propagation_targets=trace_propagation_targets, traces_sample_rate=1.0, - data_collection={}, ) url = f"http://localhost:{server_port}/propagation" @@ -328,7 +320,6 @@ def test_omit_url_data_if_parsing_fails( sentry_init( integrations=[PyreqwestIntegration()], traces_sample_rate=1.0, - data_collection={}, ) url = f"http://localhost:{server_port}/parse-fail" @@ -364,7 +355,6 @@ def test_request_source_disabled( traces_sample_rate=1.0, enable_http_request_source=False, http_request_source_threshold_ms=0, - data_collection={}, ) url = f"http://localhost:{server_port}/hello" @@ -431,7 +421,6 @@ def test_request_source( traces_sample_rate=1.0, enable_http_request_source=True, http_request_source_threshold_ms=0, - data_collection={}, ) url = f"http://localhost:{server_port}/hello" @@ -472,7 +461,6 @@ 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={}, ) url = f"http://localhost:{server_port}/hello" @@ -510,7 +498,6 @@ def test_no_request_source_if_duration_too_short( traces_sample_rate=1.0, enable_http_request_source=True, http_request_source_threshold_ms=100, - data_collection={}, ) url = f"http://localhost:{server_port}/hello" @@ -557,7 +544,6 @@ def test_request_source_if_duration_over_threshold( traces_sample_rate=1.0, enable_http_request_source=True, http_request_source_threshold_ms=100, - data_collection={}, ) url = f"http://localhost:{server_port}/hello" @@ -606,7 +592,6 @@ def before_breadcrumb(crumb, hint): sentry_init( integrations=[PyreqwestIntegration()], before_breadcrumb=before_breadcrumb, - data_collection={}, ) url = f"http://localhost:{server_port}/hello?q=test#frag" @@ -645,7 +630,6 @@ async def test_async_crumb_capture( ): sentry_init( integrations=[PyreqwestIntegration()], - data_collection={}, ) url = f"http://localhost:{server_port}/hello?q=test#frag" @@ -695,7 +679,6 @@ def test_crumb_capture_client_error( ): sentry_init( integrations=[PyreqwestIntegration()], - data_collection={}, ) url = f"http://localhost:{server_port}/status/{status_code}" @@ -1128,7 +1111,6 @@ def test_omit_url_data_if_parsing_fails_data_collection( sentry_init( integrations=[PyreqwestIntegration()], traces_sample_rate=1.0, - data_collection={}, ) items = capture_items("span") diff --git a/tests/integrations/tornado/test_tornado.py b/tests/integrations/tornado/test_tornado.py index 288172971f..12a4a4ab95 100644 --- a/tests/integrations/tornado/test_tornado.py +++ b/tests/integrations/tornado/test_tornado.py @@ -246,7 +246,6 @@ def test_url_query_data_collection_no_query_string( sentry_init( integrations=[TornadoIntegration()], traces_sample_rate=1.0, - data_collection={}, ) items = capture_items("span") @@ -270,7 +269,6 @@ def test_url_query_data_collection_repeated_and_blank_params( sentry_init( integrations=[TornadoIntegration()], traces_sample_rate=1.0, - data_collection={}, ) items = capture_items("span") @@ -584,7 +582,7 @@ def get_current_user(self): def test_formdata(tornado_testcase, sentry_init, capture_events): - sentry_init(integrations=[TornadoIntegration()], data_collection={}) + sentry_init(integrations=[TornadoIntegration()]) events = capture_events() class FormdataHandler(RequestHandler): @@ -609,7 +607,7 @@ def post(self): def test_json(tornado_testcase, sentry_init, capture_events): - sentry_init(integrations=[TornadoIntegration()], data_collection={}) + sentry_init(integrations=[TornadoIntegration()]) events = capture_events() class FormdataHandler(RequestHandler):