U 췀gB@s"ddlmZddlZddlmZmZddlmZmZddlm Z ddl m Z ddl m Z ddlmZmZmZmZz ed ZWnek red YnXdd lmZerdd lmZmZmZmZdd lmZmZmZmZddl m!Z!ddl"m#Z#m$Z$GdddeZ%ddZ&ddZ'ddZ(dS)) import_moduleN) get_client capture_event) DidNotEnable Integration) ignore_logger)request_body_within_bounds)should_send_default_pii)capture_internal_exceptionsensure_integration_enabledevent_from_exceptionpackage_versionzariadne.graphqlzariadne is not installed) TYPE_CHECKING)AnyDictListOptional) GraphQLError GraphQLResult GraphQLSchema QueryParser) DocumentNode)EventEventProcessorc@seZdZdZeddZdS)AriadneIntegrationariadnecCs:td}|dkrtd|dkr(tdtdtdS)NrzUnparsable ariadne version.)rzariadne 0.20 or newer required.)r rr_patch_graphql)versionrM/opt/hc_python/lib/python3.8/site-packages/sentry_sdk/integrations/ariadne.py setup_once#szAriadneIntegration.setup_onceN)__name__ __module__ __qualname__ identifier staticmethodr!rrrr r srcsjtjtjtjttfdd}ttfdd}ttfdd}|t_|t_|t_dS)Ncs&t|}t||||}|S)N)_make_request_event_processor sentry_sdkget_isolation_scopeadd_event_processor)Z context_valueZ query_parserdataevent_processorresult)old_parse_queryrr _sentry_patched_parse_query9s z3_patch_graphql.._sentry_patched_parse_queryc s|f||}t|d}t|t}|r|t8|D],}t||jt j ddd\}}t ||dqDW5QRX|SNF)typeZhandled)Zclient_optionsZ mechanism)hint) _make_response_event_processorr(r)r*r is_activer r optionsrr%r) errorsargskwargsr-r,clienterroreventr3)old_handle_errorsrr %_sentry_patched_handle_graphql_errorsBs   z=_patch_graphql.._sentry_patched_handle_graphql_errorsc s|f||}t|d}t|t}|rt>|jpHgD],}t||j t j ddd\}}t ||dqJW5QRX|Sr0) r4r(r)r*rr5r r7r r6rr%r) r-r8r9Z query_resultr,r:r;r<r3)old_handle_query_resultrr #_sentry_patched_handle_query_resultZs   z;_patch_graphql.._sentry_patched_handle_query_result)ariadne_graphqlZ parse_queryZhandle_graphql_errorsZhandle_query_resultr r)r/r>r@r)r=r?r.r r3srcsfdd}|S)z*Add request data and api_target to events.c stts|Stztdp&idd}Wn(ttfk r\|YW5QRSXtrtt |r| di}d|d<|d<n|didr|dd=W5QRX|S)NheaderszContent-LengthrrequestgraphqlZ api_targetr+) isinstancedictr intget TypeError ValueErrorr rr setdefault)r<r3content_lengthZ request_infor+rr inner{s&   z,_make_request_event_processor..innerr)r+rNrrMr r'ws r'csfdd}|S)z2Add response data to the event's response context.c s>t.tr0dr0|di}di|d<W5QRX|S)Nr7contextsr+response)r r rHrK)r<r3rOrPrr rNs z-_make_response_event_processor..innerr)rPrNrrQr r4s r4)) importlibrr(rrZsentry_sdk.integrationsrrZsentry_sdk.integrations.loggingrZ$sentry_sdk.integrations._wsgi_commonrZsentry_sdk.scoper Zsentry_sdk.utilsr r r r rA ImportErrortypingrrrrrZ ariadne.typesrrrrZgraphql.language.astrZsentry_sdk._typesrrrrr'r4rrrr s*       D