o
    h                     @   s4  d dl Z d dlmZ d dlmZ d dlmZmZ d dlm	Z	 d dl
mZ d dlmZmZmZ d dlmZ d d	lmZ d dlZd d
lmZmZ d dlmZ erpd dlmZ d dlmZ d dlmZ d dlmZ ededef dZzd dlm Z! W n e"y   edw G dd deZdd Z#G dd deZ$dS )    N)reraise)Hub)IntegrationDidNotEnable)_make_request_event_processor)TRANSACTION_SOURCE_COMPONENT)capture_internal_exceptionsevent_from_exceptionparse_version)TYPE_CHECKINGwraps)ChaliceChaliceViewError)EventSourceHandler)Any)Dict)TypeVar)CallableF.)bound)__version__zChalice is not installedc                   @   s   e Zd Zdd ZdS )r   c           	   
   C   s   t j}|j}| b}t  | }|t||| W d    n1 s&w   Y  zt	| ||W W  d    S  t
yc   t }t||jdddd\}}|j||d |  t|  Y nw W d    d S 1 sow   Y  d S )NchaliceFtypehandledclient_options	mechanismhint)r   currentclient
push_scoper   get_remaining_time_in_millisadd_event_processorr   ChaliceEventSourceHandler__call__	Exceptionsysexc_infor	   optionscapture_eventflushr   )	selfeventcontexthubr"   scopeconfigured_timer*   r     r4   b/var/www/html/aiguide_backend/venv/lib/python3.10/site-packages/sentry_sdk/integrations/chalice.pyr'   #   s2   


	"zEventSourceHandler.__call__N)__name__
__module____qualname__r'   r4   r4   r4   r5   r   "   s    r   c                    s   t  fdd}|S )Nc            	         s  t j}|j}| n}t #  j }|j jjt	d |
t j  j| W d    n1 s4w   Y  zdi | W W  d    S  tyw } z#t|trV t }t||jdddd\}}|j||d |   d }~ww 1 s{w   Y  d S )N)sourcer   Fr   r   r   r4   )r   r!   r"   r#   r   lambda_contextr$   set_transaction_namefunction_namer   r%   r   current_requestto_dictr(   
isinstancer   r)   r*   r	   r+   r,   r-   )	function_argsr1   r"   r2   r3   excr*   r/   r    appview_functionr4   r5   wrapped_view_function>   sF   



z:_get_view_function_response.<locals>.wrapped_view_functionr   rC   rD   r@   rE   r4   rB   r5   _get_view_function_response<   s   "rG   c                   @   s   e Zd ZdZedd ZdS )ChaliceIntegrationr   c                     sn   t t} | d u rtdt| dk rtj n	ddlm} |j  fdd}| dk r.|t_n||_tt	j
_d S )NzUnparsable Chalice version: {})      r   )RestAPIEventHandlerc                    s   t | ||} | ||S )N)rG   rF   old_get_view_function_responser4   r5   sentry_event_responsey   s   z<ChaliceIntegration.setup_once.<locals>.sentry_event_response)r
   CHALICE_VERSIONr   formatr   rG   chalice.apprK   r   r   rC   )versionrK   rN   r4   rL   r5   
setup_onceg   s   
zChaliceIntegration.setup_onceN)r6   r7   r8   
identifierstaticmethodrS   r4   r4   r4   r5   rH   d   s    rH   )%r)   sentry_sdk._compatr   sentry_sdk.hubr   sentry_sdk.integrationsr   r   "sentry_sdk.integrations.aws_lambdar   sentry_sdk.tracingr   sentry_sdk.utilsr   r	   r
   sentry_sdk._typesr   sentry_sdk._functoolsr   r   r   r   rQ   r   r&   typingr   r   r   r   r   r   rO   ImportErrorrG   rH   r4   r4   r4   r5   <module>   s4    (