
    \j                        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 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mZ 	 d dlZdZ!e jD                  dk\  rd dl#m$Z$ nd dl%m$Z$  G d de      Z&ddde'ddddfdZ(d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)NoOpStreamedSpanStreamedSpan)SOURCE_FOR_STYLETransactionSource)has_span_streaming_enabled)transaction_from_function)TYPE_CHECKING)AnyCallableDict)Event)StarletteIntegrationStarletteRequestExtractor+_set_request_body_data_on_streaming_segmentzStarlette is not installedzFastAPI is not installedzgeneric FastAPI request)      )iscoroutinefunctionc                   "    e Zd ZdZedd       Zy)FastApiIntegrationfastapiNc                      t                y N)patch_get_request_handler     I/root/env/lib/python3.12/site-packages/sentry_sdk/integrations/fastapi.py
setup_oncezFastApiIntegration.setup_once/   s    !#r   returnN)__name__
__module____qualname__
identifierstaticmethodr!   r   r   r    r   r   ,   s    J$ $r   r   scopezsentry_sdk.Scopetransaction_stylerequestr   r#   c                 <   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                  ||       y )N endpointurlroutepath)source)	r)   getr   getattr_DEFAULT_TRANSACTION_NAMEr
   ROUTEr	   set_transaction_name)r)   r*   r+   namer.   r0   r1   r2   s           r     _set_transaction_name_and_sourcer9   4   s     DJ&==$$Z0,X6<"D	e	#!!'*5&$/D("((!"34	tF3r   c                  p    t         j                  j                  dfd} | t         j                  _        y )Nc                      |j                  d      }|rH|j                  <t        |j                        s'|j                  t              dfd       }||_         | i |dfd}|S )N	dependantc                     t        j                         }t        j                         }t        |j                        rI|j
                  }t        |t              rSt        |t              sC|j                  }|j                          n&|j                  |j                  j                          t        j                         }|j                  |j                  j                           | i |S r   )
sentry_sdkget_current_scope
get_clientr   optionsstreamed_span
isinstancer   r   _segment_update_active_threadtransactionupdate_active_threadget_isolation_scopeprofileupdate_active_thread_id)argskwargscurrent_scopeclientcurrent_spansegmentsentry_scopeold_calls          r    _sentry_callzTpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_callZ   s     * < < >#..0-fnn=#0#>#>L!,=j$&6G #/"7"7557"..:!--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 {   	 	 	 	 	 	 dfd}t        j                  |_        |j                   |||             t        |j                        rt                	| i | d {   S 7 7 o7 w)Nr   c                     dfd}|S )Nc                     | j                  di       }r"dv rt               rd   |d<   dv rd   |d<   t        |      | d<   | S )Nr+   cookiesdata)r3   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_processor   s[    #(99Y#;L$,1H1J6:9oL3!T>37<L0'/'=E)$ Lr   )rY   r   rZ   zDict[str, Any]r#   r   r   )reqintegrationr]   r\   s      r    _make_request_event_processorzzpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app.<locals>._make_request_event_processor   s    
! '&r   )r^   r   r_   r   r#   z(Callable[[Event, Dict[str, Any]], Event])r>   r@   get_integrationr   r9   r?   r*   rH   r   extract_request_infor'   _nameadd_event_processorr   rA   r   )
rK   rL   rN   r_   r+   rQ   	extractorr`   r\   old_apps
           @r    _sentry_appzSpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_appu   s    **,F 001CDK"$d5f5551gG,,,.0M0Mw &99;L1':I"7799D'').';'" "4!>!>L,,-g{C *&..9;DA $1&111I 6 :6 2s5   7DDA$D D!A(D	D
DDDrK   r   rL   r   r#   r   )r3   callr   r   )rK   rL   r<   rS   rg   rf   rR   old_get_request_handlers        @@r    _sentry_get_request_handlerz>patch_get_request_handler.<locals>._sentry_get_request_handlerQ   so    JJ{+	*'	7 ~~H8_1 1, *IN)4:6:(	2T r   rh   )r   routingget_request_handler)rk   rj   s    @r    r   r   N   s)    %ooAAN` +FGOO'r   r"   )*syscopyr   	functoolsr   r>   sentry_sdk.integrationsr   sentry_sdk.scoper   sentry_sdk.tracesr   r   sentry_sdk.tracingr	   r
   sentry_sdk.tracing_utilsr   sentry_sdk.utilsr   typingr   r   r   r   sentry_sdk._typesr   !sentry_sdk.integrations.starletter   r   r   r   ImportErrorr5   version_infoinspectr   asyncior   strr9   r   r   r   r    <module>r      s    
    0 4 < B ? 6  **'5 3
 6  w++$- $44254@E4	44SFk  5
3
445
  3
1
223s   
B !B0 B-0B>