
    Uvhn                        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rd d	lmZmZmZ d d
lmZ 	 d dlmZmZ 	 d dlZdZ G d de      Zd Zd Zy# e$ r	  ed      w xY w# e$ r	  ed      w xY w)    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                        e Zd ZdZed        Zy)FastApiIntegrationfastapic                      t                y N)patch_get_request_handler     Z/opt/face_recognition/venv/lib/python3.12/site-packages/sentry_sdk/integrations/fastapi.py
setup_oncezFastApiIntegration.setup_once(   s
     	"#r   N)__name__
__module____qualname__
identifierstaticmethodr   r   r   r   r   r   %   s    J$ $r   r   c                 j   d}|dk(  r-|j                   j                  d      }|rCt        |      xs d}n3|dk(  r.|j                   j                  d      }|rt        |dd       }||}|st        }t
        j                  }n	t        |   }| j                  ||       t        j                  d||       y )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'   s           r    _set_transaction_name_and_sourcer2   .   s    DJ&==$$Z0,X6<"D	e	#!!'*5&$/D("((!"34	tF3
LLEtVr   c                  n    t         j                  j                  fd} | t         j                  _        y )Nc                      |j                  d      }|rQ|j                  Et        j                  |j                        s&|j                  t	              fd       }||_         | i |fd}|S )N	dependantc                      t        j                         }|j                  |j                  j                          t        j                         }|j
                  |j
                  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_calls       r   _sentry_callzTpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_callX   sm     !+ < < > ,,8!--BBD)==?''3 ((@@B000r   c                    K   t        j                         j                  t              }| | i | d {   S | d   }t	        t        j
                         |j                  |       t        j                         }t        |      }|j                          d {   fd}t        j                  |_        |j                   |||              | i | d {   S 7 7 H7 w)Nr   c                     fd}|S )Nc                     | j                  di       }r"dv rt               rd   |d<   dv rd   |d<   t        |      | d<   | S )Nr0   cookiesdata)r)   r   r   )eventhintrequest_infoinfos      r   event_processorzpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app.<locals>._make_request_event_processor.<locals>.event_processorz   s]     $)99Y#;L$,1H1J6:9oL3!T>37<L0'/'=E)$ Lr   r   )reqintegrationrM   rL   s      r   _make_request_event_processorzzpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app.<locals>._make_request_event_processorx   s    ! '&r   )r7   
get_clientget_integrationr   r2   r8   r/   r;   r   extract_request_infor   _nameadd_event_processor)	r>   r?   rO   r0   rA   	extractorrP   rL   old_apps	          @r   _sentry_appzSpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_appi   s     $//1AABTUK"$d5f5551gG,,,.0M0Mw &99;L1':I"7799D'$ "4!>!>L,,-g{C !$1&111E 6 :2 2s5   5C+C%A$C+C'AC+ C)!C+'C+)C+)r)   callasyncioiscoroutinefunctionr   )r>   r?   r5   rC   rX   rW   rB   old_get_request_handlers        @@r   _sentry_get_request_handlerz>patch_get_request_handler.<locals>._sentry_get_request_handlerN   su    JJ{+	*//	? ~~H8_
1 
1 *IN)4:6:&	2P r   )r   routingget_request_handler)r]   r\   s    @r   r   r   J   s)    %ooAACJ +FGOO'r   ) rZ   copyr   	functoolsr   r7   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   r2   r   r   r   r   <module>rj      s        0 4 B
 !**'53
 6 $- $8IFc  5
3
445
  3
1
223s   
A+ A< +A9<B
