
    lhR                      R   d dl Z d dlZd dlmZ d dlmZmZ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 d dlmZ d d	lmZ d d
lmZ d dlmZmZmZmZmZmZ d dlmZ dZdZ er1d dlm!Z! d dlm"Z" d dlm#Z# d dlm$Z$ d dl%m&Z&m'Z'm(Z(  e"de#de!f         Z)d Z* G d de      Z+d Z,d Z-y)    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                 B     t        j                          fd       }|S )Nc           
         t        j                         }|j                  t              }| | |g|i |S t	        j
                  d      }|s"t        j                  d        | |g|i |S t        |      }t        j                  t        j                        }t        j                         5 }t               5  |j                          |j!                  t#        |||             |j%                  dt	        j
                  d             d }	|j&                  r.|t(        kD  r%|t(        z
  }
t+        |
|      }	|	j-                          d d d        i }t/        |d      r|j0                  }t3        |t4        j6                  t	        j
                  dd      t8        j:                  t        j<                        }t	        j
                  d      t	        j
                  d	      t	        j
                  d
      t	        j
                  d      t	        j
                  d      d|d}t        j>                  ||      5  	  | |g|i |	r|	jA                          |jC                          cd d d        cd d d        S # 1 sw Y   6xY w# tD        $ rT tG        jH                         }tK        ||jL                  ddd      \  }}t        jN                  ||       tQ        |  Y nw xY w	 	r|	jA                          |jC                          n'# 	r|	jA                          |jC                          w xY w	 d d d        n# 1 sw Y   nxY wd d d        y # 1 sw Y   y xY w)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                    m/var/www/pru.catia.catastroantioquia-mas.com/tasa/lib/python3.12/site-packages/sentry_sdk/integrations/gcp.pysentry_funcz_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 '	  --5E ##LTLVL &&++-LLN%# #U<	# <	#+ +\ ! '"||~H)= '-~~+0U"C*&L$
 ,,\EX&' '%&++-LLN &&++-LLNN%# # #U<	# <	# <	#s{   5M BJC1M?MJ"M/	MJ	MAK,)L+K,,L0#M$L77M;	MM		MM")	functoolswraps)rd   rf   s   ` re   
_wrap_funcri   (   s)    __TO# O#b     c                   2    e Zd ZdZde ZddZed        Zy)r>   r5   zauto.function.c                     || _         y )N)rI   )selfrI   s     re   __init__zGcpIntegration.__init__   s
    .rj   c                      dd l } t        | d      st        j                  d       y | j                  }t        |j                  j                        |j                  _        y )Nr   	worker_v1zFGcpIntegration currently supports only Python 3.7 runtime environment.)__main__rL   r   warningrp   ri   FunctionHandlerinvoke_user_function)gcp_functionsworker1s     re   
setup_oncezGcpIntegration.setup_once   sR     	)}k2NNX ))7A##888
4rj   N)F)__name__
__module____qualname__
identifierr)   rn   staticmethodrw    rj   re   r>   r>      s,    Jj\*F/ 
 
rj   r>   c                       fd}|S )Nc                    t        j                  t        j                        }|	z
  }|t	        d      z  }| j                  di       }t        j                  d      t        j                  d      t        j                  d      t        j                  d      t        j                  d      |d	|d
<   dt        |      i|d<   | j                  di       }dj                  t        j                  d            |d<   t        d      rj                  |d<   t        d      rj                  j                  d      |d<   t        d      rt        j                        |d<   t!               rt        d      r3j"                  |d<   n#t        d      rt%        j&                         |d<   t)        |      | d<   | S )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_processorz6_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rj   r}   )r3   r   r]   r   s   ``` re   rG   rG      s    /b rj   c           	         | t        d      z
  }d}dj                  t        j                  d      t        j                  d      t        j                  d      | j	                  |      |j	                  |            }|S )	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    Jrj   ).rg   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   ri   r>   rG   r   r}   rj   re   <module>r      s     
  2 2   )   / @ 4 0  !   ==8CH-.ATn
[ 
44nrj   