From 3a2e49bac10089568b05c67e3fcd120ee89d9302 Mon Sep 17 00:00:00 2001 From: Erica Pisani Date: Thu, 1 Oct 2026 14:06:48 -0400 Subject: [PATCH 1/2] ref(gql)!: Drop `send_default_pii` support in GraphQL data collection The gql integration now relies solely on `data_collection.graphql` to decide whether to attach the query document, variables and error response to events. `send_default_pii` no longer has any effect here. Also fix a typo in a test assertion message (`exception(type)` -> `exception["type"]`) and remove the legacy PII tests. Fixes PY-2818 Fixes #7589 --- sentry_sdk/integrations/gql.py | 31 ++---------------- tests/integrations/gql/test_gql.py | 52 ++---------------------------- 2 files changed, 4 insertions(+), 79 deletions(-) diff --git a/sentry_sdk/integrations/gql.py b/sentry_sdk/integrations/gql.py index 30b4af6ad5..10112a6951 100644 --- a/sentry_sdk/integrations/gql.py +++ b/sentry_sdk/integrations/gql.py @@ -1,10 +1,8 @@ import sentry_sdk from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version -from sentry_sdk.scope import should_send_default_pii from sentry_sdk.utils import ( ensure_integration_enabled, event_from_exception, - has_data_collection_enabled, parse_version, ) @@ -61,10 +59,7 @@ def _data_from_document(document: "DocumentNode") -> "EventDataType": data: "EventDataType" = {"query": print_ast(document)} if operation_ast is not None: - if has_data_collection_enabled(client_options): - if client_options["data_collection"]["graphql"]["variables"]: - data["variables"] = operation_ast.variable_definitions - elif should_send_default_pii(): + if client_options["data_collection"]["graphql"]["variables"]: data["variables"] = operation_ast.variable_definitions if operation_ast.name is not None: @@ -155,29 +150,7 @@ def processor(event: "Event", hint: "dict[str, Any]") -> "Event": ) client_options = sentry_sdk.get_client().options - if has_data_collection_enabled(client_options): - if client_options["data_collection"]["graphql"]["document"]: - if GraphQLRequest is not None and isinstance( - document_or_request, GraphQLRequest - ): - # In v4.0.0, gql moved to using GraphQLRequest instead of - # DocumentNode in execute - # https://github.com/graphql-python/gql/pull/556 - document = document_or_request.document - else: - document = document_or_request - - request["data"] = _data_from_document(document) - contexts = event.setdefault("contexts", {}) - response = contexts.setdefault("response", {}) - response.update( - { - "data": {"errors": errors}, - "type": response, - } - ) - - elif should_send_default_pii(): + if client_options["data_collection"]["graphql"]["document"]: if GraphQLRequest is not None and isinstance( document_or_request, GraphQLRequest ): diff --git a/tests/integrations/gql/test_gql.py b/tests/integrations/gql/test_gql.py index dcaee5be10..da00d0e9f5 100644 --- a/tests/integrations/gql/test_gql.py +++ b/tests/integrations/gql/test_gql.py @@ -4,6 +4,7 @@ from gql.transport.exceptions import TransportQueryError from gql.transport.requests import RequestsHTTPTransport +import sentry_sdk from sentry_sdk.integrations.gql import GQLIntegration from sentry_sdk.utils import parse_version @@ -107,7 +108,7 @@ def _make_erroneous_query(capture_events, execute_query): (exception,) = event["exception"]["values"] assert exception["type"] == "TransportQueryError", ( - "%s was captured, but we expected a TransportQueryError" % exception(type) + "%s was captured, but we expected a TransportQueryError" % exception["type"] ) assert "request" in event @@ -143,42 +144,10 @@ def test_real_gql_request_no_error(sentry_init, capture_events, execute_query): ) -@pytest.mark.parametrize("execute_query", _execute_query_funcs) -def test_real_gql_request_with_error_no_pii(sentry_init, capture_events, execute_query): - """ - Integration test verifying that the GQLIntegration works as expected with query resulting - in a GraphQL error, and that PII is not sent. - """ - sentry_init(integrations=[GQLIntegration()]) - - event = _make_erroneous_query(capture_events, execute_query) - - assert "data" not in event["request"] - assert "response" not in event["contexts"] - - -@pytest.mark.parametrize("execute_query", _execute_query_funcs) -def test_real_gql_request_with_error_with_pii( - sentry_init, capture_events, execute_query -): - """ - Integration test verifying that the GQLIntegration works as expected with query resulting - in a GraphQL error, and that PII is not sent. - """ - sentry_init(integrations=[GQLIntegration()], send_default_pii=True) - - event = _make_erroneous_query(capture_events, execute_query) - - assert "data" in event["request"] - assert "response" in event["contexts"] - - @pytest.mark.parametrize("execute_query", _execute_query_funcs) @pytest.mark.parametrize( "init_kwargs,expect_data", [ - pytest.param({}, False, id="no_pii_no_data_collection"), - pytest.param({"send_default_pii": True}, True, id="legacy_pii_on"), pytest.param( {"data_collection": {}}, True, @@ -194,22 +163,6 @@ def test_real_gql_request_with_error_with_pii( False, id="data_collection_document_off", ), - pytest.param( - { - "send_default_pii": True, - "data_collection": {"graphql": {"document": False}}, - }, - False, - id="data_collection_takes_precedence_over_send_default_pii_on", - ), - pytest.param( - { - "send_default_pii": False, - "data_collection": {"graphql": {"document": True}}, - }, - True, - id="data_collection_takes_precedence_over_send_default_pii_off", - ), ], ) def test_real_gql_request_with_error_data_collection( @@ -236,7 +189,6 @@ def test_real_gql_request_with_error_data_collection( @pytest.mark.parametrize( "init_kwargs,expect_variables", [ - pytest.param({"send_default_pii": True}, True, id="legacy_pii_on"), pytest.param( {"data_collection": {}}, True, From 4904b6e05d6d0eb6b1642e924efb6482b846f04a Mon Sep 17 00:00:00 2001 From: Erica Pisani Date: Thu, 1 Oct 2026 14:13:24 -0400 Subject: [PATCH 2/2] . --- tests/integrations/gql/test_gql.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integrations/gql/test_gql.py b/tests/integrations/gql/test_gql.py index da00d0e9f5..55283b2019 100644 --- a/tests/integrations/gql/test_gql.py +++ b/tests/integrations/gql/test_gql.py @@ -4,7 +4,6 @@ from gql.transport.exceptions import TransportQueryError from gql.transport.requests import RequestsHTTPTransport -import sentry_sdk from sentry_sdk.integrations.gql import GQLIntegration from sentry_sdk.utils import parse_version