o
    ZhM                     @   s  d dl Z d dlm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mZ d dlmZmZ erLd d	lmZmZmZ d d
lmZ d dlmZ z
d dlmZmZ W n eya   edw zd dlZW n eys   edw dZG dd deZdd Z dd Z!dS )    N)deepcopy)wraps)TYPE_CHECKING)Hub_should_send_default_pii)DidNotEnable)SOURCE_FOR_STYLETRANSACTION_SOURCE_ROUTE)transaction_from_functionlogger)AnyCallableDict)Scope)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   V/var/www/html/lang_env/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-|}|s4t}t}nt| }| j||d t	d|| d S )N endpointurlroutepath)sourcez;[FastAPI] Set transaction name and source on scope: %s / %s)
scopegetr
   getattr_DEFAULT_TRANSACTION_NAMEr	   r   Zset_transaction_namer   debug)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                     sT   t j}| }|jd ur|j   | i |W  d    S 1 s#w   Y  d S r   )r   currentconfigure_scopeZprofileZupdate_active_thread_id)argskwargshubsentry_scope)old_callr   r   _sentry_callT   s   


$zTpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_callc                     s   t j}|t}|d u r| i |I d H S | 0}| d }t||j| t|}| I d H   fdd}tj	|_
|||| W d    n1 sNw   Y  | 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integrationr=   r;   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   r/   Zget_integrationr   r0   r-   r*   r   Zextract_request_infor   _nameZadd_event_processor)r1   r2   r3   r?   r4   r+   Z	extractorr@   )old_appr;   r   _sentry_appa   s&   

!zSpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app)r&   callasyncioiscoroutinefunctionr   )r1   r2   r.   r6   rC   Zold_get_request_handler)rB   r5   r   _sentry_get_request_handlerJ   s   


*z>patch_get_request_handler.<locals>._sentry_get_request_handler)r   ZroutingZget_request_handler)rH   r   rG   r   r   F   s   Cr   )"rE   copyr   Zsentry_sdk._functoolsr   Zsentry_sdk._typesr   Zsentry_sdk.hubr   r   Zsentry_sdk.integrationsr   Zsentry_sdk.tracingr   r	   Zsentry_sdk.utilsr
   r   typingr   r   r   Zsentry_sdk.scoper   r   Z!sentry_sdk.integrations.starletter   r   r   ImportErrorr(   r   r-   r   r   r   r   r   <module>   s4    	