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

�

_�*jW��
��ddlZddlZddlmZmZmZddlmZddlmZddl	Z	ddl
mZmZm
Z
mZddlmZddlmZmZmZmZmZmZerwddlmZmZmZdd	lmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%dd
l&m'Z'm(Z(e!d�Z)e#d�Z*dd
l+m,Z,m-Z-m.Z.m/Z/ddlm0Z0ddl1m2Z2Gd�de'd��Z3Gd�de3d��Z4e'dde5i�Z6dZ7dZ8Gd�de5e�Z9e9jtgZ;e9jxe9jxe9jxe9jze9jte9jxe9jze9jze9jzd�	Z>de?de5fd�Z@Gd �d!�ZAGd"�d#�ZBGd$�d%eB�ZCGd&�d'eB�ZDer/e%	d-dddej�d(�											d.d)��ZFe%d/d*��ZF	d-dddej�d(�											d0d+�ZFdd,lGmHZHmIZImJZJmKZKmLZLmMZMy)1�N)�datetime�	timedelta�timezone)�Enum)�
TYPE_CHECKING)�INSTRUMENTER�SPANDATA�
SPANSTATUS�SPANTEMPLATE)�get_profiler_id)�capture_internal_exceptions�get_current_thread_meta�is_valid_sample_rate�logger�nanosecond_time�should_be_treated_as_error)�Callable�Mapping�MutableMapping)
�Any�Dict�Iterator�List�Optional�	ParamSpec�Tuple�TypeVar�Union�overload)�	TypedDict�Unpack�P�R)�Event�MeasurementUnit�MeasurementValue�SamplingContext)�ContinuousProfile)�Profilec��eZdZUeed<	eed<	eed<	eed<	eed<	eed<	eed<	ded	<	eed
<	ded<	d
ed<	ded<	eed<	eed<y)�
SpanKwargs�trace_id�span_id�parent_span_id�same_process_as_parent�sampled�op�description�Optional[sentry_sdk.Hub]�hub�status�Optional[Transaction]�containing_transaction� Optional[Union[datetime, float]]�start_timestampzsentry_sdk.Scope�scope�origin�nameN��__name__�
__module__�__qualname__�str�__annotations__�bool���A/opt/hc_python/lib/python3.12/site-packages/sentry_sdk/tracing.pyr+r+0s����
�	�
��T���<� $�$�J��
�	�

��	�
��	Y�
'�'�s���r� 7�7�8�;�;�	�
"�!�X���	��	�`rEr+F)�totalc�0�eZdZUeed<	eed<	ded<y)�TransactionKwargs�source�parent_sampled�Baggage�baggageNr=rDrErFrIrIks ����	������PrErI�ProfileContext�profiler_idrMzsentry-tracec�0�eZdZdZdZdZdZdZdZde	fd�Z
y	)
�TransactionSource�	component�custom�route�task�url�view�returnc��|jS�N)�value��selfs rF�__str__zTransactionSource.__str__�s���z�z�rEN)r>r?r@�	COMPONENT�CUSTOM�ROUTE�TASK�URL�VIEWrAr^rDrErFrQrQ�s,���I�
�F��E��D�
�C��D���rErQ)	�endpoint�
function_name�handler_name�method_and_path_pattern�path�
route_name�
route_pattern�uri_templaterV�http_status_coderXc�\�|dkrtjSd|cxkrdkr�nn�|dk(rtjS|dk(rtjS|dk(rtjS|dk(rtj
S|dk(rtjS|dk(rtjStjSd|cxkrd	krantjS|d
k(rtjS|dk(rtjS|dk(rtjStjStjS)
z�
    Returns the Sentry status corresponding to the given HTTP status code.

    See: https://develop.sentry.dev/sdk/event-payloads/contexts/#trace-context
    i�i�i�i�i�i�i�i�iXi�i�i�)r
�OK�PERMISSION_DENIED�	NOT_FOUND�RESOURCE_EXHAUSTED�FAILED_PRECONDITION�UNAUTHENTICATED�ALREADY_EXISTS�INVALID_ARGUMENT�DEADLINE_EXCEEDED�
UNIMPLEMENTED�UNAVAILABLE�INTERNAL_ERROR�
UNKNOWN_ERROR)rms rF�get_span_status_from_http_coder|�s���#���}�}��	� �	&�3�	&��s�"��/�/�/�
��
$��'�'�'�
��
$��0�0�0�
��
$��1�1�1�
��
$��-�-�-�
��
$��,�,�,��.�.�.�	� �	&�3�	&��#�#�#��s�"��/�/�/�
��
$��+�+�+�
��
$��)�)�)��,�,�,��#�#�#rEc�,�eZdZdZdZdeddfd�Zdd�Zy)	�
_SpanRecorderz5Limits the number of spans recorded in a transaction.��maxlen�spans�
dropped_spansr�rXNc�4�|dz
|_g|_d|_y)N�rr�r]r�s  rF�__init__z_SpanRecorder.__init__�s���q�j���#%��
�"#��rEc��t|j�|jkDrd|_|xjdz
c_y|jj|�y)Nr�)�lenr�r��_span_recorderr��append)r]�spans  rF�addz_SpanRecorder.add�sA���t�z�z�?�T�[�[�(�"&�D�����!�#���J�J���d�#rE)r��SpanrXN)r>r?r@�__doc__�	__slots__�intr�r�rDrErFr~r~�s"��?�4�I�$�s�$�t�$�$rEr~c���eZdZdZdZ														dEddddddded	d
ddddd
ddddddddddeddddfd�Zdeddfd�Z	e
defd��Zejdeddfd��Ze
defd��Z
e
jdeddfd ��Z
defd!�ZdFd"�Z								dGd#�Ze
dHd$��Zej&fd%ed&d'ddfd(�Ze						dId)��Zedd*�							dJd+��ZdKd,�Ze						dLd-��Zdefd.�ZdMd/�Zd0edd'ddfd1�Zd0edd'ddfd2�ZdNd3�Zd4ed5eddfd6�Zdeddfd7�Z 	dOdede!d8d9ddfd:�Z"						dPd;�Z#dQd<�Z$d=eddfd>�Z%defd?�Z&		dR					dSd@�Z'dTdA�Z(dUdB�Z)dVdC�Z*dWdD�Z+eZ,eZ-eZ.e)Z/y)Xr�akA span holds timing information of a block of code.
    Spans can have multiple child spans thus forming a span tree.

    :param trace_id: The trace ID of the root span. If this new span is to be the root span,
        omit this parameter, and a new trace ID will be generated.
    :param span_id: The span ID of this span. If omitted, a new span ID will be generated.
    :param parent_span_id: The span ID of the parent span, if applicable.
    :param same_process_as_parent: Whether this span is in the same process as the parent span.
    :param sampled: Whether the span should be sampled. Overrides the default sampling decision
        for this span when provided.
    :param op: The span's operation. A list of recommended values is available here:
        https://develop.sentry.dev/sdk/performance/span-operations/
    :param description: A description of what operation is being performed within the span.

        .. deprecated:: 2.15.0
            Please use the `name` parameter, instead.
    :param name: A string describing what operation is being performed within the span.
    :param hub: The hub to use for this span.

        .. deprecated:: 2.0.0
            Please use the `scope` parameter, instead.
    :param status: The span's status. Possible values are listed at
        https://develop.sentry.dev/sdk/event-payloads/span/
    :param containing_transaction: The transaction that this span belongs to.
    :param start_timestamp: The timestamp when the span started. If omitted, the current time
        will be used.
    :param scope: The scope to use for this span. If not provided, we use the current scope.
    )�	_trace_id�_span_idr.r/r0r1r2�
_measurementsr9�_start_timestamp_monotonic_nsr5�	timestamp�_tags�_datar�r4�_context_manager_state�_containing_transactionr:r;r<�_flags�_flags_capacityNr,�
Optional[str]r-r.r/r0�Optional[bool]r1r2r4r3r5r7r6r9r8r:�Optional[sentry_sdk.Scope]r;r<rXc���||_||_||_||_||_||_|xs||_|	|_||_||_	|
|_
i|_i|_i|_
|
|_i|_d|_|�;t#j$dt&d��|jxs|j|_	|�$t)j*t,j.�}n4t1|t2�r$t)j4|t,j.�}||_	t9�|_d|_d|_ |jC�|jEtG��y#t<$rY�CwxYw)N�
z>The `hub` parameter is deprecated. Please use `scope` instead.���
stacklevel)$r�r�r.r/r0r1r2r5r4r:r;r�r�r�r�r�r��warnings�warn�DeprecationWarningr�nowr�utc�
isinstance�float�
fromtimestampr9rr��AttributeErrorr�r��update_active_thread�set_profiler_idr)r]r,r-r.r/r0r1r2r4r5r7r9r:r;r<s               rFr�z
Span.__init__sK��""�����
�,���&<��#��������.�;�����������
����<>���13��
�')��
�'=��$�)+���!����?��M�M�P�"��
����0�s�y�y�D�J��"�&�l�l�8�<�<�8�O�
���
/�&�4�4�_�h�l�l�S�O�.���	�2A�1B�D�.�
04���9=����!�!�#����_�.�/���	��	�s�E"�"	E.�-E.r�c�>�|j�t|�|_yyrZ)r�r~r�s  rF�init_span_recorderzSpan.init_span_recorder[s �����&�"/��"7�D��'rEc�x�|js#tj�j|_|jSrZ)r��uuid�uuid4�hexr\s rFr,z
Span.trace_id_s&���~�~�!�Z�Z�\�-�-�D�N��~�~�rEr[c��||_yrZ)r��r]r[s  rFr,z
Span.trace_idfs	����rEc�~�|js&tj�jdd|_|jS)N�)r�r�r�r�r\s rFr-zSpan.span_idjs-���}�}� �J�J�L�,�,�R�S�1�D�M��}�}�rEc��||_yrZ)r�r�s  rFr-zSpan.span_idqs	����
rEc���d|jj�d|j�d|j�d|j�d|j
�d|j�d|j�d|j�d	�S)
N�<z(op=z, description:�, trace_id=�
, span_id=�, parent_span_id=�
, sampled=�	, origin=�)>)	�	__class__r>r1r2r,r-r.r0r;r\s rF�__repr__z
Span.__repr__usP�����'�'����� � ��
�
�����#�#�������

�	
rEc��|jxstj�}|j}||_||f|_|SrZ)r:�
sentry_sdk�get_current_scoper�r�)r]r:�old_spans   rF�	__enter__zSpan.__enter__�s;���
�
�<�j�:�:�<���:�:����
�',�h�&7��#��rEc���|�+t||�r|jtj�t	�5|j
\}}|`|j
|�||_ddd�y#1swYyxYwrZ)r�
set_statusr
rzr
r��finishr�)r]�tyr[�tbr:r�s      rF�__exit__z
Span.__exit__�s`����!;�B��!F��O�O�J�5�5�6�
(�
*�"�9�9�O�E�8��+��K�K���!�E�J�	+�
*�
*�s�*A+�+A4c��|jS)z�The ``Transaction`` that this span belongs to.
        The ``Transaction`` is the root of the span tree,
        so one could also think of this ``Transaction`` as the "root span".)r�r\s rFr7zSpan.containing_transaction�s���+�+�+rE�instrumenter�kwargsrc��|jd��tjdtd��t	j
�jd}||k7r
t�S|jd|j�td|j|j|jd�|��}|jxr|jj}|r|j|�|S)	a�
        Start a sub-span from the current span or transaction.

        Takes the same arguments as the initializer of :py:class:`Span`. The
        trace id, sampling decision, transaction pointer, and span recorder are
        inherited from the current span/transaction.

        The instrumenter parameter is deprecated for user code, and it will
        be removed in the next major version. Going forward, it should only
        be used by the SDK itself.
        r2zEThe `description` parameter is deprecated. Please use `name` instead.r�r�r�r0)r,r.r7rD)�getr�r�r�r��
get_client�options�NoOpSpan�
setdefaultr0r�r,r-r7r�r�)r]r�r��configuration_instrumenter�child�
span_recorders      rF�start_childzSpan.start_child�s����:�:�m�$�0��M�M�W�"��
�&0�%:�%:�%<�%D�%D�^�%T�"��5�5��:�����)�T�\�\�2��
��]�]��<�<�#'�#>�#>�
��	
��
�'�'�V�D�,G�,G�,V�,V�	�����e�$��rEc�@�tjt|�fi|��S)ag
        DEPRECATED: Use :py:meth:`sentry_sdk.continue_trace`.

        Create a Transaction with the given params, then add in data pulled from
        the ``sentry-trace`` and ``baggage`` headers from the environ (if any)
        before returning the Transaction.

        This is different from :py:meth:`~sentry_sdk.tracing.Span.continue_from_headers`
        in that it assumes header names in the form ``HTTP_HEADER_NAME`` -
        such as you would get from a WSGI/ASGI environ -
        rather than the form ``header-name``.

        :param environ: The ASGI/WSGI environ to pull information from.
        )�Transaction�continue_from_headers�EnvironHeaders)�cls�environr�s   rF�continue_from_environzSpan.continue_from_environ�s��(�0�0���1H�S�F�S�SrE��_sample_randc�X�tjd�tj|j	t
�|��}|j
t
|i�t|j	t��}|�!|j
|�|j�tdi|��}d|_|S)a�
        DEPRECATED: Use :py:meth:`sentry_sdk.continue_trace`.

        Create a transaction with the given params (including any data pulled from
        the ``sentry-trace`` and ``baggage`` headers).

        :param headers: The dictionary with the HTTP headers to pull information from.
        :param _sample_rand: If provided, we override the sample_rand value from the
            incoming headers with this value. (internal use only)
        z2Deprecated: use sentry_sdk.continue_trace instead.r�FrD)r�warningrL�from_incoming_headerr��BAGGAGE_HEADER_NAME�update�extract_sentrytrace_data�SENTRY_TRACE_HEADER_NAME�freezer�r/)r��headersr�r�rM�sentrytrace_kwargs�transactions       rFr�zSpan.continue_from_headers�s���$	���K�L��.�.��K�K�+�,�<�
��	�
�
�*�G�4�5�5��K�K�0�1�
���)��M�M�,�-�

�N�N��!�+�F�+��-2��*��rEc#�K�|jsyt|j�f��|jj�j	�}|rt
|f��yy�w)z�
        Creates a generator which returns the span's ``sentry-trace`` and ``baggage`` headers.
        If the span's containing transaction doesn't yet have a ``baggage`` value,
        this will cause one to be generated and stored.
        N)r7r��to_traceparent�get_baggage�	serializer�)r]rMs  rF�iter_headerszSpan.iter_headerssZ�����*�*�

�&��(;�(;�(=�=�=��-�-�9�9�;�E�E�G���%�w�.�.��s�AAc�:�|sy|jt|ifi|��S)z�
        DEPRECATED: Use :py:meth:`sentry_sdk.continue_trace`.

        Create a ``Transaction`` with the given params, then add in data pulled from
        the given ``sentry-trace`` header value before returning the ``Transaction``.
        N)r�r�)r��traceparentr�s   rF�from_traceparentzSpan.from_traceparent"s/����(�s�(�(�
%�{�3�
�7=�
�	
rEc��|jdurd}n|jdurd}nd}|j�d|j��}|�|d|��z
}|S)NT�1F�0�-)r0r,r-)r]r0r�s   rFr�zSpan.to_traceparent5sT���<�<�4���G�
�\�\�U�
"��G��G�!%������=�����G�-�-�K��rEc�P�|jr|jj�Sy)z�Returns the :py:class:`~sentry_sdk.tracing_utils.Baggage`
        associated with this ``Span``, if any. (Taken from the root of the span tree.)
        N)r7r�r\s rF�
to_baggagezSpan.to_baggageCs%���&�&��.�.�:�:�<�<�rE�keyc�"�||j|<yrZ)r��r]r�r[s   rF�set_tagzSpan.set_tagK�����
�
�3�rEc�"�||j|<yrZ)r�rs   rF�set_dataz
Span.set_dataNrrEc�:�|jj|�yrZ)r�r��r]�datas  rF�update_datazSpan.update_dataQs���
�
���$�rE�flag�resultc�h�t|j�|jkr||j|<yyrZ)r�r�r�)r]r
rs   rF�set_flagz
Span.set_flagTs,���t�{�{��d�2�2�2� &�D�K�K���3rEc��||_yrZ�r5r�s  rFr�zSpan.set_statusXs	����rE�unitr%c�`�tjdtd��||d�|j|<y�z
        .. deprecated:: 2.28.0
            This function is deprecated and will be removed in the next major release.
        zq`set_measurement()` is deprecated and will be removed in the next major version. Please use `set_data()` instead.r�r�)r[rN�r�r�r�r��r]r<r[rs    rF�set_measurementzSpan.set_measurement[�0��	�
�
����	
�
.3�D�#A����4� rEc��|�M|jtjt|��|�!|jtj|�yyyrZ)rr	�	THREAD_IDrA�THREAD_NAME�r]�	thread_id�thread_names   rF�
set_threadzSpan.set_threadjsF��� ��M�M�(�,�,�c�)�n�=��&��
�
�h�2�2�K�@�'�!rEc�J�|�!|jtj|�yyrZ)rr	�PROFILER_ID�r]rOs  rFr�zSpan.set_profiler_idss!���"��M�M�(�.�.��<�#rE�http_statusc��|jdt|��|jtj|�|jt
|��y)Nzhttp.status_code)rrArr	�HTTP_STATUS_CODEr�r|�r]r!s  rF�set_http_statuszSpan.set_http_statusws@�������K� 0�	
�	
�
�
�h�/�/��=����6�{�C�DrEc� �|jdk(S)N�okrr\s rF�
is_successzSpan.is_success~s���{�{�d�"�"rEc���|j�y	|r<t|t�r$tj|t
j�}||_n8t�|jz
}|jt|dz��z|_|xstj�}|j�}|rzt j"|j$v}|j&duxr8|j&j)d�xs|j&j)d�}|s|r|j+d|�t-||�y#t$r+tjt
j�|_Y��wxYw)aD
        Sets the end timestamp of the span.

        Additionally it also creates a breadcrumb from the span,
        if the span represents a database or HTTP request.

        :param scope: The scope to use for this transaction.
            If not provided, the current scope will be used.
        :param end_timestamp: Optional timestamp that should
            be used as timestamp instead of the current time.

        :return: Always ``None``. The type is ``Optional[str]`` to match
            the return value of :py:meth:`sentry_sdk.tracing.Transaction.finish`.
        Ni�)�microsecondszai.�gen_ai.zgen_ai.conversation.id)r�r�r�rr�rr�rr�r9rr�r�r�r��get_conversation_idr	�GEN_AI_OPERATION_NAMEr�r1�
startswithr�"maybe_create_breadcrumbs_from_span)r]r:�
end_timestamp�elapsed�conversation_id�	has_ai_op�
is_ai_span_ops       rFr�zSpan.finish�s3��&�>�>�%��	8���m�U�3�$,�$:�$:�=�(�,�,�$W�M�!.���)�+�d�.P�.P�P��!%�!5�!5�	�!(�4��9�"����7��5�5�7�� �3�3�5��� �6�6�$�*�*�D�I� �G�G�4�/�����"�"�5�)�J�T�W�W�-?�-?�	�-J�
��M��
�
�6��H�*�5�$�7���#�	8�%�\�\�(�,�,�7�D�N�	8�s�A6D6�61E*�)E*c
�,�|j|j|j|j|j|j
|j|j|jd�	}|jr(|j|d<|j|jd<t|j�dkDr|j|d<|j}|r||d<i}|j|j�|j|j�|r||d<|S)z5Returns a JSON-compatible representation of the span.)	r,r-r.r/r1r2r9r�r;r5r�measurements�tagsr)r,r-r.r/r1r2r9r�r;r5r�r�r�r�r�r�)r]�rvr7rs    rF�to_jsonzSpan.to_json�s����
�
��|�|�"�1�1�&*�&A�&A��'�'��+�+�#�3�3�����k�k�
 
���;�;��;�;�B�x�L�#'�;�;�D�J�J�x� ��t�!�!�"�Q�&�!%�!3�!3�B�~���z�z����B�v�J������D�K�K� ����D�J�J����B�v�J��	rEc��|j|j|j|j|j|j
d�}|jr|j|d<|jr+|jj�j�|d<i}|jjtj�}|�||d<|jjtj�}|�||d<|r||d<|S)N)r,r-r.r1r2r;r5�dynamic_sampling_contextz	thread.idzthread.namer)r,r-r.r1r2r;r5r7r�r;r�r�r	rr)r]r8rrrs     rF�get_trace_contextzSpan.get_trace_context�s����
�
��|�|�"�1�1��'�'��+�+��k�k�
 
���;�;��;�;�B�x�L��&�&��+�+�7�7�9�R�R�T�
�)�*����J�J�N�N�8�#5�#5�6�	�� � )�D����j�j�n�n�X�%9�%9�:���"�"-�D�����B�v�J��	rEc�b�|jjtj�}|�yd|iS)NrO)r�r�r	rr s  rF�get_profile_contextzSpan.get_profile_context�s4���j�j�n�n�X�%9�%9�:�����
�;�
�	
rEc�B�t�\}}|j||�yrZ)rrrs   rFr�zSpan.update_active_threads��!8�!:��	�;����	�;�/rE)NNNTNNNNNNNN�manualN)rXr��r��
Optional[Any]r[rBr�rBrXN�rXr6)r��Mapping[str, str]r�rrXr�)r�rDr�r�r�rrXr��rXzIterator[Tuple[str, str]])r�r�r�rrXr6�rX�Optional[Baggage]�r�Dict[str, Any]rXN��)rz
Optional[int]rr�rXN)rOr�rXN�NN)r:r�r0� Optional[Union[float, datetime]]rXr��rXrI�rXr)rXzOptional[ProfileContext])rXN)0r>r?r@r�r�rCrAr�r�r��propertyr,�setterr-r�r�r�r7r�SENTRYr��classmethodr�r�r�r�r�r�rrr	r
r�r�rrr�r%r(r�r9r<r>r��_to_traceparent�_to_baggage�
_iter_headers�_get_trace_contextrDrErFr�r��s����:�I�8%)�#'�*.�'+�$(�"�'+�*.�"&�:>�>B�.2�� $�>0�!�>0�!�>0�(�	>0�
!%�>0�"�
>0�
�>0�%�>0�(�>0� �>0�!8�>0�<�>0�,�>0��>0��>0� 
�!>0�D8��8��8���#�����_�_��c��d����������
�^�^��S��T����

�#�

��
"�!�
"�*9�
"�?N�
"�	
�
"��,��,�#/�"5�"5�)��)�AF�)�	�)�V�T�$�T��T�
�	T��T�*�
)-�	)�$�)�&�	)�
�)�
�
)��)�V/�&�
�$�
��
�
!�	
��
�$���� �3� �u� �� � �C� �� �$� � �'�S�'�$�'�4�'������BD�
B��
B� %�
B�->�
B�	
�
B�A�(�A�7F�A�	
�A�=�E�3�E�4�E�#�D�#�
/3�<@�2�+�2�:�2�
�	2�h!�F�@
�0�
%�O��K� �M�*�rEr�c
�r��eZdZdZdZdddejfdedddd	d
eddd
df�fd�
Zd
efd�Z	d
e
fd�Zd%�fd�Z								d&�fd�Z
ed%d��Z						d'd�Zd
efd�Z		d(dd�							d)�fd�Z	d*dededdd
dfd�Zdeddd
dfd�Zded
df�fd �Zd+�fd!�Zd,�fd"�Zd-d#�Z				d.d$�ZeZeZ�xZS)/r�aiThe Transaction is the root element that holds all the spans
    for Sentry performance instrumentation.

    :param name: Identifier of the transaction.
        Will show up in the Sentry UI.
    :param parent_sampled: Whether the parent transaction was sampled.
        If True this transaction will be kept, if False it will be discarded.
    :param baggage: The W3C baggage header value.
        (see https://www.w3.org/TR/baggage/)
    :param source: A string describing the source of the transaction name.
        This will be used to determine the transaction's type.
        See https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations
        for more information. Default "custom".
    :param kwargs: Additional arguments to be passed to the Span constructor.
        See :py:class:`sentry_sdk.tracing.Span` for available arguments.
    )
r<rJrK�sample_rater��	_contexts�_profile�_continuous_profile�_baggager�rKNr<rKr�rMrGrJr�zUnpack[SpanKwargs]rXc�:��t�|�di|��||_||_d|_||_i|_i|_d|_d|_	||_
|j�dn|jj�}|�||_yt|j�|_y�NrD)�superr�r<rJrYrKr�rZr[r\r]r��_generate_sample_randr,)r]r<rKrMrJr��baggage_sample_randr�s       �rFr�zTransaction.__init__,s����	���"�6�"���	����.2���,���<>���+-���-1��
�BF�� ���
��M�M�)�D�t�}�}�/I�/I�/K�	��*� 3�D�� 5�d�m�m� D�D�rEc��d|jj�d|j�d|j�d|j�d|j
�d|j�d|j�d|j�d	|j�d
�S)Nr�z(name=z, op=r�r�r�r�z	, source=r�r�)
r�r>r<r1r,r-r.r0rJr;r\s rFr�zTransaction.__repr__HsU�����'�'��	�	�����
�
�����#�#����������
�
	
rEc�>�|jduxs|jduS)z�Returns whether the transaction might have been started.

        If this returns False, we know that the transaction was not started
        with sentry_sdk.start_transaction, and therefore the transaction will
        be discarded.
        NF)r�r0r\s rF�_possibly_startedzTransaction._possibly_startedXs#���"�"�$�.�G�$�,�,�%�2G�GrEc���|j�stjd�t�|��|j
�|j
j	�|S)Nz�Transaction was entered without being started with sentry_sdk.start_transaction.The transaction will not be sent to Sentry. To fix, start the transaction bypassing it to sentry_sdk.start_transaction.)rer�debugr`r�r[)r]r�s �rFr�zTransaction.__enter__csL����%�%�'��L�L�>�
�	�����=�=�$��M�M�#�#�%��rEr[c����|j�|jj|||�|j�|jj�t�|�|||�yrZ)r[r�r\�stopr`)r]r�r[r�r�s    �rFr�zTransaction.__exit__rsT����=�=�$��M�M�"�"�2�u�b�1��#�#�/��$�$�)�)�+�
����U�B�'rEc��|S)znThe root element of the span tree.
        In the case of a transaction it is the transaction itself.
        rDr\s rFr7z"Transaction.containing_transaction}s	���rEc���|}|�tjdtd��|}t|tj
�r(tjdtd��|jS|S)z�
        Logic to get the scope from the arguments passed to finish. This
        function exists for backwards compatibility with the old finish.

        TODO: Remove this function in the next major version.
        zMThe `hub` parameter is deprecated. Please use the `scope` parameter, instead.�r�zDPassing a Hub to finish is deprecated. Please pass a Scope, instead.)r�r�r�r�r��Hubr:)r]�	scope_arg�hub_arg�scope_or_hubs    rF�_get_scope_from_finish_argsz'Transaction._get_scope_from_finish_args�sb��!�����M�M�_�"��
�#�L��l�J�N�N�3��M�M�V�"��
� �%�%�%��rEc�x�dj|jrd|jzdznd|j��S)Nz{op}transaction <{name}>r�z> rK)r1r<)�formatr1r<r\s rF�_get_log_representationz#Transaction._get_log_representation�s8��)�0�0�(,����d�g�g�
��$�R�t�y�y�1�
�	
rE�r4c	��	��|j�y|j||�}|xs"|jxstj�}tj
�}|j
�sy|j��|jdurtjd�ntjd�|jryt|j�rd|jr|jjdkDrd}nd}|jj!|d�	�|jj!|d
�	�y|j"stj$d�d|_t&�|�Q||�|j*j-t.j0�}|��||jd
vr�tjdj3|j5�|j*t.j0|jd
���|jr]|jj!dd�	�t7|jj8�dz}|jj!dd
|��d|_|js"|j�tj$d�yg}d}	|jj-dd�r|jj8D]e}
|
j��t;|
j<t>�r|
j<jAd�rd}	|jC|
jE���gn=|jj8D�
cgc]}
|
j�|
jE��� }}
t7|jj8�t7|�z
}||jjFz}d|_i}
|
jI|jJ�|
jId|jM�i�|jO�}|�|
jId|i�d|j"d|jPi|
|jR|j|jT|d�}|dkDr||d<|	rd|d<|jV�0|jVjY�r|jV|d<d|_+|jZ|d<|j]|�Scc}
w)auFinishes the transaction and sends it to Sentry.
        All finished spans in the transaction will also be sent to Sentry.

        :param scope: The Scope to use for this transaction.
            If not provided, the current Scope will be used.
        :param end_timestamp: Optional timestamp that should
            be used as timestamp instead of the current time.
        :param hub: The hub to use for this transaction.
            This argument is DEPRECATED. Please use the `scope`
            parameter, instead.

        :return: The event ID if the transaction was sent to Sentry,
            otherwise None.
        NFz.Discarding transaction because sampled = FalsezSDiscarding transaction because it was not started with sentry_sdk.start_transactionr�backpressurerYr�)�
data_categoryr�zCTransaction has no name, falling back to `<unlabeled transaction>`.z<unlabeled transaction>�trace_ignore_status_codesz�[Tracing] Discarding {transaction_description} because the HTTP status code {status_code} is matched by trace_ignore_status_codes: {trace_ignore_status_codes})�transaction_description�status_codery�event_processorr�)rx�quantityz1Discarding transaction without sampling decision.�stream_gen_ai_spansr+T�trace�profilerJ)�typer��transaction_info�contextsr7r�r9r��_dropped_spans�_has_gen_ai_spanr6)/r�rqr:r�r�r��	is_activer�r0rrg�	transport�has_tracing_enabledr��monitor�downsample_factor�record_lost_eventr<r�r`r�r�r�r	r#rsrtr�r�r�r1rAr.r�r9r�r�rZr<r>rJr�r9r[�validr��
capture_event)r]r:r0r4�client�reasonr{�	num_spans�finished_spans�has_gen_ai_spanr��len_diffr�r��profile_context�eventr�s                �rFr�zTransaction.finish�sJ���*�>�>�%���0�0���<���E����E�z�'C�'C�'E���&�&�(�����!�����&��|�|�u�$����M�N����i�����$7����$G��>�>�f�n�n�&F�&F��&J�+�F�*�F�� � �2�2�6��2�W�� � �2�2�6��2�P���y�y��N�N�U�
�2�D�I�
���u�m�,��j�j�n�n�X�%>�%>�?���#��v�~�~�.I�J�J��L�L�q�x�x�,0�,H�,H�,J� $�
�
�8�+D�+D� E�.4�n�n�3�/�x��
����� � �2�2�%�]�3�� �� 3� 3� 9� 9�:�Q�>�	�� � �2�2�%�V�i�3��!�D�L��|�|��|�|�#����R�S�������>�>���3�U�;��+�+�1�1���>�>�)���d�g�g�s�+����0B�0B�9�0M�&*�O��%�%�d�l�l�n�5�2�!�/�/�5�5��5�D��>�>�-�����5�
���t�*�*�0�0�1�C��4G�G�� �4�#6�#6�#D�#D�D�
�#�����������'�����$�"8�"8�":�;�<��2�2�4���&��O�O�Y��8�9�"��9�9�!)�4�;�;� 7� ��J�J����#�3�3�#�	
���1��&3�E�"�#��(,�E�$�%��=�=�$����)<�)<�)>�#�}�}�E�)�� �D�M� $� 2� 2��n���"�"�5�)�)��[s�#Srr%c�`�tjdtd��||d�|j|<yrrrs    rFrzTransaction.set_measurementNrrEr��dict[str, Any]c�"�||j|<y)aSets a context. Transactions can have multiple contexts
        and they should follow the format described in the "Contexts Interface"
        documentation.

        :param key: The name of the context.
        :param value: The information about the context.
        N)rZrs   rF�set_contextzTransaction.set_context]s��$����s�rEr!c�L��t�|�|�|jdd|i�y)zySets the status of the Transaction according to the given HTTP status.

        :param http_status: The HTTP status code.�responser{N)r`r%r�)r]r!r�s  �rFr%zTransaction.set_http_statusgs'���	����,�����m�[�%A�BrEc�~��t�|��}|j|d<|j|d<|j|d<|S)z<Returns a JSON-compatible representation of the transaction.r<rJr0)r`r9r<rJr0)r]r8r�s  �rFr9zTransaction.to_jsonns;���
�W�_�
���Y�Y��6�
��{�{��8������9�
��	rEc�Z��t�|��}|jr|j|d<|S)Nr)r`r<r�)r]�
trace_contextr�s  �rFr<zTransaction.get_trace_contextxs+�����1�3�
��:�:�$(�J�J�M�&�!��rEc��|jr|jjrtj|�|_|jS)z�Returns the :py:class:`~sentry_sdk.tracing_utils.Baggage`
        associated with the Transaction.

        The first time a new baggage with Sentry items is made,
        it will be frozen.)r]�mutablerL�populate_from_transactionr\s rFr�zTransaction.get_baggage�s3���}�}��
�
� 5� 5�#�=�=�d�C�D�M��}�}�rEc
�<�tj�}|j�}t|j�sd|_y|j
�t
|j
�|_yt|jjd��r|jd|�n|d�|dn|jd}t|d��s-tjdj|�	��d|_yt
|�|_|jr,|xjd
|jjzzc_|jsTtj dj|t|jjd��rdnd
���d|_y|j"|jk|_|j
r&tj dj|�	��ytj dj||j���y)aO
        Sets the transaction's sampling decision, according to the following
        precedence rules:

        1. If a sampling decision is passed to `start_transaction`
        (`start_transaction(name: "my transaction", sampled: True)`), that
        decision will be used, regardless of anything else

        2. If `traces_sampler` is defined, its decision will be used. It can
        choose to keep or ignore any parent sampling decision, or use the
        sampling context data to make its own decision or to choose a sample
        rate for the transaction.

        3. If `traces_sampler` is not defined, but there's a parent sampling
        decision, the parent sampling decision will be used.

        4. If `traces_sampler` is not defined and there's no parent sampling
        decision, `traces_sample_rate` will be used.
        FN�traces_samplerrK�traces_sample_rate�Tracing)rJzN[Tracing] Discarding {transaction_description} because of invalid sample rate.)rzr�z?[Tracing] Discarding {transaction_description} because {reason}z"traces_sampler returned 0 or Falseztraces_sample_rate is set to 0)rzr�z,[Tracing] Starting {transaction_description}z}[Tracing] Discarding {transaction_description} because it's not included in the random sample (sampling rate = {sample_rate}))rzrY)r�r�rtr�r�r0r�rY�callabler�rrr�rsr�r�rgr�)r]�sampling_contextr�rzrYs     rF�_set_initial_sampling_decisionz*Transaction._set_initial_sampling_decision�s���,�&�&�(��"&�">�">�"@��#�6�>�>�2� �D�L���<�<�#�$�T�\�\�2�D�������*�*�+;�<�=�
-�F�N�N�+�,�-=�>�
$�$4�5�A�!�!1�2��^�^�$8�9�	�$�K�	�B��N�N�`�g�g�,C�h��
�
!�D�L�� ��-����>�>�����6�>�>�#C�#C� C�C������L�L�Q�X�X�,C�$�F�N�N�$6�$6�7G�$H�I�=�=�Y��	
�!�D�L���(�(�4�+;�+;�;����<�<��L�L�>�E�E�,C�F��
�
�L�L�P�W�W�,C� $� 0� 0�W��
rE)rXr�rA)rn�1Optional[Union[sentry_sdk.Scope, sentry_sdk.Hub]]ror�rXr�rL�r:r�r0rMr4r3rXr�rJrNrO)rXrL�r�r'rXN)r>r?r@r�r�rQr`rAr�r�rCrer�r�rPr7rqrtr�r�rr�r�r%r9r<r�r��_get_baggagerW�
__classcell__)r�s@rFr�r�s�����"�I� �+/�'+�'�.�.�E��E�)�E�%�	E�
�E�'�
E�
�E�8
�#�
� 	H�4�	H�
�	(�!�	(�*9�	(�?N�	(�	
�	(������F��E��
&�	�@
��
�/3�<@�_*�
+/�_*�+�_*�:�_*�
(�_*�
�
_*�DBD�
B��
B� %�
B�->�
B�	
�
B�$�s�$�+;�$��$�C�3�C�4�C���	�c� 1�c�	
�c�L�L�*�rEr�c	�t�eZdZdefd�Zed$d��Zejfdeddddfd�Z	defd�Z
d%d	�Zd%d
�Zd&d�Z
ded
dddfd�Zded
dddfd�Zd'd�Zd
eddfd�Zdeddfd�Zdefd�Zd(d�Zd)d�Zd)d�Z		d*dd�							d+d�Z	d,ded
eddddfd�Zded
dddfd �Zd!eddfd"�Z				d-d#�Ze
ZeZ eZ!e
Z"eZ#y).r�rXc�4�d|jjzS)Nz<%s>)r�r>r\s rFr�zNoOpSpan.__repr__�s������/�/�/�/rEc��yrZrDr\s rFr7zNoOpSpan.containing_transaction�s��rEr�r�rc��t�SrZ)r�)r]r�r�s   rFr�zNoOpSpan.start_child�s���z�rEc��y)NrKrDr\s rFr�zNoOpSpan.to_traceparents��rEc��yrZrDr\s rFr�zNoOpSpan.to_baggage���rEc��yrZrDr\s rFr�zNoOpSpan.get_baggager�rEc��td�Sr_)�iterr\s rFr�zNoOpSpan.iter_headerss���B�x�rEr�r[Nc��yrZrDrs   rFrzNoOpSpan.set_tag���rEc��yrZrDrs   rFrzNoOpSpan.set_datar�rEc��yrZrDrs  rFr	zNoOpSpan.update_datar�rEc��yrZrDr�s  rFr�zNoOpSpan.set_statusr�rEr!c��yrZrDr$s  rFr%zNoOpSpan.set_http_statusr�rEc��y)NTrDr\s rFr(zNoOpSpan.is_successr�rEc��iSrZrDr\s rFr9zNoOpSpan.to_json ����	rEc��iSrZrDr\s rFr<zNoOpSpan.get_trace_context#r�rEc��iSrZrDr\s rFr>zNoOpSpan.get_profile_context&r�rEruc��y)z_
        The `hub` parameter is deprecated. Please use the `scope` parameter, instead.
        NrD)r]r:r0r4s    rFr�zNoOpSpan.finish)���	
rEr<rr%c��yrZrDrs    rFrzNoOpSpan.set_measurement5���	
rEr�c��yrZrDrs   rFr�zNoOpSpan.set_context:r�rEr�c��yrZrDr�s  rFr�zNoOpSpan.init_span_recorder=r�rEc��yrZrD)r]r�s  rFr�z'NoOpSpan._set_initial_sampling_decision@r�rErCrFrErHrNrOrLr�rJr�)$r>r?r@rAr�rPr7rrRr�r�r�r�r�rrr	r�r�r%rCr(r9r<r>r�r�rr�r�r�rTrUr�rVrWrDrErFr�r��s���0�#�0�����#/�"5�"5����AF��	��
������
�3�
�u�
��
�
�C�
��
�$�
�
�
��
��
�
�3�
�4�
��D�����
/3�<@�

�
+/�

�+�

�:�

�
(�

�
�

�BD�
��
� %�
�->�
�	
�
�

�s�
�+;�
��
�
��
��
�
� 1�
�	
�
�%�O��K��L� �M�*�rEr��r1r<�
attributes�templatec��yrZrD)�funcr1r<r�r�s     rFrrOr�rEc��yrZrD)r�s rFrr[r�rEc�>�ddlm}|||||��}|r||�S|S)a�

    Decorator to start a child span around a function call.

    This decorator automatically creates a new span when the decorated function
    is called, and finishes the span when the function returns or raises an exception.

    :param func: The function to trace. When used as a decorator without parentheses,
        this is the function being decorated. When used with parameters (e.g.,
        ``@trace(op="custom")``, this should be None.
    :type func: Callable or None

    :param op: The operation name for the span. This is a high-level description
        of what the span represents (e.g., "http.client", "db.query").
        You can use predefined constants from :py:class:`sentry_sdk.consts.OP`
        or provide your own string. If not provided, a default operation will
        be assigned based on the template.
    :type op: str or None

    :param name: The human-readable name/description for the span. If not provided,
        defaults to the function name. This provides more specific details about
        what the span represents (e.g., "GET /api/users", "process_user_data").
    :type name: str or None

    :param attributes: A dictionary of key-value pairs to add as attributes to the span.
        Attribute values must be strings, integers, floats, or booleans. These
        attributes provide additional context about the span's execution.
    :type attributes: dict[str, Any] or None

    :param template: The type of span to create. This determines what kind of
        span instrumentation and data collection will be applied. Use predefined
        constants from :py:class:`sentry_sdk.consts.SPANTEMPLATE`.
        The default is `SPANTEMPLATE.DEFAULT` which is the right choice for most
        use cases.
    :type template: :py:class:`sentry_sdk.consts.SPANTEMPLATE`

    :returns: When used as ``@trace``, returns the decorated function. When used as
        ``@trace(...)`` with parameters, returns a decorator function.
    :rtype: Callable or decorator function

    Example::

        import sentry_sdk
        from sentry_sdk.consts import OP, SPANTEMPLATE

        # Simple usage with default values
        @sentry_sdk.trace
        def process_data():
            # Function implementation
            pass

        # With custom parameters
        @sentry_sdk.trace(
            op=OP.DB_QUERY,
            name="Get user data",
            attributes={"postgres": True}
        )
        def make_db_query(sql):
            # Function implementation
            pass

        # With a custom template
        @sentry_sdk.trace(template=SPANTEMPLATE.AI_TOOL)
        def calculate_interest_rate(amount, rate, years):
            # Function implementation
            pass
    r)�create_span_decoratorr�)�sentry_sdk.tracing_utilsr�)r�r1r<r�r�r��	decorators       rFrras3��T?�%�
�
���	�I�������rE)rLr�rar�r�r/rZ)r�Nr1r�r<r�r��Optional[dict[str, Any]]r�rrXz*Callable[[Callable[P, R]], Callable[P, R]])r��Callable[P, R]rXr�)r�zOptional[Callable[P, R]]r1r�r<r�r�r�r�rrXzAUnion[Callable[P, R], Callable[[Callable[P, R]], Callable[P, R]]])Nr�r�rrr�enumr�typingrr��sentry_sdk.constsrr	r
r�'sentry_sdk.profiler.continuous_profilerr�sentry_sdk.utilsr
rrrrr�collections.abcrrrrrrrrrrrrr�typing_extensionsr r!r"r#�sentry_sdk._typesr$r%r&r'r(�(sentry_sdk.profiler.transaction_profilerr)r+rIrArNr�r�rQrc�LOW_QUALITY_TRANSACTION_SOURCESr_ra�SOURCE_FOR_STYLEr�r|r~r�r�r��DEFAULTrr�rLr�rar�r�r/rDrErF�<module>r�su����2�2�� ��N�N�C����A�A����4��#��A����A���J�@�9a�Y�e�9a�vQ�J�e�Q����3�	
��N� ��)��
	��T�	����#��
"�+�+�&�0�0�%�/�/�0�6�6��!�!�#�-�-�&�,�,�%�+�+��"�"�
��#$�S�#$�S�#$�L$�$�.h+�h+�Vf+�$�f+�RU+�t�U+�p�
��	
�#� $�15�#/�#7�#7�
	
��	
�
�	
��		
�
/�	
�!�
	
�
6�	
��	
��
��
�(,�V�� �-1�+�3�3�
V�
$�V�	�V��	V�
+�V��
V�I�V�v��rE
Back to Directory File Manager