o
    0 i                     @   s  d dl Z d dlmZ d dlmZ 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 erFd d	lmZmZmZ d d
lmZ z
d dlmZmZ W n ey[   edw zd dlZW n eym   edw dZG dd deZdd Zdd ZdS )    N)deepcopy)wraps)DidNotEnable)should_send_default_pii)SOURCE_FOR_STYLETransactionSource)transaction_from_function)TYPE_CHECKING)AnyCallableDict)Event)StarletteIntegrationStarletteRequestExtractorzStarlette is not installedzFastAPI is not installedzgeneric FastAPI requestc                   @   s   e Zd ZdZedd ZdS )FastApiIntegrationfastapic                   C   s
   t   d S N)patch_get_request_handler r   r   k/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/sentry_sdk/integrations/fastapi.py
setup_once%   s   
zFastApiIntegration.setup_onceN)__name__
__module____qualname__
identifierstaticmethodr   r   r   r   r   r   "   s    r   c                 C   s   d}|dkr|j d}|rt|pd}n|dkr-|j d}|r-t|dd }|d ur-|}|s5t}tj}nt| }| j||d d S )N endpointurlroutepath)source)	scopegetr   getattr_DEFAULT_TRANSACTION_NAMEr   ZROUTEr   Zset_transaction_name)r"   transaction_stylerequestnamer   r   r    r!   r   r   r    _set_transaction_name_and_source+   s"   r)   c                     s    t jj  fdd} | t j_d S )Nc                     sb   | d}|r"|jd ur"t|js"|jtfdd}||_| i |  fdd}|S )N	dependantc                     sF   t  }|jd ur|j  t  }|jd ur|j   | i |S r   )
sentry_sdkget_current_scopeZtransactionZupdate_active_threadget_isolation_scopeZprofileZupdate_active_thread_id)argskwargsZcurrent_scopesentry_scope)old_callr   r   _sentry_callR   s   



zTpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_callc                     s   t  t}|d u r| i |I d H S | d }tt  |j| t  }t|}|	 I d H   fdd}tj
|_|||| | i |I d H S )Nr   c                    s    fdd}|S )Nc                    sN   |  di } rd v rt r d |d< d v r d |d< t|| d< | S )Nr'   cookiesdata)r#   r   r   )eventhintZrequest_infoinfor   r   event_processort   s   zpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app.<locals>._make_request_event_processor.<locals>.event_processorr   )reqintegrationr9   r7   r   r   _make_request_event_processorr   s   zzpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app.<locals>._make_request_event_processor)r+   Z
get_clientZget_integrationr   r)   r,   r&   r-   r   Zextract_request_infor   _nameZadd_event_processor)r.   r/   r;   r'   r0   Z	extractorr<   )old_appr7   r   _sentry_appc   s"   zSpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app)r#   callasyncioiscoroutinefunctionr   )r.   r/   r*   r2   r?   Zold_get_request_handler)r>   r1   r   _sentry_get_request_handlerH   s   


(z>patch_get_request_handler.<locals>._sentry_get_request_handler)r   ZroutingZget_request_handler)rD   r   rC   r   r   D   s   Er   )rA   copyr   	functoolsr   r+   Zsentry_sdk.integrationsr   Zsentry_sdk.scoper   Zsentry_sdk.tracingr   r   Zsentry_sdk.utilsr   typingr	   r
   r   r   Zsentry_sdk._typesr   Z!sentry_sdk.integrations.starletter   r   r   ImportErrorr%   r   r)   r   r   r   r   r   <module>   s4    	