HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/mysql/opentelemetry/sdk/trace/__pycache__/__init__.cpython-39.pyc
a

�,�h���
@s�ddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZddl
mZddlmZddlmZmZddlmZmZmZmZmZmZmZmZmZddlmZdd	lmZdd
l m!Z"m#Z$ddl%m&Z&ddl'm(Z(dd
l)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7m8Z8ddl9m:Z:ddl;m<Z<m=Z=ddl>m?Z?ddl@mAZAmBZBddlCmZe�DeE�ZFdZGdZHdZIdZJdZKdZLdZMGdd�d�ZNGdd�deN�ZOGdd�deN�ZPGdd�dejQ�ZRGd d!�d!eR�ZSd"d#�ZTGd$d%�d%�ZUGd&d'�d'�ZVeVeVjWeVjWeVjWeVjWeVjWeVjWeVjWeVjWd(�ZXeV�Yde.eH�ZZGd)d*�d*e$j[eU�Z[Gd+d,�d,e[�Z\Gd-d.�d.e$j]�Z]Gd/d0�d0e$j^�Z^dS)1�N)�OrderedDict)�contextmanager)�environ)�time_ns)�MappingProxyType�
TracebackType)	�Any�Callable�Dict�Iterator�Optional�Sequence�Tuple�Type�Union)�filterwarnings)�
deprecated)�context�trace)�BoundedAttributes)�util)�OTEL_ATTRIBUTE_COUNT_LIMIT�!OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT� OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT�OTEL_LINK_ATTRIBUTE_COUNT_LIMIT�OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT�&OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT�OTEL_SPAN_EVENT_COUNT_LIMIT�OTEL_SPAN_LINK_COUNT_LIMIT)�Resource)�sampling)�IdGenerator�RandomIdGenerator)�BoundedList)�InstrumentationInfo�InstrumentationScope)�SpanContext)�Status�
StatusCode)�types��c@sZeZdZdZddeejdd�dd�Zddd�d	d
�Zdd�dd
�Z	de
ed�dd�ZdS)�
SpanProcessoraInterface which allows hooks for SDK's `Span` start and end method
    invocations.

    Span processors can be registered directly using
    :func:`TracerProvider.add_span_processor` and they are invoked
    in the same order as they were registered.
    N�Span��span�parent_context�returncCsdS)a�Called when a :class:`mysql.opentelemetry.trace.Span` is started.

        This method is called synchronously on the thread that starts the
        span, therefore it should not block or throw an exception.

        Args:
            span: The :class:`mysql.opentelemetry.trace.Span` that just started.
            parent_context: The parent context of the span that just started.
        N���selfr/r0r2r2�Y/opt/nydus/tmp/pip-target-wkfpz8uv/lib64/python/mysql/opentelemetry/sdk/trace/__init__.py�on_startQszSpanProcessor.on_start�ReadableSpan�r/r1cCsdS)a2Called when a :class:`mysql.opentelemetry.trace.Span` is ended.

        This method is called synchronously on the thread that ends the
        span, therefore it should not block or throw an exception.

        Args:
            span: The :class:`mysql.opentelemetry.trace.Span` that just ended.
        Nr2�r4r/r2r2r5�on_end`szSpanProcessor.on_end�r1cCsdS)zPCalled when a :class:`mysql.opentelemetry.sdk.trace.TracerProvider` is shutdown.Nr2�r4r2r2r5�shutdownjszSpanProcessor.shutdown�0u��timeout_millisr1cCsdS)a+Export all ended spans to the configured Exporter that have not yet
        been exported.

        Args:
            timeout_millis: The maximum amount of time to wait for spans to be
                exported.

        Returns:
            False if the timeout is exceeded, True otherwise.
        Nr2�r4r@r2r2r5�force_flushmszSpanProcessor.force_flush)N)r>)
�__name__�
__module__�__qualname__�__doc__r�context_api�Contextr6r:r=�int�boolrBr2r2r2r5r,Hs��
r,c@sreZdZdZdd�Zedd�dd�Zddeej	dd	�d
d�Z
ddd
�dd�Zdd�dd�Zde
ed�dd�ZdS)�SynchronousMultiSpanProcessorz�Implementation of class:`SpanProcessor` that forwards all received
    events to a list of span processors sequentially.

    The underlying span processors are called in sequential order as they were
    added.
    cCsd|_t��|_dS)Nr2)�_span_processors�	threading�Lock�_lockr<r2r2r5�__init__�sz&SynchronousMultiSpanProcessor.__init__N��span_processorr1cCs:|j� |j|f7_Wd�n1s,0YdS�z:Adds a SpanProcessor to the list handled by this instance.N�rOrL�r4rRr2r2r5�add_span_processor�sz0SynchronousMultiSpanProcessor.add_span_processorr-r.cCs|jD]}|j||d�qdS)N�r0)rLr6)r4r/r0�spr2r2r5r6�s
z&SynchronousMultiSpanProcessor.on_startr7r8cCs|jD]}|�|�qdS�N)rLr:)r4r/rXr2r2r5r:�s
z$SynchronousMultiSpanProcessor.on_endr;cCs|jD]}|��qdS)z7Sequentially shuts down all underlying span processors.N)rLr=)r4rXr2r2r5r=�s
z&SynchronousMultiSpanProcessor.shutdownr>r?cCsJt�|d}|jD]0}t�}||kr,dS|�||d�sdSqdS)a�Sequentially calls force_flush on all underlying
        :class:`SpanProcessor`

        Args:
            timeout_millis: The maximum amount of time over all span processors
                to wait for spans to be exported. In case the first n span
                processors exceeded the timeout followup span processors will be
                skipped.

        Returns:
            True if all span processors flushed their spans within the
            given timeout, False otherwise.
        i@BFT)rrLrB)r4r@Zdeadline_nsrXZcurrent_time_nsr2r2r5rB�s
z)SynchronousMultiSpanProcessor.force_flush)N)r>)rCrDrErFrPr,rVrrGrHr6r:r=rIrJrBr2r2r2r5rK|s��rKc@s�eZdZdZded�dd�Zedd�dd	�Zeeged
fe	e	d�dd
�Z
ddeej
dd�dd�Zddd�dd�Zdd�dd�Zdeed�dd�ZdS) �ConcurrentMultiSpanProcessora�Implementation of :class:`SpanProcessor` that forwards all received
    events to a list of span processors in parallel.

    Calls to the underlying span processors are forwarded in parallel by
    submitting them to a thread pool executor and waiting until each span
    processor finished its work.

    Args:
        num_threads: The number of threads managed by the thread pool executor
            and thus defining how many span processors can work in parallel.
    �)�num_threadscCs$d|_t��|_tjj|d�|_dS)Nr2)�max_workers)rLrMrNrO�
concurrent�futures�ThreadPoolExecutor�	_executor)r4r\r2r2r5rP�s
z%ConcurrentMultiSpanProcessor.__init__NrQcCs:|j� |j|f7_Wd�n1s,0YdSrSrTrUr2r2r5rV�sz/ConcurrentMultiSpanProcessor.add_span_processor).N)�func�args�kwargscOsNg}|jD],}|jj||�g|�Ri|��}|�|�q
|D]}|��q<dSrY)rLra�submit�append�result)r4rbrcrdr_rX�futurer2r2r5�_submit_and_await�s
z.ConcurrentMultiSpanProcessor._submit_and_awaitr-r.cCs|jdd�||d�dS)NcSs|jSrY)r6�rXr2r2r5�<lambda>��z7ConcurrentMultiSpanProcessor.on_start.<locals>.<lambda>rW�rir3r2r2r5r6�s
�z%ConcurrentMultiSpanProcessor.on_startr7r8cCs|�dd�|�dS)NcSs|jSrY)r:rjr2r2r5rk�rlz5ConcurrentMultiSpanProcessor.on_end.<locals>.<lambda>rmr9r2r2r5r:�sz#ConcurrentMultiSpanProcessor.on_endr;cCs|�dd��dS)z6Shuts down all underlying span processors in parallel.cSs|jSrY)r=rjr2r2r5rk�rlz7ConcurrentMultiSpanProcessor.shutdown.<locals>.<lambda>Nrmr<r2r2r5r=�sz%ConcurrentMultiSpanProcessor.shutdownr>r?cCshg}|jD]}|j�|j|�}|�|�q
|d}tj�||�\}}|rLdS|D]}|��sPdSqPdS)aFCalls force_flush on all underlying span processors in parallel.

        Args:
            timeout_millis: The maximum amount of time to wait for spans to be
                exported.

        Returns:
            True if all span processors flushed their spans within the given
            timeout, False otherwise.
        g@�@FT)	rLrarerBrfr^r_�waitrg)r4r@r_rXrhZtimeout_secZdone_futuresZnot_done_futuresr2r2r5rB�s
z(ConcurrentMultiSpanProcessor.force_flush)r[)N)r>)rCrDrErFrIrPr,rVr	rrirrGrHr6r:r=rJrBr2r2r2r5rZ�s ���	rZc@sbeZdZdeeedd�dd�Zeed�dd��Zeed�dd	��Z	ee
jej
d�d
d���ZdS)
�	EventBaseN)�name�	timestampr1cCs"||_|durt�|_n||_dSrY)�_namer�
_timestamp)r4rprqr2r2r5rP
s
zEventBase.__init__r;cCs|jSrY�rrr<r2r2r5rpszEventBase.namecCs|jSrY)rsr<r2r2r5rqszEventBase.timestampcCsdSrYr2r<r2r2r5�
attributesszEventBase.attributes)N)rCrDrE�strrrIrP�propertyrprq�abc�abstractmethodr)�
Attributesrur2r2r2r5rosrocsTeZdZdZddefeejee	ee	dd��fdd�
Z
eejd�dd��Z�Z
S)	�EventaA text annotation with a set of attributes. The attributes of an event
    are immutable.

    Args:
        name: Name of the event.
        attributes: Attributes of the event.
        timestamp: Timestamp of the event. If `None` it will filled
            automatically.
    N)rprurq�limitr1cst��||�||_dSrY)�superrP�_attributes)r4rprurqr|��	__class__r2r5rP-szEvent.__init__r;cCs|jSrY)r~r<r2r2r5ru7szEvent.attributes)rCrDrErF�(_DEFAULT_OTEL_SPAN_ATTRIBUTE_COUNT_LIMITrvr)rzrrIrPrwru�
__classcell__r2r2rr5r{"s
��
r{cs�fdd�}|S)Ncsfd}|j�6|jdur.�|g|�Ri|��nd}Wd�n1sF0Y|rbt�d�j�dS)NFTz"Tried calling %s on an ended span.)rO�	_end_time�logger�warningrC)r4rcrdZ
already_ended�rbr2r5�wrapper=s
"z"_check_span_ended.<locals>.wrapperr2)rbr�r2r�r5�_check_span_ended<sr�c@seZdZdZddde�i�dddejjde	e
j�dddf
eej
eej
eejeeeejejee	eeeeedd�dd�Zeed�dd	��Zeed�d
d��Zeed�dd
��Zeed�dd��Zdd�Zedd��Zeejd�dd��Zeeej
d�dd��Z eeed�dd��Z!eeed�dd��Z"eej	d�dd��Z#eejd�dd��Z$eeed�d d!��Z%eeejd�d"d#��Z&eed�d$d%��Z'ee(d&d'd(�ed�d)d*���Z)eed�d+d,��Z*d8d.d/�Z+e,d0d1��Z-e,d2d3��Z.e,d4d5��Z/e,d6d7��Z0dS)9r7z,Provides read-only access to span attributesNr2)rpr�parent�resourceru�events�links�kind�instrumentation_info�status�
start_time�end_time�instrumentation_scoper1cCsR||_||_||_|	|_|
|_||_||_||_||_||_	||_
||_|
|_dSrY)
rr�_context�_kind�_instrumentation_info�_instrumentation_scope�_parent�_start_timer�r~�_events�_links�	_resource�_status)r4rprr�r�rur�r�r�r�r�r�r�r�r2r2r5rPNszReadableSpan.__init__r;cCs|jr|jjSdS�Nr)r~�droppedr<r2r2r5�dropped_attributeslszReadableSpan.dropped_attributescCs|jr|jjSdSr�)r�r�r<r2r2r5�dropped_eventsrszReadableSpan.dropped_eventscCs|jr|jjSdSr�)r�r�r<r2r2r5�
dropped_linksxszReadableSpan.dropped_linkscCs|jSrYrtr<r2r2r5rp~szReadableSpan.namecCs|jSrY�r�r<r2r2r5�get_span_context�szReadableSpan.get_span_contextcCs|jSrYr�r<r2r2r5r�szReadableSpan.contextcCs|jSrY)r�r<r2r2r5r��szReadableSpan.kindcCs|jSrY)r�r<r2r2r5r��szReadableSpan.parentcCs|jSrY)r�r<r2r2r5r��szReadableSpan.start_timecCs|jSrY�r�r<r2r2r5r��szReadableSpan.end_timecCs|jSrY)r�r<r2r2r5r��szReadableSpan.statuscCs
t|j�SrY)rr~r<r2r2r5ru�szReadableSpan.attributescCstdd�|jD��S)Ncss|]
}|VqdSrYr2)�.0�eventr2r2r5�	<genexpr>�rlz&ReadableSpan.events.<locals>.<genexpr>)�tupler�r<r2r2r5r��szReadableSpan.eventscCstdd�|jD��S)Ncss|]
}|VqdSrYr2)r��linkr2r2r5r��rlz%ReadableSpan.links.<locals>.<genexpr>)r�r�r<r2r2r5r��szReadableSpan.linkscCs|jSrY�r�r<r2r2r5r��szReadableSpan.resourcez1.11.1z$You should use instrumentation_scope)�version�reasoncCs|jSrY)r�r<r2r2r5r��sz!ReadableSpan.instrumentation_infocCs|jSrY)r�r<r2r2r5r��sz"ReadableSpan.instrumentation_scope�cCsdd}|jdurVt|jt�r6|jj}dt�|j���}n t|jt�rVdt�|jj���}d}|jrlt	�
|j�}d}|jr�t	�
|j�}|jdur�t
�}t|jjj�|d<|jjr�|jj|d<t
�}|j|d<|�|j�|d<t|j�|d<||d<||d<||d	<|jdu�r||d
<|�|j�|d<|�|j�|d<|�|j�|d
<t�|j���|d<tj ||d�S)N�0x�status_code�descriptionrprr��	parent_idr�r�r�rur�r�r�)�indent)!r��
isinstancer-r�	trace_api�format_span_id�span_idr&r�r�
ns_to_iso_strr�r�rrvr�rpr�rr�_format_contextr�r��_format_attributesr~�_format_eventsr��
_format_linksr��json�loadsr��to_json�dumps)r4r�r��ctxr�r�r�Zf_spanr2r2r5r��s@


zReadableSpan.to_jsoncCsDt�}dt�|j���|d<dt�|j���|d<t|j�|d<|S)Nr��trace_idr��trace_state)rr�Zformat_trace_idr�r�r��reprr�)rZx_ctxr2r2r5r��s
zReadableSpan._format_contextcCs&t|t�r|jSt|t�r"|��S|SrY)r�r�_dictr�copy)rur2r2r5r��s


zReadableSpan._format_attributescCsLg}|D]>}t�}|j|d<t�|j�|d<t�|j�|d<|�|�q|S)Nrprqru)	rrprr�rqr-r�rurf)r�Zf_eventsr�Zf_eventr2r2r5r��s
���zReadableSpan._format_eventscCsBg}|D]4}t�}t�|j�|d<t�|j�|d<|�|�q|S)Nrru)rr-r�rr�rurf)r�Zf_linksr�Zf_linkr2r2r5r��s"������zReadableSpan._format_links)r�)1rCrDrErFr�creater��SpanKind�INTERNALr'r(�UNSETrvr&rr)rzr
r{�Linkr$rIr%rPrwr�r�r�rpr�rr�r�r�r�r�rur�r�r�rr�r�r��staticmethodr�r�r�r�r2r2r2r5r7Ks���


(


r7c
@s�eZdZdZdZdeeeeeeeeeeeeeeeed�dd�Zdd�Ze	d
eee
eeeed	�d
d��ZdS)�
SpanLimitsa/	The limits that should be enforce on recorded data such as events, links, attributes etc.

    This class does not enforce any limits itself. It only provides an a way read limits from env,
    default values and from user provided arguments.

    All limit arguments must be either a non-negative integer, ``None`` or ``SpanLimits.UNSET``.

    - All limit arguments are optional.
    - If a limit argument is not set, the class will try to read its value from the corresponding
      environment variable.
    - If the environment variable is not set, the default value, if any, will be used.

    Limit precedence:

    - If a model specific limit is set, it will be used.
    - Else if the corresponding global limit is set, it will be used.
    - Else if the model specific limit has a default value, the default value will be used.
    - Else if the global limit has a default value, the default value will be used.

    Args:
        max_attributes: Maximum number of attributes that can be added to a span, event, and link.
            Environment variable: OTEL_ATTRIBUTE_COUNT_LIMIT
            Default: {_DEFAULT_ATTRIBUTE_COUNT_LIMIT}
        max_events: Maximum number of events that can be added to a Span.
            Environment variable: OTEL_SPAN_EVENT_COUNT_LIMIT
            Default: {_DEFAULT_SPAN_EVENT_COUNT_LIMIT}
        max_links: Maximum number of links that can be added to a Span.
            Environment variable: OTEL_SPAN_LINK_COUNT_LIMIT
            Default: {_DEFAULT_SPAN_LINK_COUNT_LIMIT}
        max_span_attributes: Maximum number of attributes that can be added to a Span.
            Environment variable: OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT
            Default: {_DEFAULT_OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT}
        max_event_attributes: Maximum number of attributes that can be added to an Event.
            Default: {_DEFAULT_OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT}
        max_link_attributes: Maximum number of attributes that can be added to a Link.
            Default: {_DEFAULT_OTEL_LINK_ATTRIBUTE_COUNT_LIMIT}
        max_attribute_length: Maximum length an attribute value can have. Values longer than
            the specified length will be truncated.
        max_span_attribute_length: Maximum length a span attribute value can have. Values longer than
            the specified length will be truncated.
    ���N��max_attributes�
max_events�	max_links�max_span_attributes�max_event_attributes�max_link_attributes�max_attribute_length�max_span_attribute_lengthc	
Cs�|�|tt�|_|�|tt�|_|�|t�}	|	dur8|	nt|_	|�|t
|	durR|	nt�|_|�|t
|	durn|	nt�|_|�|t|	dur�|	nt�|_|�|t�|_|�|t|j�|_dSrY)�_from_env_if_absentr�$_DEFAULT_OTEL_SPAN_EVENT_COUNT_LIMITr�r�#_DEFAULT_OTEL_SPAN_LINK_COUNT_LIMITr�r�#_DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMITr�rr�r�r�)_DEFAULT_OTEL_EVENT_ATTRIBUTE_COUNT_LIMITr�r�(_DEFAULT_OTEL_LINK_ATTRIBUTE_COUNT_LIMITr�rr�rr�)
r4r�r�r�r�r�r�r�r�Zglobal_max_attributesr2r2r5rP=s^�����������	��zSpanLimits.__init__cCsHt|�j�d|j�d|j�d|j�d|j�d|j�d|j�d|j�d�S)	Nz(max_span_attributes=z, max_events_attributes=z, max_link_attributes=z, max_attributes=z
, max_events=z, max_links=z, max_attribute_length=�))	�typerCr�r�r�r�r�r�r�r<r2r2r5�__repr__�szSpanLimits.__repr__)�value�env_var�defaultr1cCs�||jkrdSd}|durv|tvr&|St�|d�����}|tkrFdSzt|�}Wn"tytt|�||���Yn0|dkr�t|�||���|S)Nz-{0} must be a non-negative integer but got {}r+r)	r�r�get�strip�lower�_ENV_VALUE_UNSETrI�
ValueError�format)�clsr�r�r��err_msgZ	str_valuer2r2r5r��s 
zSpanLimits._from_env_if_absent)NNNNNNNN)N)rCrDrErFr�rrIrPr��classmethodrvr�r2r2r2r5r�s6*��C��r�r�cs�eZdZdZ�fdd�Zddde�i�dddejj	e
�dddedfeej
eej
eejdeejeeeejeje
eeeedd��fdd	�
Zd
d�Zdd
�Zdd�Zdd�Zeeejfdd�dd�Z eejdd�dd�Z!e"e#dd�dd��Z$d6eejee%dd�dd�Z&e'd�dd �Z(d7ee%ee)j*dd!�d"d#�Z+d8ee%dd$�d%d&�Z,e"edd'�d(d)��Z-ed�d*d+�Z.e"d9e/j0e1e2fe/jedd,�d-d.��Z3ee4e5ee5ee6dd/��fd0d1�Z7d:e8ejee%edd3�d4d5�Z9�Z:S);r-a?See `mysql.opentelemetry.trace.Span`.

    Users should create `Span` objects via the `Tracer` instead of this
    constructor.

    Args:
        name: The name of the operation this span represents
        context: The immutable span context
        parent: This span's parent's `mysql.opentelemetry.trace.SpanContext`, or
            None if this is a root span
        sampler: The sampler used to create this span
        trace_config: TODO
        resource: Entity producing telemetry
        attributes: The span's attributes to be exported
        events: Timestamped events to be exported
        links: Links to other spans to be exported
        span_processor: `SpanProcessor` to invoke when starting and ending
            this `Span`.
        limits: `SpanLimits` instance that was passed to the `TracerProvider`
    cs|turtd��t��|�S)Nz'Span must be instantiated via a tracer.)r-�	TypeErrorr}�__new__)r�rcrdrr2r5r��szSpan.__new__Nr2T)rprr��sampler�trace_configr�rur�r�r�rRr��record_exception�set_status_on_exceptionr�r1c	s�t�j||||
|||d�||_||_|
|_||_||_||_t�	�|_
t|jj|d|jj
d�|_|��|_|r�|D]*}t|jj|j|jjd�|_|j�|�qt|	dur�|��|_n6|	D]}t|jj|j|jjd�|_q�t�|jj|	�|_dS)N)rprr�r�r�r�r�F)Z	immutable�
max_value_len�r�)r}rPZ_samplerZ
_trace_config�_record_exception�_set_status_on_exception�_span_processor�_limitsrMrNrOrr�r�r~�_new_eventsr�r�rur�rf�
_new_linksr�r�r#Zfrom_seqr�)r4rprr�r�r�r�rur�r�r�rRr�r�r��limitsr�r�r�rr2r5rP�sP�	
�
��
z
Span.__init__cCs t|�j�d|j�d|j�d�S)Nz(name="z", context=r�)r�rCrrr�r<r2r2r5r�sz
Span.__repr__cCst|jj�SrY)r#r�r�r<r2r2r5r�szSpan._new_eventscCst|jj�SrY)r#r�r�r<r2r2r5r�szSpan._new_linkscCs|jSrYr�r<r2r2r5r�szSpan.get_span_context)rur1cCsj|j�P|jdur,t�d�Wd�dS|��D]\}}||j|<q4Wd�n1s\0YdS)Nz Setting attribute on ended span.)rOr�r�r��itemsr~)r4ru�keyr�r2r2r5�set_attributess

zSpan.set_attributes)r�r�r1cCs|�||i�SrY)r�)r4r�r�r2r2r5�
set_attribute$szSpan.set_attribute)r�r1cCs|j�|�dSrY)r�rf)r4r�r2r2r5�
_add_event'szSpan._add_event)rprurqr1cCs.t|jj||jjd�}|�t|||d��dS)Nr��rprurq)rr�r�r�r�r{)r4rprurqr2r2r5�	add_event+s���zSpan.add_eventr;cCs<t|j|j|j|j|j|j|j|j|j	|j
|j|j|j
d�
S)N)
rprr�r�rur�r�r�r�r�r�r�r�)r7rrr�r�r�r~r�r�r�r�r�r�r�r�r<r2r2r5�_readable_span>s�zSpan._readable_span)r�r0r1cCsr|j�H|jdur,t�d�Wd�dS|dur8|nt�|_Wd�n1sT0Y|jj||d�dS)Nz"Calling start() on a started span.rW)rOr�r�r�rr�r6)r4r�r0r2r2r5�startOs

2z
Span.start)r�r1cCs�|j�Z|jdurtd��|jdur>t�d�Wd�dS|durJ|nt�|_Wd�n1sf0Y|j�|�	��dS)Nz$Calling end() on a not started span.zCalling end() on an ended span.)
rOr��RuntimeErrorr�r�r�rr�r:r)r4r�r2r2r5�end\s


2zSpan.end)rpr1cCs
||_dSrYrt)r4rpr2r2r5�update_namehszSpan.update_namecCs
|jduSrYr�r<r2r2r5�is_recordinglszSpan.is_recording)r�r�r1cCs�t|t�rJ|jr|jjtjus*|jtjur.dS|durBt�d|�||_n8t|t�r�|jrh|jjtjusr|tjurvdSt||�|_dS)NzJDescription %s ignored. Use either `Status` or `(StatusCode, Description)`)	r�r'r�r�r(�OKr�r�r�)r4r�r�r2r2r5�
set_statusos.
��
��
���zSpan.set_status)�exc_type�exc_val�exc_tbr1cs^|durJ|��rJ|jr$|j|dd�|jrJ|�ttj|j�d|��d��t	��
|||�dS)z3Ends context manager and calls `end` on the `Span`.NT)�	exception�escapedz: )r�r�)rr�r�r�r	r'r(�ERRORrCr}�__exit__)r4r
rrrr2r5r�s��z
Span.__exit__F)r
rurqrr1cCs`zt��}Wnty"d}Yn0|jjt|�|t|�d�}|rL|�|�|jd||d�dS)z%Records an exception as a span event.z+Exception occurred on stacktrace formatting)zexception.typezexception.messagezexception.stacktracezexception.escapedr
rN)�	traceback�
format_exc�	Exceptionr�rCrv�updater)r4r
rurqrZ
stacktracer~r2r2r5r��s
�
zSpan.record_exception)NN)NN)N)N)NNF);rCrDrErFr�rr�r�r�r�r,�_UnsetLimitsrvr&rr �Samplerr)rzr
r{r�r$rJr%rPr�r�r�r�r
ZAttributeValuer�r�r�ror�rIrr7rrGrHrrrr�typingrr'r(r	r�
BaseExceptionrrrr�r�r2r2rr5r-�s�
��>	����
��
���r-c@seZdZdZdS)�_Spanz�Protected implementation of `mysql.opentelemetry.trace.Span`.

    This constructor exists to prevent the instantiation of the `Span` class
    by other mechanisms than through the `Tracer`.
    N)rCrDrErFr2r2r2r5r�src
@s�eZdZdZejeeee	fe
eee
dd�dd�Zedejjddddddfeeejejejeejeeeeeeejd�
d	d
��Zdejjdddddfeeejejejeejeeeeejd�	dd
�Z dS)�Tracerz'See `mysql.opentelemetry.trace.Tracer`.N)r�r�rR�id_generatorr��span_limitsr�r1cCs.||_||_||_||_||_||_||_dSrY)r�r�rRrr��_span_limitsr�)r4r�r�rRrr�rr�r2r2r5rP�szTracer.__init__r2T)
rprr�rur�r�r�r��end_on_exitr1c

csV|j||||||||d�}
tj|
|	||d��}|VWd�n1sH0YdS)N)rprr�rur�r�r�r�)rr�r�)�
start_spanr�Zuse_span)r4rprr�rur�r�r�r�rr/�span_contextr2r2r5�start_as_current_span�s$
�
�zTracer.start_as_current_span)	rprr�rur�r�r�r�r1c	Cst�|���}	|	dur*t|	tj�s*td��|	dus8|	jsHd}	|j��}
n|	j	}
|j
�||
||||�}|j�
�r|t�tjj�nt�tjj�}tj|
|j��d||jd�}
|j��r�t||
|	|j
|j|j��|j|||j|||j|jd�}|j||d�ntj|
d�}|S)Nz2parent_span_context must be a SpanContext or None.F)Z	is_remote�trace_flagsr�)rprr�r�r�rurRr�r�r�r�r�r�r�)r�r0)r)r�Zget_current_spanr�r�r&r�Zis_validrZgenerate_trace_idr�r�Z
should_sampleZdecisionZ
is_sampledZ
TraceFlagsZSAMPLED�DEFAULTZgenerate_span_idr�rrr�rur�rRr�rr�rZNonRecordingSpan)r4rprr�rur�r�r�r�Zparent_span_contextr�Zsampling_resultr"r r/r2r2r5r�sV
�����	
�zTracer.start_span)!rCrDrErFr rrrrKrZr!r$r�r%rPrr�r�r�rvrrGrHr)rzr
r�rIrJrr-r!rr2r2r2r5r�sf����!��rc@s�eZdZdZde�i�ddddfejeee	e
efee
d�dd�Zeed�dd	��Zdeejeejed
d�dd
�Zedd�dd�Zdd�Zdeed�dd�ZdS)�TracerProviderz/See `mysql.opentelemetry.trace.TracerProvider`.NT)r�r��shutdown_on_exit�active_span_processorrrcCsd|pt�|_|durt�|_n||_||_|s6t��}||_|pDt�|_	d|_
|r`t�|j
�|_
dSrY)rK�_active_span_processorr"rr�r Z_get_from_env_or_defaultr�r�r�_atexit_handler�atexit�registerr=)r4r�r�r%r&rrr2r2r5rPIs�
zTracerProvider.__init__r;cCs|jSrYr�r<r2r2r5r�eszTracerProvider.resourceztrace_api.Tracer)�instrumenting_module_name�instrumenting_library_version�
schema_urlr1cCs`|sd}t�d�|durd}tddtdd�t|||�}t|j|j|j|j	||j
t|||��S)Nr+z+get_tracer called with missing module name.�ignorezoCall to deprecated method __init__. \(You should use InstrumentationScope\) -- Deprecated since version 1.11.1.zmysql.opentelemetry.sdk.trace)�message�category�module)r��errorr�DeprecationWarningr$rr�r�r'rrr%)r4r+r,r-r�r2r2r5�
get_traceris:
�
���zTracerProvider.get_tracerrQcCs|j�|�dS)z�Registers a new :class:`SpanProcessor` for this `TracerProvider`.

        The span processors are invoked in the same order they are registered.
        N)r'rVrUr2r2r5rV�sz!TracerProvider.add_span_processorcCs*|j��|jdur&t�|j�d|_dS)z;Shut down the span processors added to the tracer provider.N)r'r=r(r)�
unregisterr<r2r2r5r=�s

zTracerProvider.shutdownr>r?cCs|j�|�S)a�Requests the active span processor to process all spans that have not
        yet been processed.

        By default force flush is called sequentially on all added span
        processors. This means that span processors further back in the list
        have less time to flush their spans.
        To have span processors flush their spans in parallel it is possible to
        initialize the tracer provider with an instance of
        `ConcurrentMultiSpanProcessor` at the cost of using multiple threads.

        Args:
            timeout_millis: The maximum amount of time to wait for spans to be
                processed.

        Returns:
            False if the timeout is exceeded, True otherwise.
        )r'rBrAr2r2r5rB�szTracerProvider.force_flush)NN)r>)rCrDrErFrr�r rrJrrKrZr!r�rPrwr�rvrrr4r,rVr=rIrBr2r2r2r5r$Fs<�����*
r$)_rxr)�concurrent.futuresr^r��loggingrMrr�collectionsr�
contextlibr�osr�timerr)rrrr	r
rrr
rrr�warningsrrZmysql.opentelemetryrrGrr�Zmysql.opentelemetry.attributesrZmysql.opentelemetry.sdkrZ-mysql.opentelemetry.sdk.environment_variablesrrrrrrrrZ!mysql.opentelemetry.sdk.resourcesrZmysql.opentelemetry.sdk.tracer Z*mysql.opentelemetry.sdk.trace.id_generatorr!r"Zmysql.opentelemetry.sdk.utilr#Z,mysql.opentelemetry.sdk.util.instrumentationr$r%Zmysql.opentelemetry.tracer&Z mysql.opentelemetry.trace.statusr'r(Zmysql.opentelemetry.util�	getLoggerrCr�r�r�r�r�r�r�r�r,rKrZ�ABCror{r�r7r�r�rr�ZSPAN_ATTRIBUTE_COUNT_LIMITr-rrr$r2r2r2r5�<module>s�,(

4>RF�
��