HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/sentry_sdk/__pycache__/tracing.cpython-37.pyc
B

Ta�d�@szddlZddlZddlZddlZddlZddlZddlmZmZddlm	Z	ddl
Z
ddlmZm
Z
mZddlmZddlmZer�ddlmZnddlmZer�ddlZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZe�d�ZGdd�de�Z Gdd�de!�Z"Gdd�de!�Z#Gdd�de#�Z$dd�Z%dd�Z&dd�Z'ej(dd��Z)d d!�Z*dS)"�N)�datetime�	timedelta)�Real)�capture_internal_exceptions�logger�	to_string)�PY2)�MYPY)�Mapping)�	Generator)�Optional)�Any)�Dict)�List)�Tuple)�SamplingContextz5^[ 	]*([0-9a-f]{32})?-?([0-9a-f]{16})?-?([01])?[ 	]*$c@s.eZdZddd�Zdd�Zdd�Zdd	�Zd
S)�EnvironHeaders�HTTP_cCs||_||_dS)N)�environ�prefix)�selfrr�r�C/opt/alt/python37/lib/python3.7/site-packages/sentry_sdk/tracing.py�__init__0szEnvironHeaders.__init__cCs|j|j|�dd���S)N�-�_)rr�replace�upper)r�keyrrr�__getitem__9szEnvironHeaders.__getitem__cCstdd�t|�D��S)Ncss|]
}dVqdS)�Nr)�.0rrrr�	<genexpr>?sz)EnvironHeaders.__len__.<locals>.<genexpr>)�sum�iter)rrrr�__len__=szEnvironHeaders.__len__ccsRxL|jD]B}t|t�sq|�dd���}|�|j�s6q|t|j�d�VqWdS)Nrr)r�
isinstance�strrr�
startswithr�len)r�krrr�__iter__As
zEnvironHeaders.__iter__N)r)�__name__�
__module__�__qualname__rrr%r+rrrrr/s
rc@s$eZdZdZdZdd�Zdd�ZdS)�
_SpanRecorderz5Limits the number of spans recorded in a transaction.)�maxlen�spanscCs|d|_g|_dS)Nr )r0r1)rr0rrrrSs
z_SpanRecorder.__init__cCs(t|j�|jkrd|_n|j�|�dS)N)r)r1r0�_span_recorder�append)r�spanrrr�add]sz_SpanRecorder.addN)r,r-r.�__doc__�	__slots__rr5rrrrr/Ns
r/c
@s�eZdZdZdd�Zd.dd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zedd��Z
edd��Zdd�Zedd��Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd/d(d)�Zd*d+�Zd,d-�ZdS)0�Span)�trace_id�span_id�parent_span_id�same_process_as_parent�sampled�op�description�start_timestamp�_start_timestamp_monotonic�status�	timestamp�_tags�_datar2�hub�_context_manager_state�_containing_transactioncKsd|krt�t�St�|�S)z_
        Backwards-compatible implementation of Span and Transaction
        creation.
        �transaction)�object�__new__�Transaction)�cls�kwargsrrrrK|s

zSpan.__new__NTcCs�|pt��j|_|p$t��jdd�|_||_||_||_||_||_	|	|_
||_i|_i|_
t��|_yt��|_Wntk
r�YnXd|_d|_d|_dS)N�)�uuidZuuid4�hexr9r:r;r<r=r>r?rBrFrDrEr�utcnowr@�time�perf_counterrA�AttributeErrorrCr2rH)rr9r:r;r<r=r>r?rFrBrIrrrr�s&
z
Span.__init__cCs$|jdkrt|�|_|j�|�dS)N)r2r/r5)rr0rrr�init_span_recorder�s

zSpan.init_span_recordercCs&d|jj|j|j|j|j|j|jfS)NzS<%s(op=%r, description:%r, trace_id=%r, span_id=%r, parent_span_id=%r, sampled=%r)>)�	__class__r,r>r?r9r:r;r=)rrrr�__repr__�sz
Span.__repr__cCs8|jptjj}|jd\}}|j}||_|||f|_|S)N���)rF�
sentry_sdk�Hub�currentZ_stackr4rG)rrFr�scope�old_spanrrr�	__enter__�szSpan.__enter__cCs6|dk	r|�d�|j\}}}|`|�|�||_dS)N�internal_error)�
set_statusrG�finishr4)r�ty�value�tbrFr]r^rrr�__exit__�s

z
Span.__exit__cKs`|�d|j�tf|jd|jd�|��}t|t�r:||_n|j|_|j|_}|r\|�	|�|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.
        r=N)r9r:r;)
�
setdefaultr=r8r9r:r&rLrHr2r5)rrN�rvZrecorderrrr�start_child�s	

zSpan.start_childcKst�d�|jf|�S)z$Deprecated: use start_child instead.z:Deprecated: use Span.start_child instead of Span.new_span.)r�warningri)rrNrrr�new_span�s
z
Span.new_spancKs$|tkrt�d�tjt|�f|�S)aJ
        Create a Transaction with the given params, then add in data pulled from
        the 'sentry-trace' header in the environ (if any) before returning the
        Transaction.

        If the 'sentry-trace' header is malformed or missing, just create and
        return a Transaction instance with the given params.
        zXDeprecated: use Transaction.continue_from_environ instead of Span.continue_from_environ.)r8rrjrL�continue_from_headersr)rMrrNrrr�continue_from_environ�szSpan.continue_from_environcKsB|tkrt�d�tj|�d�f|�}|dkr8tf|�}d|_|S)a3
        Create a Transaction with the given params, then add in data pulled from
        the 'sentry-trace' header (if any) before returning the Transaction.

        If the 'sentry-trace' header is malformed or missing, just create and
        return a Transaction instance with the given params.
        zXDeprecated: use Transaction.continue_from_headers instead of Span.continue_from_headers.zsentry-traceNF)r8rrjrL�from_traceparent�getr<)rM�headersrNrIrrrrls
zSpan.continue_from_headersccsd|��fVdS)Nzsentry-trace)�to_traceparent)rrrr�iter_headers*szSpan.iter_headerscKs�|tkrt�d�|sdS|�d�r:|�d�r:|dd�}t�t|��}|dkrTdS|��\}}}|dk	rzd�	t
|d��}|dk	r�d	�	t
|d��}|r�|d
k}nd}tf|||d�|��S)a-
        Create a Transaction with the given params, then add in data pulled from
        the given 'sentry-trace' header value before returning the Transaction.

        If the header value is malformed or missing, just create and return a
        Transaction instance with the given params.
        zNDeprecated: use Transaction.from_traceparent instead of Span.from_traceparent.Nz00-z-00����z{:032x}rOz{:016x}�0)r9r;�parent_sampled)r8rrjr(�endswith�_traceparent_header_format_re�matchr'�groups�format�intrL)rMZtraceparentrNryr9r;Zsampled_strrvrrrrn.s.
zSpan.from_traceparentcCs2d}|jdkrd}|jdkr d}d|j|j|fS)N�T�1Fruz%s-%s-%s)r=r9r:)rr=rrrrq_s

zSpan.to_traceparentcCs||j|<dS)N)rD)rrrdrrr�set_taghszSpan.set_tagcCs||j|<dS)N)rE)rrrdrrr�set_datalsz
Span.set_datacCs
||_dS)N)rB)rrdrrrrapszSpan.set_statuscCs6|�dt|��|dkr&|�d��nd|kr:dkr�nn�|dkrR|�d�nn|dkrf|�d�nZ|d	krz|�d
�nF|dkr�|�d�n2|d
kr�|�d�n|dkr�|�d�n
|�d�npd|kr�dk�r(nnL|dkr�|�d�n6|dk�r|�d�n |dk�r|�d�n
|�d�n
|�d�dS)Nzhttp.status_codei��oki�i�Zpermission_deniedi�Z	not_foundi�Zresource_exhaustedi�Zfailed_preconditioni�Zunauthenticatedi�Zalready_existsZinvalid_argumentiXi�Zdeadline_exceededi�Z
unimplementedi�Zunavailabler`Z
unknown_error)rr'ra)rZhttp_statusrrr�set_http_statusts4

zSpan.set_http_statuscCs
|jdkS)Nr�)rB)rrrr�
is_success�szSpan.is_successcCsr|jdk	rdS|p|jptjj}y$t��|j}|jt	|d�|_Wnt
k
rbt��|_YnXt
||�dS)N)�seconds)rCrFrZr[r\rSrTrAr@rrUrrR�#_maybe_create_breadcrumbs_from_span)rrFZduration_secondsrrrrb�s

zSpan.finishc	Cs`|j|j|j|j|j|j|j|jd�}|jr8|j|j	d<|j	}|rJ||d<|j
}|r\||d<|S)N)r9r:r;r<r>r?r@rCrB�tags�data)r9r:r;r<r>r?r@rCrBrDrE)rrhr�r�rrr�to_json�s"
zSpan.to_jsoncCs.|j|j|j|j|jd�}|jr*|j|d<|S)N)r9r:r;r>r?rB)r9r:r;r>r?rB)rrhrrr�get_trace_context�s

zSpan.get_trace_context)
NNNTNNNNNN)N)r,r-r.r7rKrrVrXr_rfrirk�classmethodrmrlrrrnrqrr�rar�r�rbr�r�rrrrr8es>

1	!
r8csDeZdZdZddd�Zdd�Zddd	�Z�fd
d�Zdd
�Z�Z	S)rL)�namervr}NcKs>|s d|kr t�d�|�d�}tj|f|�||_||_dS)NrIz^Deprecated: use Transaction(name=...) to create transactions instead of Span(transaction=...).)rrj�popr8rr�rv)rr�rvrNrrrr�s

zTransaction.__init__cCs&d|jj|j|j|j|j|j|jfS)NzL<%s(name=%r, op=%r, trace_id=%r, span_id=%r, parent_span_id=%r, sampled=%r)>)rWr,r�r>r9r:r;r=)rrrrrX�szTransaction.__repr__c
s��jdk	rdS�jdkr&t�d�dS|p6�jp6tjj}|j}|dkrJdS�j	s`t�
d�d�_	t��|��j
s��j
dkr�t�
d�dS�fdd��jjD�}|�d�j	d���i�j�j�j|d	��S)
Nz.Discarding transaction because sampled = FalsezCTransaction has no name, falling back to `<unlabeled transaction>`.z<unlabeled transaction>z1Discarding transaction without sampling decision.cs&g|]}|�k	r|jdk	r|���qS)N)rCr�)r!r4)rrr�
<listcomp>sz&Transaction.finish.<locals>.<listcomp>rI�trace)�typerIZcontextsr�rCr@r1)rCr2r�debugrFrZr[r\�clientr�rjr8rbr=r1Z
capture_eventr�rDr@)rrFr�Zfinished_spansr)rrrb�s8






zTransaction.finishcs&tt|���}|j|d<|j|d<|S)Nr�r=)�superrLr�r�r=)rrh)rWrrr�+s

zTransaction.to_jsoncCsB|jptjj}|j}|r|jp i}dj|jr:d|jdnd|jd�}|rRt	|�s\d|_
dS|j
dk	rjdSt|�d��r�|d|�n|d	dk	r�|d	n|d
}t
|�s�t�dj|d��d|_
dS|s�t�d
j|t|�d��r�dndd��d|_
dSt��t|�k|_
|j
�r&t�dj|d��nt�dj|t|�d��dS)aP
        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, regardlesss 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.
        z{op}transaction <{name}>�<z> r})r>r�FN�traces_samplerrv�traces_sample_ratezN[Tracing] Discarding {transaction_description} because of invalid sample rate.)�transaction_descriptionz?[Tracing] Discarding {transaction_description} because {reason}z"traces_sampler returned 0 or Falseztraces_sample_rate is set to 0)r��reasonz,[Tracing] Starting {transaction_description}z}[Tracing] Discarding {transaction_description} because it's not included in the random sample (sampling rate = {sample_rate}))r��sample_rate)rFrZr[r\r��optionsr{r>r��has_tracing_enabledr=�callablero�_is_valid_sample_raterrjr��random�float)rZsampling_contextrFr�r�r�r�rrr�_set_initial_sampling_decision4sH 


z*Transaction._set_initial_sampling_decision)r}N)N)
r,r-r.r7rrXrbr�r��
__classcell__rr)rWrrL�s

3	rLcCs t|�d�dk	p|�d�dk	�S)zf
    Returns True if either traces_sample_rate or traces_sampler is
    defined, False otherwise.
    r�Nr�)�boolro)r�rrrr��sr�cCsbt|t�rt�|�r0t�dj|t|�d��dSt|�}|dksH|dkr^t�dj|d��dSdS)	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}[Tracing] Given sample rate is invalid. Sample rate must be a boolean or a number between 0 and 1. Got {rate} of type {type}.)�rater�Frr zX[Tracing] Given sample rate is invalid. Sample rate must be between 0 and 1. Got {rate}.)r�T)	r&r�math�isnanrrjr{r�r�)r�rrrr��s

r�cCsZd}y0t|d�r2|�|�}t|t�r2|�|jj�}Wntk
rLd}YnX|pXt|�S)N�mogrify)	�hasattrr�r&�bytes�decodeZ
connection�encoding�	Exceptionr)�cursorZsqlZreal_sqlrrr�_format_sql�s



r�c
	cs�|jr:|jjd�dd�r:|r(|dgkr,d}|dkrBd}nd}d}t||�}i}|dk	r`||d<|dk	rp||d<|r|d|d	<t��|j|d
|d�WdQRX|jd|d
��.}x |��D]\}}	|�||	�q�W|VWdQRXdS)NZ_experimentsZrecord_sql_paramsFZpyformatr{z	db.paramsz
db.paramstyleTzdb.executemany�query)�message�categoryr�Zdb)r>r?)	r�r�ror�r�add_breadcrumbZ
start_span�itemsr�)
rFr�r�Zparams_listZ
paramstyleZexecutemanyr�r4r*�vrrr�record_sql_queries�s,
r�cCsd|jdkr"|j|jdd|jd�n>|jdkr@|jdd|jd�n |jdkr`|jdd|j|jd�dS)NZredis)r�r�r�r��httpZhttplib)r�r�r��
subprocess)r�r�r�r�)r>r�r?rDrE)rFr4rrrr�s


r�)+�rerP�
contextlibr�r�rSrr�numbersrrZZsentry_sdk.utilsrrrZsentry_sdk._compatrZsentry_sdk._typesr	�collectionsr
�collections.abc�typingrrr
rrrr�compilerxrrJr/r8rLr�r�r��contextmanagerr�r�rrrr�<module>sJrE
+