o
    hI                     @   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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)TYPE_CHECKING)Hub_should_send_default_pii)DidNotEnable)SOURCE_FOR_STYLETRANSACTION_SOURCE_ROUTE)transaction_from_functionlogger)AnyCallableDict)Scope)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   b/var/www/html/aiguide_backend/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-|}|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   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_scopeprofileupdate_active_thread_id)argskwargshubsentry_scope)old_callr   r   _sentry_callS   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hintrequest_infoinfor   r   event_processors   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_processorq   s   zzpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app.<locals>._make_request_event_processor)r   r/   get_integrationr   r0   r-   r*   r   extract_request_infor   _nameadd_event_processor)r3   r4   r5   rB   r6   r+   	extractorrC   )old_appr>   r   _sentry_app`   s&   

!zSpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app)r%   callasyncioiscoroutinefunctionr   )r3   r4   r.   r8   rJ   old_get_request_handler)rI   r7   r   _sentry_get_request_handlerI   s   


*z>patch_get_request_handler.<locals>._sentry_get_request_handler)r   routingget_request_handler)rP   r   rN   r   r   E   s   Cr   )!rL   copyr   sentry_sdk._functoolsr   sentry_sdk._typesr   sentry_sdk.hubr   r   sentry_sdk.integrationsr   sentry_sdk.tracingr   r	   sentry_sdk.utilsr
   r   typingr   r   r   sentry_sdk.scoper   !sentry_sdk.integrations.starletter   r   r   ImportErrorr'   r   r-   r   r   r   r   r   <module>   s2    	