
    fi!                     f   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r7d 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-dS )    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     t          j                    fd            }|S )Nc           
      P   t          j                    }|                    t                    }| | |g|R i |S t	          j        d          }|s!t          j        d            | |g|R i |S t          |          }t          j
        t          j                  }t          j                    5 }t                      5  |                                 |                    t#          |||                     |                    dt	          j        d                     d }	|j        rM|t(          k    rB|t(          z
  }
t+          |
||t          j                              }	|	                                 d d d            n# 1 swxY w Y   i }t1          |d          r|j        }t5          |t6          j        t	          j        dd          t:          j        t          j        	          }t	          j        d          t	          j        d
          t	          j        d          t	          j        d          t	          j        d          d|d}t          j         ||          5  	  | |g|R i ||	r|	!                                 |"                                 cd d d            cd d d            S # tF          $ rR tI          j%                    }tM          ||j'        ddd          \  }}t          j(        ||           tS          |  Y nw xY w	 |	r|	!                                 |"                                 n/# |	r|	!                                 |"                                 w xY w	 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NFUNCTION_TIMEOUT_SECzOThe configured timeout could not be fetched from Cloud Functions configuration.
gcp_regionFUNCTION_REGION)isolation_scopecurrent_scope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   utcr#   r   clear_breadcrumbsadd_event_processor_make_request_event_processorset_tagtimeout_warningTIMEOUT_WARNING_BUFFERr   get_current_scopestarthasattrr%   r   r	   FUNCTION_GCPr   	COMPONENTr+   start_transactionstopflush	Exceptionsysexc_infor   optionscapture_eventr   )functionhandlerr5   argskwargsclientintegrationconfigured_timeinitial_timescopetimeout_threadwaiting_timer%   transactionsampling_contextrV   sentry_eventr<   funcs                    k/var/www/html/Pagina-Ingenieria-Requisitos/venv/lib/python3.11/site-packages/sentry_sdk/integrations/gcp.pysentry_funcz_wrap_func.<locals>.sentry_func*   s    &((,,^<<4DTDDDVDDD!+&<== 	ELa   4DTDDDVDDDo..|HL11')) A	#U,.. + +'')))))1!?L   
 lGK8I,J,JKKK!%/+'*@@@#25K#KL%2$'(-&0&B&D&D	& & &N #((***/+ + + + + + + + + + + + + + +2 Gy),, ,#+(?["55(2%,  K &-[%A%A,3K,F,F)05H)I)I'.{3D'E'E(/M(B(B  '	  	  -5E   # ##4LTLLLVLL & .&++---LLNNN%# # # # # # #_A	# A	# A	# A	# A	# A	# A	# A	#h ! ' ' '"|~~H)= '-~+0U"C"C* * *&L$
 ,\EEEEX&&&&' '% .&++---LLNNNN & .&++---LLNNNNN%# # # # # # # # # # # # # # #_A	# A	# A	# A	# A	# A	# A	# A	# A	# A	# A	# A	# A	# A	# A	# A	# A	# A	#s   5NB7F;NF	NF	CN+N-J<9*N#N<ALMLM+N,M33N7NN	N
N	NN"N)	functoolswraps)rf   rh   s   ` rg   
_wrap_funcrk   (   s?    _TT# T# T# T# T#l     c                   :    e Zd ZdZde ZddZed             ZdS )r@   r7   zauto.function.Fc                     || _         d S )N)rJ   )selfrJ   s     rg   __init__zGcpIntegration.__init__   s    .rl   c                      dd l } t          | d          st          j        d           d S | j        }t          |j        j                  |j        _        d S )Nr   	worker_v1zFGcpIntegration currently supports only Python 3.7 runtime environment.)__main__rN   r   warningrr   rk   FunctionHandlerinvoke_user_function)gcp_functionsworker1s     rg   
setup_oncezGcpIntegration.setup_once   sl     	)(((}k22 	NX   F)7A#88
 8
444rl   N)F)__name__
__module____qualname__
identifierr+   rp   staticmethodry    rl   rg   r@   r@      sU        J*j**F/ / / / 
 
 \
 
 
rl   r@   c                       fd}|S )Nc                    t          j        t          j                  }|	z
  }|t	          d          z  }|                     di           }t          j        d          t          j        d          t          j        d          t          j        d          t          j        d          |d	|d
<   dt          |          i|d<   |                     di           }d	                    t          j        d                    |d<   t          d          r
j        |d<   t          d          rj                            d          |d<   t          d          rt          j                  |d<   t!                      rt          d          r
j        |d<   n&t          d          rt%          j                    |d<   t)          |          | d<   | S )N   )millisecondsextrar&   r,   r-   r"   r.   )r/   r0   r1   r2   r3   execution_duration_in_millisconfigured_timeout_in_secondszgoogle cloud functionsurlzgoogle cloud logsrequestz	gcp:///{}methodquery_stringzutf-8r%   data)r   rD   r   rE   r   
setdefaultr   rA   _get_google_cloud_logs_urlformatrN   r   r   decoder   r%   r   r   r   removed_because_raw_datar   )
eventr<   
final_time	time_diffr   r   r   configured_timeoutr5   r_   s
          rg   event_processorz6_make_request_event_processor.<locals>.event_processor   s    \(,//
-	'09!3L3L3L'L$  "--$[99$+K$>$>!(-@!A!A&{+<== 'M : :,H-?+
 +
&' -j99&
!" ))Ir**$++GK,H,HII9h'' 	1 ) 0GH9n-- 	M&/&<&C&CG&L&LGN#9i(( 	D!01B!C!CGI"$$ 	Ly&)) 1"+.y&)) L #1"I"K"K#G,,irl   r   )r5   r   r_   r   s   ``` rg   rH   rH      s1    / / / / / / /b rl   c           	         | t          d          z
  }d}d                    t          j        d          t          j        d          t          j        d          |                     |          |                    |                    }|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   rA   strftime)r   hour_agoformatstringr   s       rg   r   r      s     IA....H'L	9
 fM**k/22{,-- )),77 )),77     Jrl   ).ri   rU   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   rK   MILLIS_TO_SECONDSr   r   r   r   sentry_sdk._typesr   r   r   r   rk   r@   rH   r   r   rl   rg   <module>r      s7       



       2 2 2 2 2 2 2 2 2 2           ) ) ) ) ) )             / / / / / / @ @ @ @ @ @ 4 4 4 4 4 4 0 0 0 0 0 0                !              /==========8CH-...AY Y Yx
 
 
 
 
[ 
 
 
44 4 4n    rl   