o
    BDin                     @   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mZ d dlmZ erHd 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yo   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logger)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   X/var/www/Datamplify/venv/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 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   ROUTEr   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                     sF   t  }|jd ur|j  t  }|jd ur|j   | i |S r   )
sentry_sdkget_current_scopetransactionupdate_active_threadget_isolation_scopeprofileupdate_active_thread_id)argskwargscurrent_scopesentry_scope)old_callr   r   _sentry_callX   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hintrequest_infoinfor   r   event_processorz   s   zpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app.<locals>._make_request_event_processor.<locals>.event_processorr   )reqintegrationrC   rA   r   r   _make_request_event_processorx   s   zzpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app.<locals>._make_request_event_processor)r/   
get_clientget_integrationr   r-   r0   r*   r3   r   extract_request_infor   _nameadd_event_processor)r6   r7   rE   r+   r9   	extractorrF   )old_apprA   r   _sentry_appi   s"   zSpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app)r$   callasyncioiscoroutinefunctionr   )r6   r7   r.   r;   rN   old_get_request_handler)rM   r:   r   _sentry_get_request_handlerN   s   


(z>patch_get_request_handler.<locals>._sentry_get_request_handler)r   routingget_request_handler)rT   r   rR   r   r   J   s   Er   ) rP   copyr   	functoolsr   r/   sentry_sdk.integrationsr   sentry_sdk.scoper   sentry_sdk.tracingr   r   sentry_sdk.utilsr   r	   typingr
   r   r   r   sentry_sdk._typesr   !sentry_sdk.integrations.starletter   r   r   ImportErrorr&   r   r-   r   r   r   r   r   <module>   s4    	