2020
2121if TYPE_CHECKING :
2222 from collections .abc import Generator
23- from typing import Any , Dict , Union
23+ from typing import Any , Dict , Union , Callable
2424 from graphene .language .source import Source # type: ignore
2525 from graphql .execution import ExecutionResult
2626 from graphql .type import GraphQLSchema
@@ -48,7 +48,7 @@ def _patch_graphql():
4848 def _sentry_patched_graphql_sync (schema , source , * args , ** kwargs ):
4949 # type: (GraphQLSchema, Union[str, Source], Any, Any) -> ExecutionResult
5050 scope = sentry_sdk .get_isolation_scope ()
51- scope .add_event_processor (_event_processor )
51+ scope .add_event_processor (_make_event_processor ( source ) )
5252
5353 with graphql_span (schema , source , kwargs ):
5454 result = old_graphql_sync (schema , source , * args , ** kwargs )
@@ -75,7 +75,7 @@ async def _sentry_patched_graphql_async(schema, source, *args, **kwargs):
7575 return await old_graphql_async (schema , source , * args , ** kwargs )
7676
7777 scope = sentry_sdk .get_isolation_scope ()
78- scope .add_event_processor (_event_processor )
78+ scope .add_event_processor (_make_event_processor ( source ) )
7979
8080 with graphql_span (schema , source , kwargs ):
8181 result = await old_graphql_async (schema , source , * args , ** kwargs )
@@ -99,16 +99,21 @@ async def _sentry_patched_graphql_async(schema, source, *args, **kwargs):
9999 graphene_schema .graphql = _sentry_patched_graphql_async
100100
101101
102- def _event_processor (event , hint ):
103- # type: (Event, Dict[str, Any]) -> Event
104- if should_send_default_pii ():
105- request_info = event .setdefault ("request" , {})
106- request_info ["api_target" ] = "graphql"
102+ def _make_event_processor (source ):
103+ # type: (Any) -> Callable[[Event, dict[str, Any]], Event]
104+ def _event_processor (event , hint ):
105+ # type: (Event, Dict[str, Any]) -> Event
106+ if should_send_default_pii ():
107+ request_info = event .setdefault ("request" , {})
108+ request_info ["api_target" ] = "graphql"
109+ request_info ["data" ] = {"query" : source }
107110
108- elif event .get ("request" , {}).get ("data" ):
109- del event ["request" ]["data" ]
111+ elif event .get ("request" , {}).get ("data" ):
112+ del event ["request" ]["data" ]
110113
111- return event
114+ return event
115+
116+ return _event_processor
112117
113118
114119@contextmanager
0 commit comments