Viewing File: /opt/hc_python/lib/python3.12/site-packages/sentry_sdk/integrations/__pycache__/gcp.cpython-312.pyc

�

_�*jH*���ddlZddlZddlmZddlmZmZmZddlmZddl	m
Z
ddlZddlm
Z
ddlmZddlmZdd	lmZdd
lmZddlmZmZddlmZdd
lmZddlmZddlm Z m!Z!m"Z"m#Z#m$Z$m%Z%dZ&dZ'e
r%ddl	m(Z(m)Z)m*Z*m+Z+ddl,m-Z-m.Z.m/Z/e+de)de(f��Z0dd�Z1Gd�de�Z2								d d�Z3ddde4fd�Z5y)!�N)�deepcopy)�datetime�	timedelta�timezone)�environ)�
TYPE_CHECKING)�continue_trace)�OP)�Integration)�_filter_headers)�CLOUD_PROVIDER)�Scope�should_send_default_pii)�
SegmentSource)�TransactionSource)�has_span_streaming_enabled)�AnnotatedValue�
TimeoutThread�capture_internal_exceptions�event_from_exception�logger�reraiseg�?g@�@)�Any�Callable�Optional�TypeVar)�Event�EventProcessor�Hint�F.)�bound�returnc�X��tj��										d�fd��}|S)Nc�
��tj�}|jt�}|�
�||g|��i|��St	j
d�}|s"t
jd��||g|��i|��St|�}tjtj�}tj�5}t�5|j�|j!t#|||��|j%dt	j
d��d}	|j&rC|t(kDr:|t(z
}
t+|
||tj,���}	|	j/�ddd�i}i}t1|d�rE|j2}t5|d��j7�D]\}
}||d	|
j9���<�i}t1|d
�r|j:|d<t=�r,t1|d�r |j>jAd
d��|d<t	j
d�t	j
d�t	j
d�t	j
d�t	j
d�d�|d�}t	j
dd�}t	j
d�rt	j
d�|d<t	j
d�rt	j
d�|d<t	j
d�rt	j
d�|d<tC|jD�r�tjFjI|�tKjL|�tjFjO|dtPjRtjTtVjXtZj\|d�|�|���}netI|tPjRt	j
dd�t^jXtjT��}tj`||��}|5	�||g|��i|��	r|	jc�|je�cddd�cddd�S#1swY��xYw#tf$rTtijj�}tm||jDd dd!��"�\}}tjn||�#�tq|�YnwxYw		r|	jc�|je�n'#	r|	jc�|je�wxYw	ddd�n#1swYnxYwddd�y#1swYyxYw)$N�FUNCTION_TIMEOUT_SECzOThe configured timeout could not be fetched from Cloud Functions configuration.�
gcp_region�FUNCTION_REGION)�isolation_scope�
current_scope�headersF)�use_annotated_valuezhttp.request.header.�methodzhttp.request.method�query_string�utf-8�replace��errorsz	url.query�
FUNCTION_NAME�ENTRY_POINT�FUNCTION_IDENTITY�GCP_PROJECT)�
function_name�function_entry_point�function_identity�function_region�function_project)�gcp_env�	gcp_eventz<unknown GCP function>zgcp.project.idz
faas.identityzfaas.entry_point)z	sentry.opz
sentry.originzsentry.span.sourcezcloud.providerz	faas.name)�name�parent_span�
attributes�)�opr=�source�origin)�custom_sampling_context�gcp)�type�handled)�client_options�	mechanism)�hint)9�
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�items�lowerr,rr-�decoder�options�tracesr	r�set_custom_sampling_context�
start_spanr
�FUNCTION_GCPrCr�	COMPONENTr
�GCPr�start_transaction�stop�flush�	Exception�sys�exc_infor�
capture_eventr)�functionhandlerr<�args�kwargs�client�integration�configured_time�initial_time�scope�timeout_thread�waiting_timer*�header_attributes�header�header_value�additional_attributes�sampling_contextr6�span_ctx�transactionrl�sentry_eventrJ�funcs                       ��J/opt/hc_python/lib/python3.12/site-packages/sentry_sdk/integrations/gcp.py�sentry_funcz_wrap_func.<locals>.sentry_func(s�����&�&�(���,�,�^�<�������D�T�D�V�D�D�!�+�+�&<�=����L�L�a�
����D�T�D�V�D�D��o�.���|�|�H�L�L�1��
�
'�
'�
)�U�,�.��'�'�)��)�)�1�!�?�L���
�
�
�l�G�K�K�8I�,J�K�!%���/�/�'�*@�@�#2�5K�#K�L�%2�$�'�(-�&0�&B�&B�&D�	&�N�#�(�(�*�//�2�G�24���y�)�,�#�+�+��,;���-��%�'�-�(�F�L�
%�&�(<�V�\�\�^�<L�&M�N�-�%'�!��y�(�+�?H�?O�?O�%�&;�<�&�(�W�Y��-O�5>�5K�5K�5R�5R��I�6S�6�%�k�2�&-�[�[��%A�,3�K�K�
�,F�)0���5H�)I�'.�{�{�3D�'E�(/���M�(B��'�	 ��$�K�K��9Q�R�M��{�{�=�)�:A�+�+�m�:T�%�&6�7��{�{�.�/�9@���'�:�%�o�6��{�{�=�)�<C�K�K�
�<V�%�&8�9�)�&�.�.�9��!�!�0�0��9��1�1�2B�C�%�,�,�7�7�&� $�%'�_�_�)7�)>�)>�.;�.E�.E�*8�*<�*<�%2� �,�
 �0� �8���-����� ���_�b�9�,�6�6�)�0�0���&�7�7��9I����#����L�T�L�V�L�&�&�+�+�-��L�L�N�!��I*�
)�.�.��L!�'�"�|�|�~�H�)=� �'-�~�~�+0�U�"C�*�&�L�$�
�,�,�\��E��X�&�'��'�%�&�+�+�-��L�L�N��&�&�+�+�-��L�L�N��N�!����I*�
)�
)�s{�5U	�B#Q2�#KU	�/T4�1Q?�="T4�	U	�2Q<	�7U	�?AS�T�S�T� #T4�$T'�'T4�+	U	�4T=	�9U	�	U)
rnrr<rrorrprr"r)�	functools�wraps)r�r�s` r��
_wrap_funcr�'sV����_�_�T��H#��H#�+0�H#�9>�H#�JO�H#�	�H#��H#�T��c�>�eZdZdZde��Zddeddfd�Zed	d��Zy)
rNrEzauto.function.rXr"Nc��||_y)N)rX)�selfrXs  r��__init__zGcpIntegration.__init__�s
��.��r�c���ddl}t|d�stjd�y|j}t|jj�|j_y)Nr�	worker_v1zFGcpIntegration currently supports only Python 3.7 runtime environment.)�__main__r\r�warningr�r��FunctionHandler�invoke_user_function)�
gcp_functions�worker1s  r��
setup_oncezGcpIntegration.setup_once�sP��(��}�k�2��N�N�X�
�
��)�)��7A��#�#�8�8�8
����4r�)F)r"N)	�__name__�
__module__�__qualname__�
identifierrC�boolr��staticmethodr��r�r�rNrN�s:���J��j�\�
*�F�/��/��/��

��

r�rNc�����d���fd�}|S)Nc���tjtj�}|�	z
}|t	d��z}|jdi�}t
jd�t
jd�t
jd�t
jd�t
jd�|�d	�|d
<dt|�i|d<|jd
i�}djt
jd��|d<t�d�r�j|d<t�d�r �jjdd��|d<t�d�rt�j�|d<t!�rt�d�r3�j"|d<n#t�d�rt%j&�|d<t)|�|d
<|S)N�)�milliseconds�extrar2r3r4r'r5)r6r7r8r9r:�execution_duration_in_millis�configured_timeout_in_secondszgoogle cloud functions�urlzgoogle cloud logs�requestz	gcp:///{}r,r-r.r/r0r*�data)rrRrrSr�
setdefaultrrO�_get_google_cloud_logs_url�formatr\r,r-r_rr*rr�r�removed_because_raw_datar)
�eventrJ�
final_time�	time_diffr�r�r��configured_timeoutr<rts
       ���r��event_processorz6_make_request_event_processor.<locals>.event_processor�s�����\�\�(�,�,�/�
���-�	�'0�9�!�3L�'L�$�� � ��"�-��$�[�[��9�$+�K�K�
�$>�!(���-@�!A�&�{�{�+<�=� '���M� :�,H�-?�+
��&�'�
�-�j�9�&
��!�"��)�)�I�r�*��$�+�+�G�K�K��,H�I�����9�h�'� )� 0� 0�G�H���9�n�-�&/�&<�&<�&C�&C��	�'D�'�G�N�#��9�i�(�!0��1B�1B�!C�G�I��"�$��y�&�)�"+�.�.�����y�&�)�#1�"I�"I�"K����#�G�,��i���r�)r�rrJrr"zOptional[Event]r�)r<r�rtr�s``` r�rVrV�s���/�b�r�r�rc	��|td��z
}d}djtjd�tjd�tjd�|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:%SZaYhttps://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}r5r2r')�projectr6�region�
timestamp_end�timestamp_start)rr�rrO�strftime)r��hour_ago�formatstringr�s    r�r�r�s{���I�A�.�.�H�'�L�	9�

�f����M�*��k�k�/�2��{�{�,�-� �)�)�,�7� �)�)�,�7�
��
��Jr�)r�r r"r )r<rr�rrtrr"r)6r�rk�copyrrrr�osr�typingrrK�sentry_sdk.apir	�sentry_sdk.constsr
�sentry_sdk.integrationsr�$sentry_sdk.integrations._wsgi_commonr�.sentry_sdk.integrations.cloud_resource_contextr
�sentry_sdk.scoperr�sentry_sdk.tracesr�sentry_sdk.tracingr�sentry_sdk.tracing_utilsr�sentry_sdk.utilsrrrrrrrY�MILLIS_TO_SECONDSrrrr�sentry_sdk._typesrrrr r�rNrV�strr�r�r�r��<module>r�s����
��2�2�� ��)� �/�@�I�;�+�0�?��������7�7�=�=���8�C��H�-�.�A�L�^
�[�
�04��4�*/�4�?D�4��4�n�:��#�r�
Back to Directory File Manager