
    ghR                      V   S SK r S SKrS SKJr  S SKJrJrJr  S SKJr  S SK	r	S SK
Jr  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJr  S SKJrJrJrJrJrJr  S SKJr  SrSr \(       a.  S SKJ!r!  S SKJ"r"  S SKJ#r#  S SKJ$r$  S SK%J&r&J'r'J(r(  \"" S\#S\!4   S9r)S r* " S S\5      r+S r,S r-g)    N)deepcopy)datetime	timedeltatimezone)environ)continue_trace)OP)Integration)_filter_headers)should_send_default_pii)TransactionSource)AnnotatedValuecapture_internal_exceptionsevent_from_exceptionloggerTimeoutThreadreraise)TYPE_CHECKINGg      ?g     @@)Any)TypeVar)Callable)Optional)EventProcessorEventHintF.)boundc                 F   ^  [         R                  " T 5      U 4S j5       nU$ )Nc           
      $  > [         R                  " 5       nUR                  [        5      nUc  T" X/UQ70 UD6$ [        R
                  " S5      nU(       d"  [        R                  " S5        T" X/UQ70 UD6$ [        U5      n[        R                  " [        R                  5      n[         R                  " 5        n[        5          UR                  5         UR!                  [#        XU5      5        UR%                  S[        R
                  " S5      5        S n	UR&                  (       a.  U[(        :  a$  U[(        -
  n
[+        X5      n	U	R-                  5         S S S 5        0 n[/        US5      (       a  UR0                  n[3        U[4        R6                  [        R
                  " SS5      [8        R:                  [        R<                  S9n[        R
                  " S5      [        R
                  " S	5      [        R
                  " S
5      [        R
                  " S5      [        R
                  " S5      S.US.n[         R>                  " XS9    T" X/UQ70 UD6W	(       a  U	RA                  5         URC                  5         sS S S 5        sS S S 5        $ ! , (       d  f       GND= f! [D         aP    [F        RH                  " 5       n[K        UURL                  SSS.S9u  nn[         RN                  " UUS9  [Q        U6    Of = f W	(       a  U	RA                  5         URC                  5         O,! W	(       a  U	RA                  5         URC                  5         f = f S S S 5        O! , (       d  f       O= fS S S 5        g ! , (       d  f       g = f)NFUNCTION_TIMEOUT_SECzOThe configured timeout could not be fetched from Cloud Functions configuration.
gcp_regionFUNCTION_REGIONheadersFUNCTION_NAME )opnamesourceoriginENTRY_POINTFUNCTION_IDENTITYGCP_PROJECT)function_namefunction_entry_pointfunction_identityfunction_regionfunction_project)gcp_env	gcp_event)custom_sampling_contextgcpF)typehandled)client_options	mechanism)hint))
sentry_sdk
get_clientget_integrationGcpIntegrationr   getr   debugintr   nowr   utcisolation_scoper   clear_breadcrumbsadd_event_processor_make_request_event_processorset_tagtimeout_warningTIMEOUT_WARNING_BUFFERr   starthasattrr#   r   r	   FUNCTION_GCPr   	COMPONENTr)   start_transactionstopflush	Exceptionsysexc_infor   optionscapture_eventr   )functionhandlerr3   argskwargsclientintegrationconfigured_timeinitial_timescopetimeout_threadwaiting_timer#   transactionsampling_contextrT   sentry_eventr:   funcs                    ^/home/kali/devsecops-assessor/venv/lib/python3.13/site-packages/sentry_sdk/integrations/gcp.pysentry_func_wrap_func.<locals>.sentry_func*   s    &&(,,^<DTDVDD!++&<=LLa DTDVDDo.||HLL1'')U,.'')))1!L
 lGKK8I,JK!%//'*@@#25K#KL%2<%QN #((*% /( Gy),,#++(??[["5(22%,,K &-[[%A,3KK,F)05H)I'.{{3D'E(/M(B '	  --#LTLVL &&++-LLN% U *)..\ ! '"||~H)= '-~~+0U"C*&L$
 ,,\EX&' '%&++-LLN &&++-LLNN%  U *))s{   >N	BJC6NM'J+'M'	N
J(	#N+ALL1LL1	(M'1)MM'	N'
M5	1N
N)	functoolswraps)rd   rf   s   ` re   
_wrap_funcrj   (   s)    __TO# O#b     c                   <    \ rS rSrSrS\ 3rSS jr\S 5       rSr	g)	r>      r5   zauto.function.c                     Xl         g )NrI   )selfrI   s     re   __init__GcpIntegration.__init__   s    .rk   c                      SS K n [        U S5      (       d  [        R                  " S5        g U R                  n[        UR                  R                  5      UR                  l        g )Nr   	worker_v1zFGcpIntegration currently supports only Python 3.7 runtime environment.)__main__rL   r   warningrt   rj   FunctionHandlerinvoke_user_function)gcp_functionsworker1s     re   
setup_onceGcpIntegration.setup_once   sU     	)}k22NNX ))7A##888
4rk   ro   N)F)
__name__
__module____qualname____firstlineno__
identifierr)   rq   staticmethodr{   __static_attributes__ rk   re   r>   r>      s,    Jj\*F/ 
 
rk   r>   c                    ^ ^^ UU U4S jnU$ )Nc                   > [         R                  " [        R                  5      nUT	-
  nU[	        SS9-  nU R                  S0 5      n[        R                  " S5      [        R                  " S5      [        R                  " S5      [        R                  " S5      [        R                  " S5      UTS	.US
'   S[        U5      0US'   U R                  S0 5      nSR                  [        R                  " S5      5      US'   [        TS5      (       a  TR                  US'   [        TS5      (       a  TR                  R                  S5      US'   [        TS5      (       a  [        TR                  5      US'   [!        5       (       a!  [        TS5      (       a  TR"                  US'   O)[        TS5      (       a  [$        R&                  " 5       US'   [)        U5      U S'   U $ )N   )millisecondsextrar$   r*   r+   r"   r,   )r-   r.   r/   r0   r1   execution_duration_in_millisconfigured_timeout_in_secondszgoogle cloud functionsurlzgoogle cloud logsrequestz	gcp:///{}methodquery_stringzutf-8r#   data)r   rB   r   rC   r   
setdefaultr   r?   _get_google_cloud_logs_urlformatrL   r   r   decoder   r#   r   r   r   removed_because_raw_datar   )
eventr:   
final_time	time_diffr   r   r   configured_timeoutr3   r]   s
          re   event_processor6_make_request_event_processor.<locals>.event_processor   s    \\(,,/
-	'09!3L'L$  "-$[[9$+KK$>!(-@!A&{{+<= 'M :,H-?+
&' -j9&
!" ))Ir*$++GKK,HI9h'' ) 0 0GH9n--&/&<&<&C&CG&LGN#9i((!01B1B!CGI"$$y&))"+..y&)) #1"I"I"K#G,irk   r   )r3   r   r]   r   s   ``` re   rG   rG      s    /b rk   c           	          U [        SS9-
  nSnSR                  [        R                  " S5      [        R                  " S5      [        R                  " S5      U R	                  U5      UR	                  U5      S9nU$ )	z
Generates a Google Cloud Logs console URL based on the environment variables
Arguments:
    final_time {datetime} -- Final time
Returns:
    str -- Google Cloud Logs Console URL to logs.
r   )hoursz%Y-%m-%dT%H:%M:%SZaY  https://console.cloud.google.com/logs/viewer?project={project}&resource=cloud_function%2Ffunction_name%2F{function_name}%2Fregion%2F{region}&minLogLevel=0&expandAll=false&timestamp={timestamp_end}&customFacets=&limitCustomFacetWidth=true&dateRangeStart={timestamp_start}&dateRangeEnd={timestamp_end}&interval=PT1H&scrollTimestamp={timestamp_end}r,   r$   r"   )projectr-   regiontimestamp_endtimestamp_start)r   r   r   r?   strftime)r   hour_agoformatstringr   s       re   r   r      s{     IA..H'L	9
 fM*kk/2{{,- )),7 )),7    Jrk   ).rh   rS   copyr   r   r   r   osr   r;   sentry_sdk.apir   sentry_sdk.constsr	   sentry_sdk.integrationsr
   $sentry_sdk.integrations._wsgi_commonr   sentry_sdk.scoper   sentry_sdk.tracingr   sentry_sdk.utilsr   r   r   r   r   r   typingr   rJ   MILLIS_TO_SECONDSr   r   r   r   sentry_sdk._typesr   r   r   r   rj   r>   rG   r   r   rk   re   <module>r      s     
  2 2   )   / @ 4 0  !   ==8CH-.ATn
[ 
44nrk   