o
    ٰ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dZ'dddZ(d 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dZdS )AriadneIntegrationariadnereturnNc                  C   s$   t d} tt|  td t  d S )Nr   )r   r   r   r   _patch_graphql)version r    S/home/ubuntu/.local/lib/python3.10/site-packages/sentry_sdk/integrations/ariadne.py
setup_once#   s   

zAriadneIntegration.setup_oncer   N)__name__
__module____qualname__
identifierstaticmethodr"   r    r    r    r!   r       s    r   r   c                     s   t jt j t jtt								dfd	d
} tt 								d fdd}tt								dfdd}| t _|t _|t _d S )Ncontext_valueOptional[Any]query_parserOptional[QueryParser]datar   r   r   c                    s&   t |}t |  | ||}|S )N)_make_request_event_processor
sentry_sdkget_isolation_scopeadd_event_processor)r)   r+   r-   event_processorresult)old_parse_queryr    r!   _sentry_patched_parse_query2   s   z3_patch_graphql.<locals>._sentry_patched_parse_queryerrorsList[GraphQLError]argskwargsr   c           	         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)typehandled)client_options	mechanism)hint)_make_response_event_processorr/   r0   r1   r   	is_activer   r   optionsr   r'   r   )	r6   r8   r9   r3   r2   clienterroreventr@   )old_handle_errorsr    r!   %_sentry_patched_handle_graphql_errors>   s(   

z=_patch_graphql.<locals>._sentry_patched_handle_graphql_errorsr3   c           	         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 r:   )rA   r/   r0   r1   r   rB   r   r6   r   rC   r   r'   r   )	r3   r8   r9   query_resultr2   rD   rE   rF   r@   )old_handle_query_resultr    r!   #_sentry_patched_handle_query_resultW   s(   

z;_patch_graphql.<locals>._sentry_patched_handle_query_result)r)   r*   r+   r,   r-   r   r   r   )r6   r7   r8   r   r9   r   r   r   )r3   r   r8   r   r9   r   r   r   )ariadne_graphqlparse_queryhandle_graphql_errorshandle_query_resultr   r   )r5   rH   rK   r    )rG   rJ   r4   r!   r   -   sH   
r   r-   r   r   c                       d	 fdd}|S )
z*Add request data and api_target to events.rF   r   r@   dict[str, Any]r   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   requestgraphql
api_targetr-   )
isinstancedictr   intget	TypeError
ValueErrorr
   r	   r   
setdefault)rF   r@   content_lengthrequest_infor-   r    r!   innerx   s:   




z,_make_request_event_processor.<locals>.innerNrF   r   r@   rQ   r   r   r    )r-   r`   r    r_   r!   r.   u   s   r.   responseDict[str, Any]c                    rP   )
z2Add response data to the event's response context.rF   r   r@   rQ   r   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 )Nr6   contextsr-   rb   )r   r
   rY   r\   )rF   r@   rd   rb   r    r!   r`      s   



z-_make_response_event_processor.<locals>.innerNra   r    )rb   r`   r    re   r!   rA      s   
rA   r#   )r-   r   r   r   )rb   rc   r   r   )*	importlibr   r/   r   r   sentry_sdk.integrationsr   r   r   sentry_sdk.integrations.loggingr   $sentry_sdk.integrations._wsgi_commonr	   sentry_sdk.scoper
   sentry_sdk.utilsr   r   r   r   rL   ImportErrortypingr   r   r   r   r   ariadne.typesr   r   r   r   graphql.language.astr   sentry_sdk._typesr   r   r   r   r.   rA   r    r    r    r!   <module>   s.    

H