o
    0 i                     @   s   d dl mZ d dlZd dlmZmZ d dlmZmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZmZmZmZ zed	ZW n eyK   ed
w d dlmZ erzd dlmZmZmZmZ d dlmZmZmZm Z  d dl!m"Z" d dl#m$Z$m%Z% G dd deZ&dd Z'dd Z(dd Z)dS )    )import_moduleN)
get_clientcapture_event)_check_minimum_versionDidNotEnableIntegration)ignore_logger)request_body_within_bounds)should_send_default_pii)capture_internal_exceptionsensure_integration_enabledevent_from_exceptionpackage_versionzariadne.graphqlzariadne is not installed)TYPE_CHECKING)AnyDictListOptional)GraphQLErrorGraphQLResultGraphQLSchemaQueryParser)DocumentNode)EventEventProcessorc                   @   s   e Zd ZdZedd ZdS )AriadneIntegrationariadnec                  C   s$   t d} tt|  td t  d S )Nr   )r   r   r   r   _patch_graphql)version r   k/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/sentry_sdk/integrations/ariadne.py
setup_once#   s   

zAriadneIntegration.setup_onceN)__name__
__module____qualname__
identifierstaticmethodr!   r   r   r   r    r       s    r   c                     sj   t jt j t jttfdd} tt  fdd}ttfdd}| t _|t _|t _d S )Nc                    s&   t |}t |  | ||}|S )N)_make_request_event_processor
sentry_sdkget_isolation_scopeadd_event_processor)Zcontext_valueZquery_parserdataevent_processorresult)old_parse_queryr   r    _sentry_patched_parse_query4   s   z3_patch_graphql.<locals>._sentry_patched_parse_queryc           	         s    | g|R i |}t |d }t | t }| rLt " | D ]}t||jt	j
ddd\}}t||d q%W d    |S 1 sGw   Y  |S N   F)typeZhandled)Zclient_optionsZ	mechanism)hint)_make_response_event_processorr(   r)   r*   r   	is_activer   r   optionsr   r%   r   )	errorsargskwargsr-   r,   clienterroreventr3   )old_handle_errorsr   r    %_sentry_patched_handle_graphql_errors=   s(   

z=_patch_graphql.<locals>._sentry_patched_handle_graphql_errorsc           	         s    | g|R i |}t |d }t | t }| rOt % | jp'g D ]}t||j	t
jddd\}}t||d q(W d    |S 1 sJw   Y  |S r0   )r4   r(   r)   r*   r   r5   r   r7   r   r6   r   r%   r   )	r-   r8   r9   Zquery_resultr,   r:   r;   r<   r3   )old_handle_query_resultr   r    #_sentry_patched_handle_query_resultU   s(   

z;_patch_graphql.<locals>._sentry_patched_handle_query_result)ariadne_graphqlZparse_queryZhandle_graphql_errorsZhandle_query_resultr   r   )r/   r>   r@   r   )r=   r?   r.   r    r   .   s   
r   c                        fdd}|S )z*Add request data and api_target to events.c              
      s   t  ts| S t c zt dpi dd}W n ttfy.   |  Y W  d    S w t rGtt	 |rG| 
di }d|d<  |d< n| di dr]| d d= W d    | S W d    | S W d    | S 1 spw   Y  | S )NheaderszContent-Lengthr   requestZgraphqlZ
api_targetr+   )
isinstancedictr   intget	TypeError
ValueErrorr
   r	   r   
setdefault)r<   r3   content_lengthZrequest_infor+   r   r    innerv   s:   




z,_make_request_event_processor.<locals>.innerr   )r+   rN   r   rM   r    r'   r   s   r'   c                    rB   )z2Add response data to the event's response context.c                    st   t  - t r  dr(| di }d i|d< W d    | S W d    | S W d    | S 1 s3w   Y  | S )Nr7   contextsr+   response)r   r
   rH   rK   )r<   r3   rO   rP   r   r    rN      s   



z-_make_response_event_processor.<locals>.innerr   )rP   rN   r   rQ   r    r4      s   r4   )*	importlibr   r(   r   r   Zsentry_sdk.integrationsr   r   r   Zsentry_sdk.integrations.loggingr   Z$sentry_sdk.integrations._wsgi_commonr	   Zsentry_sdk.scoper
   Zsentry_sdk.utilsr   r   r   r   rA   ImportErrortypingr   r   r   r   r   Zariadne.typesr   r   r   r   Zgraphql.language.astr   Zsentry_sdk._typesr   r   r   r   r'   r4   r   r   r   r    <module>   s.    D 