
    tni                         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%dZ* G d de          Z+	 	 	 	 	 	 	 	 d&d!Z,d"d#de-f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.)boundfuncreturnc                 \     t          j                   	 	 	 	 	 	 	 	 	 	 d fd            }|S )	Nfunctionhandlerr   	gcp_eventargskwargsr   c           
      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_envr"   )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   	COMPONENTr1   start_transactionstopflush	Exceptionsysexc_infor   optionscapture_eventr   )r!   r"   r#   r$   clientintegrationconfigured_timeinitial_timescopetimeout_threadwaiting_timer+   transactionsampling_contextr[   sentry_eventrA   r   s                    X/var/www/html/gpu-tools/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)
r!   r   r"   r   r#   r   r$   r   r   r   )	functoolswraps)r   ri   s   ` rh   
_wrap_funcrl   (   sr    _TU#U#+0U#9>U#JOU#	U# U# U# U# U# U#n     c                   F    e Zd ZdZde Zd	deddfdZed
d            ZdS )rE   r<   zauto.function.FrO   r   Nc                     || _         d S )N)rO   )selfrO   s     rh   __init__zGcpIntegration.__init__   s    .rm   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__rS   r   warningrs   rl   FunctionHandlerinvoke_user_function)gcp_functionsworker1s     rh   
setup_oncezGcpIntegration.setup_once   sj    ((((}k22 	NX   F)7A#88
 8
444rm   )F)r   N)	__name__
__module____qualname__
identifierr1   boolrq   staticmethodrz    rm   rh   rE   rE      sm        J*j**F/ / / / / / / 
 
 
 \
 
 
rm   rE   r"   r   configured_timeoutra   r   c                      d fd}|S )	Neventr   rA   r   r   Optional[Event]c                    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,   r2   r3   r(   r4   )r5   r6   r7   r8   r9   execution_duration_in_millisconfigured_timeout_in_secondszgoogle cloud functionsurlzgoogle cloud logsrequestz	gcp:///{}methodquery_stringzutf-8r+   data)r   rI   r   rJ   r   
setdefaultr   rF   _get_google_cloud_logs_urlformatrS   r   r   decoder   r+   r   r   r   removed_because_raw_datar   )
r   rA   
final_time	time_diffr   r   r   r   r"   ra   s
          rh   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rm   )r   r   rA   r   r   r   r   )r"   r   ra   r   s   ``` rh   rM   rM      s6    - - - - - - - -^ rm   r   r   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}r4   r,   r(   )projectr5   regiontimestamp_endtimestamp_start)r   r   r   rF   strftime)r   hour_agoformatstringr   s       rh   r   r      s     IA....H'L	9
 fM**k/22{,-- )),77 )),77     Jrm   )r   r   r   r   )r"   r   r   r   ra   r   r   r   )/rj   rZ   copyr   r   r   r   osr   rB   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   rP   MILLIS_TO_SECONDSr   r   r   r   sentry_sdk._typesr   r   r   r   rl   rE   rM   strr   r   rm   rh   <module>r      su       



       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 Yx
 
 
 
 
[ 
 
 
022*/2?D22 2 2 2j: #      rm   