
    tni                     B   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rd d	lmZmZmZ d d
lmZ 	 d dlmZmZ n# e$ r  ed          w xY w	 d dlZn# e$ r  ed          w xY wdZ G d de          Zdddeddddf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                   *    e Zd ZdZedd            ZdS )FastApiIntegrationfastapireturnNc                  "    t                       d S N)patch_get_request_handler     \/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/sentry_sdk/integrations/fastapi.py
setup_oncezFastApiIntegration.setup_once%   s    !#####r   r   N)__name__
__module____qualname__
identifierstaticmethodr   r   r   r   r   r   "   s7        J$ $ $ \$ $ $r   r   scopezsentry_sdk.Scopetransaction_stylerequestr   r   c                 T   d}|dk    r.|j                             d          }|rt          |          pd}n7|dk    r1|j                             d          }|rt          |dd           }||}|st          }t
          j        }nt          |         }|                     ||           d S )N endpointurlroutepath)source)	r"   getr	   getattr_DEFAULT_TRANSACTION_NAMEr   ROUTEr   set_transaction_name)r"   r#   r$   namer'   r)   r*   r+   s           r    _set_transaction_name_and_sourcer2   *   s     DJ&&=$$Z00 	=,X66<"D	e	#	#!!'** 	5&$//D 5("(!"34	tF33333r   c                  X    t           j        j        dfd} | t           j        _        d S )Nargsr   kwargsr   c                      |                     d          }|rI|j        Bt          j        |j                  s)|j        t	                    dfd            }||_         | i |dfd}|S )	N	dependantr4   r   r5   r   c                      t          j                    }|j        |j                                         t          j                    }|j        |j                                          | i |S r   )
sentry_sdkget_current_scopetransactionupdate_active_threadget_isolation_scopeprofileupdate_active_thread_id)r4   r5   current_scopesentry_scopeold_calls       r   _sentry_callzTpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_callP   sp     * < > > ,8!-BBDDD)=??'3 (@@BBBx0000r   c                    K   t          j                                        t                    }| | i | d {V S | d         }t	          t          j                    |j        |           t          j                    }t          |          }|	                                 d {V 	 	 	 	 	 	 dfd}t          j
        |_        |                     |||                      | i | d {V S )	Nr   reqr   integrationr   (Callable[[Event, Dict[str, Any]], Event]c                     dfd}|S )Neventr   hintDict[str, Any]r   c                     |                      di           }r,dv rt                      rd         |d<   dv rd         |d<   t          |          | d<   | S )Nr$   cookiesdata)r,   r   r   )rI   rJ   request_infoinfos      r   event_processorzpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app.<locals>._make_request_event_processor.<locals>.event_processorq   sr    #(99Y#;#;L @$,,1H1J1J,6:9oL3!T>>37<L0'/'='=E)$ Lr   )rI   r   rJ   rK   r   r   r   )rE   rF   rQ   rP   s      r   _make_request_event_processorzzpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app.<locals>._make_request_event_processorn   s)    
! 
! 
! 
! 
! 
! '&r   )rE   r   rF   r   r   rG   )r9   
get_clientget_integrationr   r2   r:   r#   r=   r   extract_request_infor    _nameadd_event_processor)	r4   r5   rF   r$   rA   	extractorrR   rP   old_apps	          @r   _sentry_appzSpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app`   sT     $/11AABTUUK"$Wd5f5555555551gG,,..0Mw   &9;;L1'::I"7799999999D'').';' ' ' ' ' '" "4!>L,,--g{CC   !$1&111111111r   r4   r   r5   r   r   r   )r,   callasyncioiscoroutinefunctionr   )r4   r5   r7   rC   rZ   rY   rB   old_get_request_handlers        @@r   _sentry_get_request_handlerz>patch_get_request_handler.<locals>._sentry_get_request_handlerG   s    JJ{++		**/	?? + !~H8__	1 	1 	1 	1 	1 _	1 *IN))4:6::$	2 $	2 $	2 $	2 $	2 $	2L r   r[   )r   routingget_request_handler)r`   r_   s    @r   r   r   D   s@    %oA? ? ? ? ? ?B +FGO'''r   r   ) r]   copyr   	functoolsr   r9   sentry_sdk.integrationsr   sentry_sdk.scoper   sentry_sdk.tracingr   r   sentry_sdk.utilsr	   typingr
   r   r   r   sentry_sdk._typesr   !sentry_sdk.integrations.starletter   r   r   ImportErrorr.   r   strr2   r   r   r   r   <module>rn      s                    0 0 0 0 0 0 4 4 4 4 4 4 B B B B B B B B 6 6 6 6 6 6             (**********''''''5          5 5 5
,3
4
4453NNNN 3 3 3
,1
2
223 6 $ $ $ $ $- $ $ $44254@E4	4 4 4 44DF DF DF DF DF DFs   A A"&A+ +A<