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

�

_�*j���\
�UddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlmZddlmZmZddlmZddlmZmZmZddlmZddlmZmZmZm Z m!Z!	dd	l"m#Z#dd
l%m&Z&ddl'Z'ddl(m)Z)ddl*m+Z+m,Z,m-Z-dd
l.m/Z/m0Z0m1Z1e&rXddl2m3Z3m4Z4ddl%m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEddlFmGZGddl*mHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOe>d�ZPeBd�ZQeddd�ZRej�d�ZTdaUej�dd��ZWeX�ZYdeZd<de[fd�Z\ed�d��Z]e	j�d�Z_e`d �Zae`d!�Zbd"Zc	dd#�d�d&�Zdd'd%deefd(�Zfd�d*�Zgd�d+�Zhd,d-deifd.�ZjGd/�d0�Zkek�Zld�d1�Zmd�d2�Znd$d3deofd4�Zpd$d3deifd5�Zqe`d6�Zrd$eidd3fd7�Zs	d�			d�d8�ZtGd9�d:eu�ZvGd;�d<�ZwGd=�d>�Zxd�d@�Zyd�dA�ZzdBdCde[fdD�Z{d�dG�Z|			d�dHeidIe}dJdKdLdMdNd)ddOfdP�Z~	d�							d�dS�Zd$d%deifdT�Z�d$d%deifdU�Z�						d�dW�Z�					d�dBdCdQdKdXe[dYe[dRdKdZd[dd\fd]�Z�			d�dXe[dYe[dRdKdd\fd^�Z�d_e�ddMfd`�Z�d_dadeifdb�Z�						d�																			d�dl�Z�e�e�dm�Z�e�rd�dn�Z�nd�do�Z�								d�dcd?d_dadEdFdddedfdedge}dhe}did)djdkdpdqdrdsddtfdu�Z�			d�									d�dv�Z�d$eideifdw�Z�d�dx�Z�d�dy�Z�			d�									d�d|�Z�	d�									d�d}�Z�d�d~�Z�								d�d�Z�		d�							d�d��Z�d�d)d�dzde[fd��Z�dVd)de[fd��Z�dVd)d{d)de[fd��Z�d�eid�e}deifd��Z�d$eiddKfd��Z�	d�d$eidJdKdd�fd��Z�d�eidd�fd��Z�de[fd��Z�d�e�de�fd��Z�d�d��Z�e��\Z�ZVd�Z�d�d��Z�d�d��Z�eVd��Z�Gd��d�e��Z�Gd��d�e�jP�Z�d�eidd)fd��Z�d�eidd)fd��Z�ed�gd���Z�			d�d�eid�e[d�e[d�e[dd�f
d��Z�ed�gd���Z�d�d�eid�e[dd�fd��Z�d�d%dieide[fd��Z�		d�d�eid�dzd�e[de[fd��Z�d�d�d�eide[fd��Z�d�d��Z�d�eideifd��Z�d�eideifd��Z�d�d��Z�d�eidd�fd��Z�	d�							d�d��Z�d�d��Z�e&reE						d�d���Z�eE				d�d���Z�e�f					d�d��Z�e)rde}fd��Z�nde}fd��Z�deofd��Z�	dd�l�m�Z�dd�l�m�Z�de[fdDŽZ�	d�			�ddȄZ�				�ddɄZ�d�d%d$d%de[fd˄Z�e&reBd̫ZƐdd̈́Z�d'd%deifd΄Z�d�d�de[fdфZ�				�dd҄Z�d�d�de[fdӄZ�				�ddԄZ�				�ddՄZ͐ddքZΐddׄZ�y#e$$rdZ#Y���wxYw#e$$rd�dĄZ�d�eide[fdƄZ�Y��wxYw(�N)�
namedtuple)�contextmanager)�datetime�timezone)�Decimal)�partial�
partialmethod�wraps)�Real)�parse_qs�unquote�	urlencode�urlsplit�
urlunsplit)�BaseExceptionGroup)�
TYPE_CHECKING)�PY37)�SENSITIVE_DATA_SUBSTITUTE�	Annotated�AnnotatedValue)�DEFAULT_ADD_FULL_STACK�DEFAULT_MAX_STACK_FRAMES�EndpointType)�	FrameType�
TracebackType)�Any�Callable�ContextManager�Dict�	Generator�Iterator�List�NoReturn�Optional�	ParamSpec�Set�Tuple�Type�TypeVar�Union�cast�overload)�Hub)�AttributeValue�Event�ExcInfo�Hint�Log�Metric�SerializedAttributeValue�SpanJSON�P�Ri��zsentry_sdk.errors�is_sentry_internal_taskF��defaultz	set[type]�_control_flow_exception_classes�returnc�*�tj�S�N)�_is_sentry_internal_task�get���?/opt/hc_python/lib/python3.12/site-packages/sentry_sdk/utils.py�is_internal_taskrE`s��#�'�'�)�)rCc#�K�tjd�}	d��tj|�y#tj|�wxYw�w)z2Context manager to mark a task as Sentry internal.TN)r@�set�reset)�tokens rD�mark_sentry_task_internalrJds=����
%�(�(��.�E�.�
� �&�&�u�-�� �&�&�u�-�s�A
�3�A
�A
�
A
z^[a-zA-Z0-9/+=]*$)�false�f�n�no�off�0)�true�t�y�yes�on�1i�)�strict�valuerc�~�|�t|�j�nd}|tvry|tvry|rdSt	|�S)z�Casts an ENV variable value to boolean using the constants defined above.
    In strict mode, it may return None if the value doesn't match any of the predefined values.
    NFT)�str�lower�FALSY_ENV_VALUES�TRUTHY_ENV_VALUES�bool)rXrW�
normalizeds   rD�env_to_boolr`}sF��(-�'8��U��!�!�#�d�J��%�%���&�&���4�*�t�E�{�*rC�datac�P�tj|dd��jd�S)zCSerialize data into a compact JSON representation encoded as UTF-8.F)�,�:)�	allow_nan�
separators�utf-8)�json�dumps�encode)ras rD�
json_dumpsrk�s ���:�:�d�e�
�C�J�J�7�S�SrC�
Optional[str]c��	ttjjd�5}d}tj
dk(stj
dk(r7t
j�}|xjtjzc_t
jgd�|tj||��j�dj�jd�}ddd�|S#1swYSxYw#tt t"f$rYywxYw)Nzw+�win32�cygwin)�gitz	rev-parse�HEAD)�startupinfo�stdout�stderr�stdinrrg)�open�os�path�devnull�sys�platform�
subprocess�STARTUPINFO�dwFlags�STARTF_USESHOWWINDOW�Popen�PIPE�communicate�strip�decode�OSError�IOError�FileNotFoundError)�nullrr�revisions   rD�get_git_revisionr��s����
�"�'�'�/�/�4�
(�D��K��|�|�w�&�#�,�,�(�*B�(�4�4�6���#�#�z�'F�'F�F�#�� � �0� +�%�?�?�������q�"��������
�)�,�O�-)�,�O��
�W�/�0����s/�$C5�B8C(�C5�(C2�-C5�2C5�5D�Dc��tjjd�}|r|St�}|r|SdD]'}tjj|�}|s�%|cSy)zTry to guess a default release.�SENTRY_RELEASE)�HEROKU_BUILD_COMMIT�HEROKU_SLUG_COMMIT�SOURCE_VERSION�!CODEBUILD_RESOLVED_SOURCE_VERSION�CIRCLE_SHA1�GAE_DEPLOYMENT_ID�
K_REVISIONN)rw�environrAr�)�release�vars  rD�get_default_releaser��sZ���j�j�n�n�-�.�G����� �G�������*�*�.�.��%����N��rC�installed_integrationsz	List[str]c�H�gd�}|D]}||vs�dj|�cSy)zAReturn the SDK name including the name of the used web framework.)�django�flask�fastapi�bottle�falcon�quart�sanic�	starlette�litestar�starlite�chalice�
serverless�pyramid�tornado�aiohttp�
aws_lambda�gcp�beam�asgi�wsgizsentry.python.{}z
sentry.python)�format)r��framework_integrations�integrations   rD�get_sdk_namer��s5��
��..���0�0�%�,�,�[�9�9�.�rCc�0�eZdZdZdd�Zdddddd	defd
�Zy)
�CaptureInternalExceptionrBr=c��|Sr?rB��selfs rD�	__enter__z"CaptureInternalException.__enter__�s���rC�ty�Optional[Type[BaseException]]rX�Optional[BaseException]�tb�Optional[TracebackType]c�(�|�|�t|||f�y)NT)�capture_internal_exception)r�r�rXr�s    rD�__exit__z!CaptureInternalException.__exit__�s���>�e�/�&��E�2��7�rCN�r=zContextManager[Any])�__name__�
__module__�__qualname__�	__slots__r�r^r�rBrCrDr�r��s7���I��	�+�	�)�	�
&�		�

�	rCr�c��tSr?)�_CAPTURE_INTERNAL_EXCEPTIONrBrCrD�capture_internal_exceptionsr��s��&�&rCc�x�tj�j�rtj	d|��yy)z�
    Capture an exception that is likely caused by a bug in the SDK
    itself.

    These exceptions do not end up in Sentry and are just logged instead.
    zInternal error in sentry_sdk��exc_infoN)�
sentry_sdk�
get_client�	is_active�logger�errorr�s rDr�r�s/������(�(�*����3�h��G�+rCrc�0�|tz
j�Sr?)�epoch�
total_seconds�rXs rD�to_timestampr�s���E�M�(�(�*�*rCc�b�|jtj�}|jd�S)z�Formats a timestamp in RFC 3339 format.

    Any datetime objects with a non-UTC timezone are converted to UTC, so that all timestamps are formatted in UTC.
    z%Y-%m-%dT%H:%M:%S.%fZ)�
astimezoner�utc�strftime)rX�utctimes  rD�format_timestampr�s,��
���x�|�|�,�G����3�4�4rC)�+�-c�\�	tj|�}|jtj�S#ttf$rfd|vrdnd}|j	d�r|dddz}|dt
vr|dz
}|dd	|d
dz}n|dt
vr|dz
}tj||�}Y��wxYw)N�.z%Y-%m-%dT%H:%M:%S.%fz%Y-%m-%dT%H:%M:%S�Z���z+0000i����z%z���������)
r�
fromisoformat�AttributeError�
ValueError�endswith�ISO_TZ_SEPARATORS�strptimer�rr�)rX�result�timestamp_formats   rD�datetime_from_isoformatr�s���<��'�'��.�� ���X�\�\�*�*��
�J�'�<�'*�U�l�"�8K�	��>�>�#���#�2�J��(�E���9�)�)���$���#�2�J��r�s��+�E�
�2�Y�+�
+���$���"�"�5�*:�;��<�s�6�A2B+�*B+c�\�|�tj�}nt|�}|d�d}d|iS)z+Creates a hint with the exc info filled in.Nrr�)rzr��exc_info_from_errorr�s rD�event_hint_with_exc_infor�4s9�����<�<�>��&�x�0����{������!�!rCc��eZdZdZy)�BadDsnzRaised on invalid DSNs.N�r�r�r��__doc__rBrCrDr�r�As��!rCr�c�v�eZdZdZej
d�Z	d						d
d�Zede	fd��Z
d	dd�Zde	fd�Zy)�DsnzRepresents a DSN.z	^o(\d+)\.Nr=c���t|t�rt|j�|_yt	t|��}|jdvrtd|jz��|j|_|j�td��|j|_	|�||_
nCtjj|j�}|r|jd�nd|_
|j�|jdk(xrdxsd|_n|j|_|jstd��|j|_|j"|_|j&j)d	d�}	tt+|j-���|_d	j5|�d	z|_y#t0t2f$r td
|j&xsdddz��wxYw)N)�http�httpszUnsupported scheme %rzMissing hostnamer8r���PzMissing public key�/zInvalid project in DSN (%r)�)�
isinstancer��dict�__dict__rrZ�schemer��hostname�host�org_id�ORG_ID_REGEX�match�group�port�username�
public_key�password�
secret_keyrx�rsplit�int�pop�
project_idr��	TypeError�join)r�rXr�parts�org_id_matchrxs      rD�__init__zDsn.__init__Js����e�S�!� ����0�D�M����U��$���<�<�0�0��0�5�<�<�?�@�@��l�l����>�>�!��+�,�,��N�N��	���+1�D�K��+�+�1�1�$�)�)�<�L�3?�,�,�,�Q�/�T�D�K��:�:��!�[�[�G�3�;��A�r�D�I��
�
�D�I��~�~��-�.�.��.�.����.�.����z�z� � ��a�(��	Q�!�#�d�h�h�j�/�2�D�O��H�H�T�N�S�(��	���I�&�	Q��6�%�*�*�:J��A�B�9O�O�P�P�	Q�s�<'F=�=/G,c�t�|j}|j|jfdvr|�d|j��}|S)zThe netloc part of a DSN.))r�r�)r�r�rd)rrr�r��rvs  rD�netlocz
Dsn.netlocus6���Y�Y���K�K����#�+I�I���	�	�*�B��	rCc	��t|j|j|j|j|j
|j|��S)z*Returns the auth info object for this dsn.)rrrxrr	r�client)�Authrrrxrr	r)r�rs  rD�to_authzDsn.to_auth}s<����;�;�����������������
�	
rCc���|j�d|j�|jxrd|jzxsd�d|j�|j�|j
��S)N�://�@r�)rr	rrrxrr�s rD�__str__zDsn.__str__�sL���K�K��O�O��O�O�5��d�o�o� 5�;��;��K�K��I�I��O�O�

�	
rCr?)rXzUnion[Dsn, str]rrlr=N)r�
Optional[Any]r=r)
r�r�r�r��re�compilerr�propertyrZrrr rBrCrDr�r�Esf����2�:�:�l�+�L�CG�))�&�))�0?�))�	
�))�V������

�
��
rCr�c�z�eZdZdZ				ddededededdd	ed
dded
dfd�Zejfddd
efd�Z	d
efd�Z
y)rz,Helper object that represents the auth info.Nrrrr	rrl�versionrr!rxr=c	�t�||_||_||_||_||_||_||_||_yr?)rrrxrr	rr&r)	r�rrrr	rr&rrxs	         rDrz
Auth.__init__�s<�������	���	�$���$���$��������rC�typerc	��|j�d|j�|j�d|j�d|j�d�	S)z'Returns the API url for storing events.rzapi/r�)rrrxrrX)r�r(s  rD�get_api_urlzAuth.get_api_url�s1��
�K�K��I�I��I�I��O�O��J�J�
�	
rCc��d|jfd|jfg}|j�|jd|jf�|j�|jd|jf�ddjd�|D��zS)z!Returns the auth header a string.�
sentry_key�sentry_version�
sentry_client�
sentry_secretzSentry z, c3�0K�|]\}}|�d|�����y�w)�=NrB)�.0�keyrXs   rD�	<genexpr>z!Auth.to_header.<locals>.<genexpr>�s����$Q�b�
��U��U�%;�b�s�)r	r&r�appendrrrs  rD�	to_headerzAuth.to_header�sw���T�_�_�-�0@�$�,�,�/O�
P���;�;�"��I�I�����4�5��?�?�&��I�I�����8�9��4�9�9�$Q�b�$Q�Q�Q�QrC)N�Nr�)r�r�r�r�rZr
rr�ENVELOPEr*r6rBrCrDrr�s���6�'+��"&��������	�
��$�
��� ����
��, ,�4�4�
��
�

�
�R�3�RrCr�Optional[type]c�:�t|dd�xs
t|dd�S)Nr�r���getattr)�clss rD�
get_type_namer>�s���3���-�O���j�$�1O�OrCc�*�t|dd�}|dvr|Sy)Nr�)N�builtins�__builtins__r;)r=�mods  rD�get_type_modulerC�s!��
�#�|�T�
*�C�
�4�4��
�rC�framerc���	|jd}|jd�ry	dD]}	|j|ry�y#ttf$rY�+wxYw#t
$rY�8wxYw)Nr�zsentry_sdk.T)�__traceback_hide__�__tracebackhide__F)�	f_globals�
startswithr��KeyError�f_locals�	Exception)rDrB�	flag_names   rD�should_hide_framerN�s��
��o�o�j�)���>�>�-�(��)�
?�	�	��~�~�i�(��)�?���
�H�%�
��
���	��	�s � >�A�A�A�	A�Ar�r�c#�fK�|}|�)t|j�s|��|j}|��(yy�wr?)rN�tb_frame�tb_next)r��tb_s  rD�iter_stacksrS�s1����%'�C�

�/� ����.��I��k�k���/�s�,1�1�filename�lineno�
max_length�
Optional[int]�loaderr!�module�KTuple[List[Annotated[str]], Optional[Annotated[str]], List[Annotated[str]]]c��d}d}|�0t|d�r$	|j|�}|�|j	�}|�	tj|�}|sgdgfStd||z
�}t|dz|zt|��}		|||D�
cgc]}
t|
jd�|���� }}
t||jd�|��}||dz|	D�
cgc]}
t|
jd�|���� }
}
|||
fS#ttf$rd}Y��wxYw#ttf$rgdgfcYSwxYwcc}
wcc}
w#t$rgdgfcYSwxYw)N��
get_sourcerr8z
)rV)�hasattrr]�ImportErrorr��
splitlines�	linecache�getlinesr��max�min�len�strip_stringr��
IndexError)rTrUrVrXrY�
context_lines�source�
source_str�lower_bound�upper_bound�line�pre_context�context_line�post_contexts              rD�get_lines_from_filerq�s����M�
�F�
��g�f�l�;�	�*0�*;�*;�F�*C�J��!��*�*�,�F�
�~�	 ��'�'��1�F���4��|���a��-�/�0�K��f�q�j�=�0�#�f�+�>�K�
��{�6�2�
�2��
����F�+�
�C�2�	�
�$�F�6�N�$8�$8��$@�Z�X�����
�k�:�
�:��
����F�+�
�C�:�	�
��L�,�6�6��7�W�%�	��J�	����!�	 ��t�R�<��	 ��
��

��
���4��|���sR�D�D�D;�#D1�++D;�#D6�9D;�D�D�D.�-D.�1
D;�;E�E�	tb_lineno�max_value_lengthc��	|jj}	|jd}	|jd}|�|r|dz
}t	|||||��SgdgfS#t$rd}Y�KwxYw#t$rgdgfcYSwxYw#t$rd}Y�PwxYw)Nr��
__loader__r8)rXrY)�f_code�co_filenamerLrHrq)rDrrrs�abs_pathrYrXrUs       rD�get_source_contextrys���
�$)�L�L�$<�$<�������,�������.������Q���"��f�.�v�f�
�	
��t�R�<���#���������4��|���������s3�A�A'�A;�A$�#A$�'A8�7A8�;B	�B	c�N�	t|�S#t$rt|�cYSwxYwr?)rZrL�	safe_reprr�s rD�safe_strr|/s+�� ��5�z���� ����� �s�

�$�$c�8�	t|�S#t$rYywxYw)Nz
<broken repr>)�reprrLr�s rDr{r{6s#����E�{�������s�

�	�rxc��|r|s|S	|jd�r|dd}|jdd�d}||k(rtjj	|�St
j|j}|s|S|j|jtjd�dd�djtj�S#t$r|cYSwxYw)Nz.pycr�r�r8r�)r��splitrwrx�basenamerz�modules�__file__r�sep�lstriprL)rYrx�base_module�base_module_paths    rD�filename_for_moduler�=s����6�������V�$����}�H��l�l�3��*�1�-���&� ��7�7�#�#�H�-�-��;�;�{�3�<�<����O��~�~�.�5�5�b�f�f�a�@��C�Q�G��K�R�R��F�F�
�	
�������s�AC� C�8AC�C�C�include_local_variables�include_source_context�custom_reprz&Optional[Callable[..., Optional[str]]]�Dict[str, Any]c��t|dd�}|sd}d}n,|jj}|jj}	|jd}	|�|j}	|rtjj|�nd}
t|	|�xsd|
|xsd|	|d�}|rt|||�\|d<|d<|d<|r'dd	lm
}|t|j�d
|��|d<|S#t
$rd}	Y��wxYw#t
$rd}
Y�wxYw)
Nrvr�z	<unknown>)rTrx�functionrYrUrnrorpr)�	serializeT)�is_varsr��vars)r<rvrw�co_namerHrL�f_linenorwrx�abspathr�ry�sentry_sdk.serializerr�r�rK)
rDrrr�r�rsr�rvrxr�rY�os_abs_pathrr�s
             rD�serialize_framer�Vs+���U�H�d�
+�F�������<�<�+�+���<�<�'�'�������,�����N�N�	��3;�b�g�g�o�o�h�/���
(���9�A�T���+�����B��DV��9�.�E
�A��=��2�n�-�r�.�/A��3������ �$�K�
��6�
��I��?�����������s$�C$� #C5�$C2�1C2�5D�Dc���d}g}tj�}|�8t|�s|jt	||||���|j
}|��8|j
�d|iS)NT)r�r�rs�frames)rz�	_getframerNr5r��f_back�reverse)r�r�rsrGr�rLs      rD�current_stacktracer��sp��
��
�F�"�}�}��A�
�-� ��#��M�M���,C�+A�%5�	�
�
�H�H���-��N�N���f��rC�	exc_valuec��t|dd�S)N�errnor;)r�s rD�	get_errnor��s���9�g�t�,�,rCr�c��tt|dd�xst|dd�xst|��}t|dd�}t|t�r,t	|�dkDr|ddjd�|D��zz
}|S)N�messager��detail�	__notes__r�
c3�BK�|]}t|t�s�|���y�wr?)r�rZ)r2�notes  rDr4z$get_error_message.<locals>.<genexpr>�s����#T�U�T�j��s�>S�D�U�s��)r|r<r��listrer)r�r��notess   rD�get_error_messager��s}����	�9�b�)�	��9�h��+�	��I���G��I�{�D�9�E��%���3�u�:��>��4�$�)�)�#T�U�#T�T�T�T���NrC�exc_type�client_options�Optional[Dict[str, Any]]�	mechanism�exception_id�	parent_idri�
full_stack�Optional[list[dict[str, Any]]]c	��i}	|r|j�nddd�|	d<|�||	dd<|�t|�}
nd}
|
�5|	djdi�jdi�jd	|
�|�||	dd
<|dk(}|s|�||	dd<d
|	dd<|rd|	dvrd|	dd<tduxrt	|t�}|rd|	dd<t|�|	d<t
|�|	d<t|�|	d<|�	d}
d}d}d}n |d}
|d}|d}|jd�}tt|�ttdz��D��cgc]*\}}t|j|j|
|||����,}}}t!|�tkDrt#j$d��|	d<|	S|r|s|}n
t'|||�}d|i|	d<|	Scc}}w)z�
    Creates a dict that goes into the events `exception.values` list and is ingestible by Sentry.

    See the Exception Interface documentation for more details:
    https://develop.sentry.dev/sdk/event-payloads/exception/
    �genericT�r(�handledr�Nr��metar��numberrirr��chainedr(�is_exception_grouprYrXr�r�rsr�r8)rrr�r�rsr�r��
stacktracer�)�copyr��
setdefaultrr�rCr>r�rA�ziprS�range�MAX_STACK_FRAMESr�rPrrrer�removed_because_over_size_limit�merge_stack_frames)r�r�r�r�r�r�r�rir��exception_valuer��is_root_exceptionr�r�r�rsr��_r��
new_framess                    rD�!single_exception_from_error_tupler��se��")+�O�%�	����I�$�+O��K� ���7C���$�^�4����)�$��������$�/�/���;�F�F��R�	
�
�*�X�u�
%�
��17���$�X�.�$��)����!6�4=���$�[�1�/8���$�V�,��V�?�;�+G�G�/8���$�V�,�+�4�7��J��%�=���=A���$�%9�:� /�� 9�O�H��+�H�5�O�F��0��;�O�G����"&��!%������"0�1J�"K��!/�0H�!I��)�*<�=��$�(�(��7����R��%�0@�1�0D�*E�F�&�G�E�B��	��K�K��l�l�$;�#9�-�#�
	
�G��&��6�{�%�%�)7�(V�(V��)
���%���
���J�+�F�J��O�J�)1�:�(>���%����C&s�/F?�__suppress_context__c#�hK�|\}}}g}t�}|��|��t|�|vr�|||f��|j|�|jt|��|jr
|j
}n|j}|�yt|�}|}t|dd�}|�|�t|�|vr��yyyyyy�w)N�
__traceback__)	rG�idr5�addr��	__cause__�__context__r(r<)r�r�r�r��seen_exceptions�seen_exception_ids�causes       rD�walk_exception_chainr�#s�����"*���)�R���),���
� ��%��9�
�%7�7��I�r�)�)�

�"�"�9�-��"�"�2�i�=�1��-�-�!�+�+��!�-�-���}���E�{�H��I�����6�B�)
� ��%��9�
�%7�7�&�
!�7�&�
!�s�B)B2�,B2c#�K�|��y�wr?rBr�s rDr�r�Bs������s�r�zOptional[list[BaseException]]r�zOptional[Set[int]]z Tuple[int, List[Dict[str, Any]]]c��|
�
t�}
|	�g}	|�t|�|
vr|gfS|�+|	j|�|
jt|��t	|||||||||��	}|g}|}|dz
}t|d�xr|j}
|
rl|xrt|d�xr|jdu}|r�|j}tt|�|t|dd�|||d||	|
��
\}}|j|�nk|xrt|d�xr|jdu}|rI|j}tt|�|t|dd�|||d||	|
��
\}}|j|�|xrt|d	�}|r^t|j�D]F\}}tt|�|t|dd�||||d
|z||	|
��\}}|j|��H||fS)a.
    Creates the list of exceptions.
    This can include chained exceptions and exceptions from an ExceptionGroup.

    See the Exception Interface documentation for more details:
    https://develop.sentry.dev/sdk/event-payloads/exception/

    Args:
        exception_id (int):

            Sequential counter for assigning ``mechanism.exception_id``
            to each processed exception. Is NOT the result of calling `id()` on the exception itself.

        parent_id (int):

            The ``mechanism.exception_id`` of the parent exception.

            Written into ``mechanism.parent_id`` in the event payload so Sentry can
            reconstruct the exception tree.

            Not to be confused with ``seen_exception_ids``, which tracks Python ``id()``
            values for cycle detection.
    N)	r�r�r�r�r�r�r�rir�r8r�r�r�)
r�r�r�r�r�r�rir�r�r�r��
exceptionszexceptions[%s])r�r�r�r�r�r�r�rir�r�r�)rGr�r5r�r�r^r�r��exceptions_from_errorr(r<�extendr��	enumerater�)r�r�r�r�r�r�r�rir�r�r��parentr��should_supress_context�exception_has_causer��child_exceptions�exception_has_content�contextr��idx�es                      rDr�r�Fsa��J�!� �U���������I��2D�!D��b�!�!������y�)����r�)�}�-�
.���
�%��!����
�F���J��I��A��L�	�	�1�2�U�y�7U�7U���
�
0��	�;�/�
0��#�#�4�/�	�
��'�'�E�/D��e����5�/�4�8�-�#�)�"�%� /�#5�0�,�\�+�
���.�/�
�
2��	�=�1�
2��%�%�T�1�	�
!��+�+�G�/D��g��!��7�O�T�:�-�#�)�$�%� /�#5�0�,�\�+�
���.�/�#�G�w�y�,�'G����	� 4� 4�5�F�C��/D��a����1�o�t�4�-�#�)�#�'�#�-�%� /�#5�0�,�\�+�
���.�/�6� 
�*�%�%rCc��|\}}}tduxrt|t�}|rt|||||dd|��\}}	n6g}	t|�D]&\}}}|	j	t||||||����(|	j
�|	S)Nr)r�r�r�r�r�r�r�r�)r�r�r�r�r�r�)rr�r�r�r5r�r�)
r�r�r�r�r�r�r�r�r�r�s
          rD�exceptions_from_error_tupler��s���'��H�i��+�4�7��J��%�=���/����)����!�	
���J��
�';�H�'E�#�H�i�����1�%�'��#1�'�)�
�	
�(F������rCc�T�	t|�S#t$rt|�ddcYSwxYw)Nr8r�)rZ�UnicodeDecodeErrorr~r�s rD�	to_stringr��s1��!��5�z����!��E�{�1�R� � �!�s�

�'�'c#�K�d|vr|d��d|vr)|djd�xsdD]}d|vs�|d���d|vr;|djd�xsdD]}t|t�s�d|vs�|d���!yy�w)Nr��threads�valuesrB�	exception)rAr�r�)�event�threadr�s   rD�iter_event_stacktracesr�s������u���L�!�!��E���I�&�*�*�8�4�:��:�F��v�%��\�*�*�;��e���{�+�/�/��9�?�R�?�I��)�T�*�|�y�/H���-�-�@��s�/A;�8A;�+A;�0A;c#�K�t|�D]@}t|t�r|jxsi}|j	d�xsdD]}|����By�w)Nr�rB)r�r�rrXrA)r�r�rDs   rD�iter_event_framesr�sO����,�U�3�
��j�.�1�#�)�)�/�R�J��^�^�H�-�3��3�E��K�4�	4�s�AA�Optional[List[str]]�project_rootc��t|�D]@}t|t�r|jxsi}t	|jd�|||���B|S)Nr�)�in_app_exclude�in_app_includer�)r�r�rrX�set_in_app_in_framesrA)r�r�r�r�r�s     rD�
handle_in_appr�sQ��-�U�3�
��j�.�1�#�)�)�/�R�J���N�N�8�$�)�)�%�		
�	4��LrCc��|sy|D]�}|jd�}|��|jd�}t||�rd|d<�:t||�rd|d<�L|jd�}|��`t|�rd|d<�qt||�s�~d|d<��|S)N�in_apprYTFrx)rA�_module_in_list�_is_external_source�_is_in_project_root)r�r�r�r�rD�current_in_apprYrxs        rDr�r�-s����������8�,���%�����8�$���6�>�2�"�E�(�O���6�>�2�#�E�(�O���9�9�Z�(������x�(�#�E�(�O���x��6�"�E�(�O��;�>�MrCc�f�t|t�rt|�dk(r|\}}}npt|t�rIt	|dd�}|�t|�}|}nCt
j�\}}}||ur'd}|}t|�}ntdt|�z��|||f}trtt|�}|S)N�r�z,Expected Exception object to report, got %s!)r��tuplere�
BaseExceptionr<r(rzr�r�rr+r0)r�r�r�r�r�s     rDr�r�Xs����%���C��J�!�O�"'���)�R�	�E�=�	)�
�U�O�T�
2��
�>��E�{�H��I�&)�l�l�n�#�H�i����%���!�	���;���G�$�u�+�U�V�V��)�R�(�H�����*���OrCc��|D�chc]}|d|d|d|df��}}|D�cgc]}|d|d|d|df|vr|��}}|j|�|r|jdt�nd}|�|t|�|z
d}|Scc}wcc}w)zV
    Add the missing frames from full_stack to frames and return the merged list.
    rxrorUr��max_stack_framesN)r�rArre)r�r�r�rD�	frame_ids�
stackframer�rs        rDr�r�ts������E�
�*���.�!��(�O��*��		
����%�
�$�J��z�"��~�&��x� ��z�"�	
��
�	�$��
����f��
�	���-�/G�H�
��
�#���J��2B� B� D�E�
����A��
s
�B�Bc��t|�}t|�}|r-|jdt�rt	|d|d��d}nd}ddt||||�id�|fS)	N�add_full_stackr�rs)r�rsr�r�r�)�levelr�)r�r�rArr�r�)r�r�r��hintr�s     rD�event_from_exceptionr
�s���
#�8�,�H�#�H�-�D��.�,�,�-=�?U�V�'�$2�3L�$M�+�,>�?�
���
�
�
���5��n�i����	
�	
�
�
rC�name�itemsc�T�|�y|sy|D]}||k(s|j|dz�s�yy)NFr�T�rI)rr�items   rDr�r��s8���|�������4�<�4�?�?�4�#�:�6���rCc�<�|�ytjd|�du}|S)NFz [\\/](?:dist|site)-packages[\\/]�r"�search)rx�external_sources  rDr�r��s.�����	�	�	�5�x�@��L���rCc�2�|�|�y|j|�ryy)NFTr)rxr�s  rDr�r��s(����<�/�����<�(��rC�string�	max_bytesc�\�|jd�d|dz
jdd��}|dzS)zd
    Truncate a UTF-8-encodable string to the last full codepoint so that it fits in max_bytes.
    rgNr��ignore)�errors�...)rjr�)rr�	truncateds   rD�_truncate_by_bytesr�s8���
�
�g�&���Q��7�>�>�w�x�>�X�I��u��rCc�b�	t|jd��S#ttf$rYywxYw)Nrg)rerj�UnicodeEncodeErrorr�r�s rD�_get_size_in_bytesr�s3����5�<�<��(�)�)��� 2�3����s��.�.zUnion[AnnotatedValue, str]c���|r|�|St|�}t|�}|�||kDr
t||�}n|�||kDr|d|dz
dz}n|St||xs|dd|dz
|ggd���S)Nr�rz!limit�x)re�rem)rX�metadata)rrerr)rXrV�	byte_size�	text_size�truncated_values     rDrfrf�s����J�&���"�5�)�I��E�
�I����Z�!7�,�U�J�?��	�	�9�z�#9�� 0�*�q�.�1�E�9�������)�	��s�J��N�J�?�@�
��rCr&zOptional[Tuple[int, ...]]c�P�d}tjd|zdztjtjz�}	|j	|�j�d}t
tt|jd�dd��}|S#tttf$rYywxYw)z�
    Parses a version string into a tuple of integers.
    This uses the parsing loging from PEP 440:
    https://peps.python.org/pep-0440/#appendix-b-parsing-version-strings-with-regular-expressions
    a  # noqa: N806
        v?
        (?:
            (?:(?P<epoch>[0-9]+)!)?                           # epoch
            (?P<release>[0-9]+(?:\.[0-9]+)*)                  # release segment
            (?P<pre>                                          # pre-release
                [-_\.]?
                (?P<pre_l>(a|b|c|rc|alpha|beta|pre|preview))
                [-_\.]?
                (?P<pre_n>[0-9]+)?
            )?
            (?P<post>                                         # post release
                (?:-(?P<post_n1>[0-9]+))
                |
                (?:
                    [-_\.]?
                    (?P<post_l>post|rev|r)
                    [-_\.]?
                    (?P<post_n2>[0-9]+)?
                )
            )?
            (?P<dev>                                          # dev release
                [-_\.]?
                (?P<dev_l>dev)
                [-_\.]?
                (?P<dev_n>[0-9]+)?
            )?
        )
        (?:\+(?P<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))?       # local version
    z^\s*z\s*$r�r�Nr�)
r"r#�VERBOSE�
IGNORECASEr�	groupdictr�mapr
r�rr�r�)r&�VERSION_PATTERN�patternr��
release_tuples     rD�
parse_versionr/
s����O�>�j�j��/�!�G�+�
�
�
�R�]�]�"��G�
��-�-��(�2�2�4�Y�?��+0��S�'�-�-��:L�R�a�:P�1Q�+R�
����
�z�>�2����s�A
B�B%�$B%c���	ddl}ddlm}tt	j
d|j�ddD�cgc]
}t|���c}�}|dd�r#tjdk\r|d	k\s	|d
d�ryy
		ddl}ddlm
}t|j�}|�tj!d�y|d�r|dkry
ycc}w#t$rY�WwxYw#t$rYywxYw)z�
    Returns whether gevent/eventlet have patched the stdlib in a way where thread locals are now more "correct" than contextvars.
    rN)�is_object_patchedz	a|b|rc|\.r��	threading�local�r�r7)��	�contextvars�
ContextVarFT)�is_monkey_patchedzYInternal error in Sentry SDK: Could not parse Greenlet version from greenlet.__version__.r�)rr\)�gevent�
gevent.monkeyr1rr"r��__version__r
rz�version_infor_�greenlet�eventlet.patcherr9r/r�r�)r:r1�part�
version_tupler>r9�greenlet_versions       rD�_is_contextvars_brokenrC@s��
��3��#%�8�8�L�&�:L�:L�#M�b�q�#Q�R�#Q�4�S��Y�#Q�R�
�
��[�'�2��!�!�V�+�
��0H�%�m�\�B���3�&
��6�(��)=�)=�>���#��L�L�k�
���X�&�+;�f�+D����M
S��$�
��
��"�
���
�s:�4C�C�1C�=6C�4
C�C�	C�C�	C#�"C#r3c� ��G�fd�d�}|S)Nc�B��eZdZd
deddddf�fd�
Zd
dd�Zdd�Zd
d	�Zy)�1_make_threadlocal_contextvars.<locals>.ContextVarNrr;rr=c�R��||_||_��|_��|_yr?)�_name�_default�_local�_original_local)r�rr;r3s   �rDrz:_make_threadlocal_contextvars.<locals>.ContextVar.__init__ws$����D�J�#�D�M��'�D�K�#(�7�D� rCc�L�t|jd|xs|j�S)NrX)r<rJrI)r�r;s  rDrAz5_make_threadlocal_contextvars.<locals>.ContextVar.get}s���4�;�;���1I�D�M�M�J�JrCc��ttjd��}|j�}t	|j
||�||j_|S)N�@)rZ�random�getrandbitsrA�setattrrKrJrX)r�rXrI�original_values    rDrGz5_make_threadlocal_contextvars.<locals>.ContextVar.set�sE����*�*�2�.�/�E�!�X�X�Z�N��D�(�(�%��@� %�D�K�K���LrCc�|�t|j|�|j_|jj|=yr?)r<rKrJrXr�)r�rIs  rDrHz7_make_threadlocal_contextvars.<locals>.ContextVar.reset�s/�� '��(<�(<�e� D�D�K�K���$�$�-�-�e�4rCr?)r;rr=r)rXrr=r)rIrr=N)r�r�r�rZrrArGrH�r3s�rDr8rFts-���	+��	+�u�	+��	+�	K�	�	5rCr8rB)r3r8s` rD�_make_threadlocal_contextvarsrUss���5�5�0�rCc���t�s)tjdkr	ddlm}d|fS	ddlm}d|fSddlm}dt|�fS#t
$rY�wxYw#t
$rY�-wxYw)z�
    Figure out the "right" contextvars installation to use. Returns a
    `contextvars.ContextVar`-like class with a limited API.

    See https://docs.sentry.io/platforms/python/contextvars/ for more information.
    r4r)r8TrTF)
rCrzr=�aiocontextvarsr8r_r7r2r3rU)r8r3s  rD�_get_contextvarsrX�s}��"�#�
���f�$�
�5��Z�'�'�

�2��Z�'�'� ��/��6�6�6���
��
���
��
�s"�	A�	A�	A�A�	A"�!A"z�

With asyncio/ASGI applications, the Sentry SDK requires a functional
installation of `contextvars` to avoid leaking scope/context data across
requests.

Please refer to https://docs.sentry.io/platforms/python/contextvars/ for more information.
c���d}d\}}t|t�r(t|jd�rd\}}|j}n=t	|dd�xs
t	|dd�}t|t
�rd\}}|j}t|d�r
|j}nt|d�r|j}|�@t|d	�r,t|jt�r|jd
z|z}||z|z}|S)zbReturn the qualified name of func. Works with regular function, lambda, partial and partialmethod.N)r�r�r�)zpartial(<function �>)�_partialmethod�__partialmethod__)zpartialmethod(<function rZr�r�r�)
r�rr^�funcr<r	r�r�r�rZ)r]�
func_qualname�prefix�suffix�partial_methods     rD�qualname_from_functionrb�s���%)�M��N�F�F��$�� �W�T�Y�Y�
�%C�3�����y�y��!��'7��>�
�'��%�t�C
���n�m�4�=�N�F�F�!�&�&�D��t�^�$��)�)�
�	��z�	"��
�
�
�� ��4��&�:�d�o�o�s�+K� �O�O�c�1�M�A�M���.��7�
��rCc��t|�Sr?)rb)r]s rD�transaction_from_functionrd�s
��!�$�'�'rC�disable_capture_eventc��eZdZdZy)�ServerlessTimeoutWarningz>Raised when a serverless method is about to reach its timeout.Nr�rBrCrDrgrg�s��H�rCrgc�J�eZdZdZ		d
dededdddddf
d	�Zdd
�Zdd�Zdd�Z	y)�
TimeoutThreadz�Creates a Thread which runs (sleeps) for a time duration equal to
    waiting_time and raises a custom ServerlessTimeout exception.
    N�waiting_time�configured_timeout�isolation_scopezOptional[sentry_sdk.Scope]�
current_scoper=c��tjj|�||_||_||_||_tj�|_yr?)	r2�Threadrrjrkrlrmr/�_stop_event)r�rjrkrlrms     rDrzTimeoutThread.__init__�sG��	���!�!�$�'�(���"4���.���*���$�?�?�,��rCc�8�|jj�yr?)rprGr�s rD�stopzTimeoutThread.stops�������rCc��tj�}tj�}t	||j
ddd���\}}tj||��|S)Nr2Fr�)r�r�)r	)rzr�r�r�r
�options�
capture_event)r�r�rr�r	s     rD�_capture_exceptionz TimeoutThread._capture_exceptionsR���<�<�>���&�&�(��*��!�>�>�*�u�=�
���t�
	� � ��T�2��rCc��|jj|j�|jj�ryt	|j
�}||j
kr|dz}|j�{|j�otjj|j�5tjj|j�5	tdj|���tdj|���#t$rt|j!��YnwxYw	ddd�n#1swYnxYwddd��^#1swY�gxYw)Nr8zZWARNING : Function is expected to get timed out. Configured timeout duration = {} seconds.)rp�waitrj�is_setr
rkrlrmr��scope�use_isolation_scope�	use_scopergr�rL�reraiserv)r��integer_configured_timeouts  rD�runzTimeoutThread.runs,�������d�/�/�0����"�"�$��%(��)@�)@�%A�"�&��(?�(?�?�)C�a�)G�&����+��0B�0B�0N��!�!�5�5�d�6J�6J�K��%�%�/�/��0B�0B�C�<�6�x��� :����'�h�o�o�*�
�
�	
��%�<���!8�!8�!:�;�<��;�D�C�C��L�K�K�sB�+*E�D:�D�D-�*D:�,D-�-D:�1	E�:E	�?E�E�NN)r=N)r=r0)
r�r�r�r��floatr
rrrrvrrBrCrDriri�sS���9=�6:�-��-� �-�6�	-�
4�-�
�
-� ��
rCri�originalc���d}	|jd�}tj|�}|jd�}|S#t$r1}t
j
dj|��|�Yd}~|Sd}~wwxYw)zO
    Convert a string to base64, via UTF-8. Returns None on invalid input.
    N�UTF-8z"Unable to encode {orig} to base64:)�orig)rj�base64�	b64encoder�rLr��warningr�)r��
base64_string�
utf8_bytes�base64_bytes�errs     rD�	to_base64r�2s����M�X��_�_�W�-�
��'�'�
�3��$�+�+�G�4�
�����X����;�B�B��B�Q�SV�W�W����X�s�7=�	A7�&A2�2A7r�c�&�d}	tj|�}|sJ�|jd�}tj|�}|jd�}|S#t$r1}tjdj|��|�Yd}~|Sd}~wwxYw)zQ
    Convert a string from base64, via UTF-8. Returns None on invalid input.
    Nr�z#Unable to decode {b64} from base64:)�b64)
�BASE64_ALPHABETrrjr��	b64decoder�rLr�r�r�)r��utf8_string�only_valid_charsr�r�r�s      rD�from_base64r�Bs����K�

�*�0�0��?�����$�+�+�G�4���%�%�l�3�
� �'�'��0������
����1�8�8�]�8�K�S�	
�	
����
�s�AA�	B�&B�B�
Components)rrrx�query�fragment�url�remove_authority�remove_query_valuesr�zUnion[str, Components]c	���t|�}t|jd��}|rL|jj	d�}t|�dkDrt�dt�d|d��}n|j}n|j}|r(tt|D�cic]	}|t��c}��}	n|j}	t|j||	|j|j��}
|r|
St|
�Scc}w)zL
    Removes the authority and query parameter values from a given URL.
    T)�keep_blank_valuesrr8rdr��rrr�rxr�)rrr�rr�rerr
rr�rrxr�r)r�r�r�r��
parsed_url�query_params�netloc_partsrr3�query_string�
componentss           rD�sanitize_urlr�Zs����#��J��J�,�,��E�L��!�(�(�.�.�s�3���|��q� �)�)��R� ��F� �&�&�F��"�"������N��#�s�5�5��N�O�
��"�'�'���� � ���
�_�_��$�$��J�
����*�%�%��!Os�
C0�	ParsedUrl�r�r�r��sanitizec	���t|d|d��}tt|j|jd|j
d���}t
||j|j��S)z�
    Splits a URL into a url (including path), query and fragment. If sanitize is True, the query
    parameters will be sanitized to remove sensitive data. The autority (username and password)
    in the URL will always be removed.
    T)r�r�r�r�r�r�)	r�rr�rrrxr�r�r�)r�r�r��base_urls    rD�	parse_urlr��sn����d����J����$�$��$�$������	
��H�������$�$��rC�ratec	�4�t|ttf�rtj|�r1t
j
dj||t|����yt|�}|dks|dkDr't
j
dj||���yy)	z�
    Checks the given sample rate to make sure it is valid type and value (a
    boolean or a number between 0 and 1, inclusive).
    z|{source} Given sample rate is invalid. Sample rate must be a boolean or a number between 0 and 1. Got {rate} of type {type}.)rir�r(Frr8zW{source} Given sample rate is invalid. Sample rate must be between 0 and 1. Got {rate}.)rir�T)
r�rr�math�isnanr�r�r�r(r�)r�ris  rD�is_valid_sample_rater��s����d�T�7�O�,��
�
�4�0@����
K�
R�
R��D�t�D�z�
R�
�	
�
���;�D��a�x�4�!�8����e�l�l��D�
m�
�	
�
�rCr�
regex_list�substring_matchingc�j�|�y|D]+}|s
|ddk7r|dz
}tj||�}|s�+yy)NFr��$Tr)rr�r��item_matcher�matcheds     rD�match_regex_listr��sK��
���"��!�l�2�&6�#�&=��C��L��)�)�L�$�/����
#�rCrzsentry_sdk.client.BaseClientc��|duxrL|jduxr<|jjduxr"|jjj|vS)zB
    Determines whether the given URL matches the Sentry DSN.
    N)�	transport�
parsed_dsnr)rr�s  rD�
is_sentry_urlr��s^��
	�d��	6����D�(�	6����'�'�t�3�	6�
���'�'�.�.�#�5�	rCc#��K�	ddlm}t�}|j�D]_}|jj	dd�}|��"t|�}|j��:||vs�?||jf��|j|��ay#t$rM	ddl	}n#t$rYYywxYw|jD]%}t|j�|jf���'YywxYw�w)Nr)r#�Name)�	importlibr#rG�
distributionsrA�_normalize_module_namer&r�r_�
pkg_resources�working_setr3)r#�yielded�distr�normalized_namer��infos       rD�_generate_installed_modulesr��s�����A�&��%���*�*�,�D��=�=�$�$�V�T�2�D�
��"8��">���<�<�+��w�0N�)�4�<�<�7�7��K�K��0�-���A�	� ���	��	��"�-�-�D�(����2�D�L�L�@�@�.�A�se�C �AB�B�B�##B�C �	C�B�C�	B#�C� C �"B#�#7C�C �C�C c�"�|j�Sr?)r[�rs rDr�r�s���:�:�<�rCc�0�tjdd|�S)Nz[-_.]+r�)r"�subr�s rD�1_replace_hyphens_dots_and_underscores_with_dashesr�s��
�6�6�)�S�$�'�'rCc�@�t�tt��atSr?)�_installed_modulesr�r�rBrCrD�_get_installed_modulesr�
s���!�!�"=�"?�@���rC�packagec���tt|��}t�j�D��cic]\}}t|�|��}}}|j	|�}|�yt|�Scc}}wr?)r�r�r�rrAr/)r��normalized_packagerY�v�installed_packagesr&s      rD�package_versionr�s|��/�9�'�B���0�1�7�7�9��9�I�F�A�	:�&�A�1�D�9���!�$�$�%7�8�G������!�!��s�A(c�L�|�J�|j|ur|j|��|�r?)r��with_traceback)�tprXr�s   rDr}r}!s4��
�������"�$��"�"�2�&�&�
�KrCc��y)z.No-op function for ensure_integration_enabled.NrB)�_a�_ks  rD�_no_opr�,s��rCc��yr?rB)r��original_functions  rD�ensure_integration_enabledr�3s��8;rCc��yr?rB)r�s rDr�r�9s��>ArCc�^���trttttf���d��fd�}|S)a�
    Ensures a given integration is enabled prior to calling a Sentry-patched function.

    The function takes as its parameters the integration that must be enabled and the original
    function that the SDK is patching. The function returns a function that takes the
    decorated (Sentry-patched) function as its parameter, and returns a function that, when
    called, checks whether the given integration is enabled. If the integration is enabled, the
    function calls the decorated, Sentry-patched function. If the integration is not enabled,
    the original function is called.

    The function also takes care of preserving the original function's signature and docstring.

    Example usage:

    ```python
    @ensure_integration_enabled(MyIntegration, my_function)
    def patch_my_function():
        with sentry_sdk.start_transaction(...):
            return my_function()
    ```
    c�j���d���fd�}�turt��|�St��|�S)Nc�j��tj�j����|i|��S�|i|��Sr?)r�r��get_integration)�args�kwargsr�r��sentry_patched_functions  ���rD�runnerz;ensure_integration_enabled.<locals>.patcher.<locals>.runner^s=����$�$�&�6�6�{�C�K�(�$�9�&�9�9�*�D�;�F�;�;rC)r�zP.argsr�zP.kwargsr=r7)r�r
)r�r�r�r�s` ��rD�patcherz+ensure_integration_enabled.<locals>.patcher]s8���	<���&�1�5�0�1�&�9�9�'�u�&�'��/�/rC)r��Callable[P, R]r=r�)rr+rr6r7)r�r�r�s`` rDr�r�?s,���2�!��!�Q�$��1B�C��
0��NrCc�*�tj�Sr?)�time�perf_counter_nsrBrCrD�nanosecond_timer�ns���#�#�%�%rCc�B�ttj�dz�S)Nge��A)r
r��perf_counterrBrCrDr�r�ss���4�$�$�&��,�-�-rCc�*�tj�Sr?)r�r�rBrCrD�nowr�ws������rC)�get_hub��is_module_patchedc��yr?rBrBrCrD�get_gevent_hubr��s��rC�mod_namec��y�NFrB)r�s rDr�r��s��rCc�2�td�xstd�S)Nr2�_threadr�rBrCrD�	is_geventr��s���[�)�I�->�y�-I�IrCc���|� 	|j}|j}|�||fS	t�rt	�}|�	|j
dfS	t
j�}|j}|j}|�||fS		t
j�}|j}|j}|�||fS	y#t$rY��wxYw#t$rY��wxYw#t$rY�^wxYw#t$rYywxYw)zK
    Try to get the id of the current thread, with various fall backs.
    Nr�)	�identrr�r�r��thread_identr2�current_thread�main_thread)r��	thread_id�thread_name�
gevent_hubs    rD�get_current_thread_metar�s0����	����I� �+�+�K��$� �+�-�-�%��{�#�%�
��!�
�!�.�.��4�4�

��)�)�+���L�L�	��k�k��� ��k�)�)�!�
��&�&�(���L�L�	��k�k��� ��k�)�)�!���G�	��	��"�
��
���
��
���
���	
�sF�B1�
C�	1C�=1C�1	B=�<B=�	C�C�	C�C�	C*�)C*c��t|tttf�rtj|�ytj
|�yr?)r�r�rrGr<�updater�)r�s rD� _register_control_flow_exceptionr�s1���(�T�5�#�.�/�'�.�.�x�8�'�+�+�H�5rCr�c��|tk(rt|d�r|jdvryt|t	t
��ryy)N�code)rNFT)�
SystemExitr^r	�
issubclassrr<)r�rXs  rD�should_be_treated_as_errorr�s7��	�Z��G�E�6�2�u�z�z�Y�7N���"�e�;�<�=��rC�Tc�p�	t||�r|S		||�S#t$rY�wxYw#t$rYywxYw)z�
    Attempt to convert from an unknown type to a specific type, using the
    given function. Return None if the conversion fails, i.e. if the function
    raises an exception.
    N)r�rrL)�convert_funcrXs  rD�try_convertr�sR��
��e�\�*��L�+�
��E�"�"��	�
��
��
����s�
�)�	&�&�	5�5c���				d�fd��	�|�}t|t�stj|t��S|S#t$rt|�cYSwxYw)z&Safely serialize to a readable string.c���t|�rH	t|dd�}t|dd�}t|dd�}|r
|r|�d|��}n|r
|r|�d|��}n|}d|�d�St|t�r*|j�D��cic]\}}|�	|���c}}St|ttf�r|D�cgc]
}�	|���c}St|d	�r`	t|�j�D��cic]\}}|jd
�s	|�	|���!}}}dt|�j�d|�d�S|S#t$rdt|�j�d�cYSwxYwcc}}wcc}wcc}}w#t$rt|�cYSwxYw)
Nr�r�r��	anonymousr�z
<function �>z
<callable r�r��<� )�callabler<rLr(r�r�r�rr�rr^r�rIr~)
rrY�qualnamer�	full_path�kr�r!�attrs�serialize_items
         �rDrz&safe_serialize.<locals>.serialize_item�s�����D�>�
;� ��|�T�:��"�4���>���t�Z��=���h�#)�(�!�H�:� 6�I���#)�(�!�D�6� 2�I� $�I�#�I�;�a�0�0���d�
#�59�Z�Z�\�B�\�T�Q��A�~�a�(�(�\�B�B�
��t�U�m�
,�/3�4�t�!�N�1�%�t�4�4�
�T�:�
&�
"�!%�T�
� 0� 0� 2�� 2���1��<�<��,��~�a�(�(� 2���
�4��:�.�.�/�q���q�9�9��K��#�
;�#�D��J�$7�$7�#8��:�:�
;��C��4�����
"��D�z�!�
"�sB�AD)�8E�)E�E"�$$E�E"�)"E�
E�E"�"E9�8E9r:)rrr=z6Union[str, dict[Any, Any], list[Any], tuple[Any, ...]])r�rZrhrirL)ra�
serializedrs  @rD�safe_serializer�sn���"��"�	A�"�H�#�D�)�
��j�#�.�
�J�J�z�3�/�	
��	
��
���4�y���s�2A�A�A�Art�Optional[dict[str, Any]]c�l�|�yt|jdd�xs|djdd��S)NF�enable_logs�_experiments�r^rA�rts rD�has_logs_enabledr%s?���������M�5�)�	=��>�"�&�&�}�e�<��rCc�V�|�y|jd�xs|djd�S)N�before_send_logr"�rAr$s rD�get_before_send_logr)'s8������;�;�(�)��W�^�-D�-H�-H��.�rCc�>�|�yt|jdd��S)NF�enable_metricsTr#r$s rD�has_metrics_enabledr,2s!���������,�d�3�4�4rCc�V�|�y|jd�xs|djd�S)N�before_send_metricr"r(r$s rD�get_before_send_metricr/9s8������;�;�+�,����0G�0K�0K��1�rCc�0�|�y|djd�S)Nr"�before_send_spanr(r$s rD�get_before_send_spanr2Ds#������>�"�&�&�'9�:�:rCc���t|ttttf�r|St|t
tf�r|sgSt|t
�rOt|d���ttttfvr~t�fd�|D��rjtj|�St|t�rEt|d���ttttfvrt�fd�|D��rt|�St|�S)a�
    Turn unsupported attribute value types into an AttributeValue.

    We do this as soon as a user-provided attribute is set, to prevent spans,
    logs, metrics and similar from having live references to various objects.

    Note: This is not the final attribute value format. Before they're sent,
    they're serialized further into the actual format the protocol expects:
    https://develop.sentry.dev/sdk/telemetry/attributes/
    rc3�8�K�|]}t|��u���y�wr?�r(�r2r�r�s  �rDr4z#format_attribute.<locals>.<genexpr>_������0L��1��a��B�����c3�8�K�|]}t|��u���y�wr?r5r6s  �rDr4z#format_attribute.<locals>.<genexpr>cr7r8)r�r^r
r�rZr�rr(�allr��deepcopyr{��valr�s @rD�format_attributer>Ms�����#��c�5�#�.�/��
��#��e�}�%�c��	�	�C��	�
�#�a�&�\��
�#�s�E�4�(�(�S�0L��0L�-L��=�=��%�%�	�C��	�
�#�a�&�\��
�#�s�E�4�(�(�S�0L��0L�-L���9���S�>�rCc�t��t|t�r|dd�St|t�r|dd�St|t�r|dd�St|t�r|dd�St|t
�rF|sgdd�St
|d���ttttfvrt�fd�|D��r|dd�St|�dd�S)	z2Serialize attribute value to the transport format.�boolean)rXr(�integer�doubler�arrayrc3�8�K�|]}t|��u���y�wr?r5r6s  �rDr4z&serialize_attribute.<locals>.<genexpr>zr7r8)	r�r^r
r�rZr�r(r:r{r<s @rD�serialize_attributerEis�����#�t���i�0�0��#�s���i�0�0��#�u���h�/�/��#�s���h�/�/��#�t�����1�1��#�a�&�\��
�#�s�D�%�(�(�S�0L��0L�-L� �'�2�2��s�^�X�6�6rC)r=zGenerator[None, None, None])rXrrWzOptional[bool]r=zbool | None)r=rlr�)r�r0r=Nr?)r�zOptional[ExcInfo]r=zDict[str, Optional[ExcInfo]])r=r9r=rl)r�r�r=zIterator[TracebackType])NNN)rDrrrrWrsrWr=rZ)rYrlrxrlr=rl)NTTNN)TTN)NNNNNN)r�r9r�r�r�r�r�r�r�r�r�rWr�rWrirlr�r�r=r�)r�r0r=zIterator[ExcInfo])NNrrNNNN)
r�r0r�r�r�r�r�r�r=�List[Dict[str, Any]])r�r/r=z#Iterator[Annotated[Dict[str, Any]]])r�r/r=zIterator[Dict[str, Any]])
r�r/r�r�r�r�r�rlr=r/)
r�rr�r�r�r�r�rlr=r!)r��Union[BaseException, ExcInfo]r=r0)r�rFr�rFr�r�r=rFr�)r�rGr�r�r�r�r=zTuple[Event, Dict[str, Any]])r=zTuple[bool, type])r]zCallable[..., Any]r=rl)TTF)Tr�)r=zIterator[Tuple[str, str]])r=zDict[str, str])r�r�rXr�r�r!r=r#)r�rr�rr=N)r��)type[sentry_sdk.integrations.Integration]r�r�r=�*Callable[[Callable[P, R]], Callable[P, R]])r�rHr=z0Callable[[Callable[P, None]], Callable[P, None]])r�rHr�z(Union[Callable[P, R], Callable[P, None]]r=rI)r=z
Optional[Hub])r�zOptional[threading.Thread]r=z#Tuple[Optional[int], Optional[str]])r�z/Union[type, list[type], tuple[type], set[type]]r=N)rzCallable[[Any], T]rXrr=zOptional[T])rtrr=z.Optional[Callable[[Log, Hint], Optional[Log]]])rtrr=z4Optional[Callable[[Metric, Hint], Optional[Metric]]])rtrr=z8Optional[Callable[[SpanJSON, Hint], Optional[SpanJSON]]])r=rr=r.)r=r.r=r4)�r�r7r�rhra�loggingr�rwrOr"r|rzr2r��collectionsr�
contextlibrrr�decimalr�	functoolsrr	r
�numbersr�urllib.parserr
rrrr@rr_�typingrr��sentry_sdk._compatr�sentry_sdk._typesrrr�sentry_sdk.constsrrr�typesrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,�
gevent.hubr-r.r/r0r1r2r3r4r5r6r7r��	getLoggerr�r�r8r@rGr<�__annotations__r^rErJr#r��	frozensetr\r]r�r`�bytesrkr�r�rZr�r�r�r�r�r�r�r�r�r�r�r�r�r�rr>rCrNrSr
rqryr|r{r�r�r�rr�r�r�r^rL�HAS_CHAINED_EXCEPTIONSr�r�r�r�r�r�r�r�r�r�r
r�r�r�rrrfr/rCr(rUrX�HAS_REAL_CONTEXTVARS�CONTEXTVARS_ERROR_MESSAGErbrdrergrorir�r�r�r�r�r�r�r�r�r�r�r�r�r�r}r�r�r�r�r:r�r�r;r�r�rrrr
rrr%r)r,r/r2r>rErBrCrD�<module>r^s�
��
�������	�
�	��
���"�%�'��3�3��K�K��+�
!��#�R�R����.������(�	�	�	�	�#��A����A�	��q�!���
��	�	�.�	/����1�;�1�1��u���03�u���4�*�$�*��.��.��"�*�*�1�2���B�C���B�C�����=B�+�T�U�T�u�T�
�6�2 �� �� �F��$7�8��'�H�+�
�+�u�+�	5�J�	5�3�	5��j�)��+�3�+�:�+�,%)�
"�!�
"�#�
"�"�Z�"�L
�L
�^+R�+R�\P���[��T��$�#'�"�"�*��*��*� �*�
�	*�

�*�S�
*�`)-������&��S�	�6 �E� �c� ��U��s�����'6����6"&�$(�#'�(,�<@�
0��0��0�"�0�!�	0�
&�0�:�
0��0�h%)�#'�(,��!�� ��&���	�4-��-�?�-��!:��s��,26�,0�$(�!%�"�37�c��c�(�c�	"�c�/�	c�
*�c�"�
c��c�
�c�1�c��c�L!��,B�C���7�>�26�,0���"�37�7;�/3�H&��H&�(�H&�	"�H&�/�	H&�
*�H&��
H&��H&�
�H&�1�H&�5�H&�-�H&�(�H&�Z26�,0�37�	(��(�.�(�*�(�1�	(�
�(�V!�S�!�S�!�
.��-1�,0�$(�	���)��*��"�	�

��0%)�	(��(�)�(�*�(�"�	(�
�(�V�8(�"�(�&�(�/�(��	(�Z26�,0��-��.��*��$�	�:�/��2G��D���/��d��
��
�-<�
�	�
��s��s��s���c��o��/3����+��!��60�3�0�#>�0�f0��0�f���$��8"7�J$4�#5� ��j����@(�#�#:�;��	�y�	�B
�I�$�$�B
�J
��
��
� �s����*��&W�
X�
�
"� $��	-&�	�-&��-&��-&��	-&�
�-&�`
�{�$@�A�	��3��$��+��6�u��c��d��@)-�$��

��%����
�	�&	�8�	�s�	�t�	�A�8�����(�C�(�C�(�
�
"�S�
"�%@�
"�&��'��$��	���	�	�
�
�;�@�;�+�;�
6�;��;�
�A�@�A�	;�A��A�EK�*�<�*�A�*�2�*�Z�&�S�&�
.�S�.��U���0�/�J�4�J�
,0�1�(�1�*�1�h6�?�6�	�6��5����4������A��$/��/�3�/�d�8��T���
'��5��5�!;�5��5��
'��;��;�
'�;�?�;��87��_B������H;����C��D��
�s$�3T	�
T�	T�T�T+�*T+
Back to Directory File Manager