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/export/__pycache__/__init__.cpython-39.pyc
a

�,�hOD�@s<ddlZddlZddlZddlZddlZddlZddlmZddlmZm	Z	ddl
mZddlmZddl
mZmZmZmZmZddlmZmZmZmZddlmZmZmZdd	lmZd
ZdZdZ d
Z!dZ"e�#e$�Z%Gdd�de�Z&Gdd�d�Z'Gdd�de�Z(Gdd�d�Z)e�Z*Gdd�de�Z+Gdd�de'�Z,dS)�N)�Enum)�environ�linesep)�time_ns)�Optional)�_SUPPRESS_INSTRUMENTATION_KEY�Context�attach�detach�	set_value)�OTEL_BSP_EXPORT_TIMEOUT�OTEL_BSP_MAX_EXPORT_BATCH_SIZE�OTEL_BSP_MAX_QUEUE_SIZE�OTEL_BSP_SCHEDULE_DELAY)�ReadableSpan�Span�
SpanProcessor)�Oncei�i�0uiz:Unable to parse value for %s as integer. Defaulting to %s.c@seZdZdZdZdS)�SpanExportResultr�N)�__name__�
__module__�__qualname__�SUCCESS�FAILURE�rr�`/opt/nydus/tmp/pip-target-wkfpz8uv/lib64/python/mysql/opentelemetry/sdk/trace/export/__init__.pyr6src@sFeZdZdZejedd�dd�Zdd�dd	�Zde	e
d�dd
�ZdS)�SpanExportera)Interface for exporting spans.

    Interface to be implemented by services that want to export spans recorded
    in their own format.

    To export data this MUST be registered to the :class`mysql.opentelemetry.sdk.trace.Tracer` using a
    `SimpleSpanProcessor` or a `BatchSpanProcessor`.
    r��spans�returncCsdS)z�Exports a batch of telemetry data.

        Args:
            spans: The list of `mysql.opentelemetry.trace.Span` objects to be exported

        Returns:
            The result of the export
        Nr)�selfr rrr�exportEszSpanExporter.exportN�r!cCsdS)zLShuts down the exporter.

        Called when the SDK is shut down.
        Nr�r"rrr�shutdownOszSpanExporter.shutdownr��timeout_millisr!cCsdS)z�Hint to ensure that the export of any spans the exporter has received
        prior to the call to ForceFlush SHOULD be completed as soon as possible, preferably
        before returning from this method.
        Nr�r"r(rrr�force_flushUszSpanExporter.force_flush)r)rrr�__doc__�typing�Sequencerr#r&�int�boolr*rrrrr;s	
rc@sheZdZdZed�dd�Zdeeje	dd�dd�Z
edd	�d
d�Zdd�d
d�Z
deed�dd�ZdS)�SimpleSpanProcessorz�Simple SpanProcessor implementation.

    SimpleSpanProcessor is an implementation of `SpanProcessor` that
    passes ended spans directly to the configured `SpanExporter`.
    ��
span_exportercCs
||_dS�Nr1)r"r2rrr�__init__cszSimpleSpanProcessor.__init__N��span�parent_contextr!cCsdSr3r�r"r6r7rrr�on_startfszSimpleSpanProcessor.on_start�r6r!cCsX|jjjsdStttd��}z|j�|f�WntyJt	�
d�Yn0t|�dS)NTzException while exporting Span.)�context�trace_flags�sampledr	rrr2r#�	Exception�logger�	exceptionr
)r"r6�tokenrrr�on_endks
zSimpleSpanProcessor.on_endr$cCs|j��dSr3)r2r&r%rrrr&vszSimpleSpanProcessor.shutdownrr'cCsdS�NTrr)rrrr*yszSimpleSpanProcessor.force_flush)N)r)rrrr+rr4rr,rrr9rrBr&r.r/r*rrrrr0\s�
�r0c@s eZdZdZddgZdd�ZdS)�
_FlushRequestz?Represents a request for the BatchSpanProcessor to flush spans.�event�	num_spanscCst��|_d|_dS)Nr)�	threading�EventrErFr%rrrr4�s
z_FlushRequest.__init__N)rrrr+�	__slots__r4rrrrrD~srDc@s"eZdZdZd-eeeeed�dd�Zd.ee	j
edd�dd�Ze
dd	�d
d�Zdd
�Zdd�Ze	j
ed�dd�Zee	j
ed�dd��Zed�dd�Ze	j
ed�dd�Zed�dd�Zdd�Zd/eed�dd �Zdd�d!d"�Zed#d$��Zed%d&��Zed'd(��Zed)d*��Zed+d,��Z dS)0�BatchSpanProcessora�Batch span processor implementation.

    `BatchSpanProcessor` is an implementation of `SpanProcessor` that
    batches ended spans and pushes them to the configured `SpanExporter`.

    `BatchSpanProcessor` is configurable with the following environment
    variables which correspond to constructor parameters:

    - :envvar:`OTEL_BSP_SCHEDULE_DELAY`
    - :envvar:`OTEL_BSP_MAX_QUEUE_SIZE`
    - :envvar:`OTEL_BSP_MAX_EXPORT_BATCH_SIZE`
    - :envvar:`OTEL_BSP_EXPORT_TIMEOUT`
    N)r2�max_queue_size�schedule_delay_millis�max_export_batch_size�export_timeout_milliscCs�|durt��}|dur t��}|dur0t��}|dur@t��}t�|||�||_t�g|�|_	t
jd|jdd�|_
t
�t
���|_d|_||_||_||_||_d|_d|_dg|j|_|j
��ttd�r�tj|jd�t��|_dS)N�OtelBatchSpanProcessorT��name�target�daemonF�register_at_fork)�after_in_child) rJ�_default_max_queue_size�_default_schedule_delay_millis�_default_max_export_batch_size�_default_export_timeout_millis�_validate_argumentsr2�collections�deque�queuerG�Thread�worker�
worker_thread�	Condition�Lock�	condition�_flush_requestrLrMrKrN�done�_spans_dropped�
spans_list�start�hasattr�osrT�_at_fork_reinit�getpid�_pid)r"r2rKrLrMrNrrrr4�sD����

�zBatchSpanProcessor.__init__r5cCsdSr3rr8rrrr9�szBatchSpanProcessor.on_startr:cCs�|jrt�d�dS|jjjs"dS|jt��kr<t	�
|j�t|j
�|jkrb|jsbt�d�d|_|j
�|�t|j
�|jkr�|j�|j��Wd�n1s�0YdS)Nz Already shutdown, dropping span.z,Queue is full, likely spans will be dropped.T)rer?�warningr;r<r=rmrjrl�_BSP_RESET_ONCEZdo_oncerk�lenr]rKrf�
appendleftrMrc�notify)r"r6rrrrB�s


zBatchSpanProcessor.on_endcCsFt�t���|_|j��tjd|jdd�|_|j�	�t
��|_dS)NrOTrP)
rGrarbrcr]�clearr^r_r`rhrjrlrmr%rrrrk�s
�
z"BatchSpanProcessor._at_fork_reinitcCsX|jd}d}|j�s|j��|jr4Wd��q|��}t|j�|jkr�|dur�|j�|�|��}|js�|jd}|�|�d}Wd�q|jr�Wd��qWd�n1s�0Yt	�}|�
|�t	�}||d}|jd|}|�|�d}q|j�|��}Wd�n1�s.0Y|��|�|�|�|�dS)N�@�@ge��A)rLrerc�_get_and_unset_flush_requestrpr]rM�wait�_notify_flush_request_finishedr�_export�_drain_queue)r"�timeout�
flush_requestrh�end�durationZshutdown_flush_requestrrrr_�s@
��

.

(
zBatchSpanProcessor.workerr$cCs$|j}d|_|dur t|j�|_|S)ztReturns the current flush request and makes it invisible to the
        worker thread for subsequent calls.
        N)rdrpr]rF)r"r{rrrrus
z/BatchSpanProcessor._get_and_unset_flush_request�r{cCs|dur|j��dS)zzNotifies the flush initiator(s) waiting on the given request/event
        that the flush operation was finished.
        N)rE�setr~rrrrw*sz1BatchSpanProcessor._notify_flush_request_finishedcCs|jdurt�|_|jS)a�Either returns the current active flush event or creates a new one.

        The flush event will be visible and read by the worker thread before an
        export operation starts. Callers of a flush operation may wait on the
        returned event to be notified when the flush/export operation was
        finished.

        This method is not thread-safe, i.e. callers need to take care about
        synchronization/locking.
        N)rdrDr%rrr�_get_or_create_flush_request4s
z/BatchSpanProcessor._get_or_create_flush_requestcCs<|s|��dS|j}|jr8|��}||8}|dkrq8qdS)aUExports spans considering the given flush_request.

        In case of a given flush_requests spans are exported in batches until
        the number of exported spans reached or exceeded the number of spans in
        the flush request.
        In no flush_request was given at most max_export_batch_size spans are
        exported.
        Nr)�
_export_batchrFr])r"r{rFZnum_exportedrrrrxCs	zBatchSpanProcessor._exportcCs�d}||jkr.|jr.|j��|j|<|d7}qtttd��}z|j�|jd|��Wnt	yrt
�d�Yn0t|�t
|�D]}d|j|<q�|S)zfExports at most max_export_batch_size spans and returns the number of
        exported spans.
        rrTNz%Exception while exporting Span batch.)rMr]�poprgr	rrr2r#r>r?r@r
�range)r"�idxrA�indexrrrr�Xs
z BatchSpanProcessor._export_batchcCs|jr|��qdS)z�Export all elements until queue is empty.

        Can only be called from the worker thread context because it invokes
        `export` that is not thread safe.
        N)r]r�r%rrrrypszBatchSpanProcessor._drain_queuer'cCs||dur|j}|jr"t�d�dS|j�"|��}|j��Wd�n1sP0Y|j�|d�}|sxt�d�|S)Nz1Already shutdown, ignoring call to force_flush().Trtz&Timeout was exceeded in force_flush().)	rNrer?rnrcr��
notify_allrErv)r"r(r{�retrrrr*ys
(
zBatchSpanProcessor.force_flushcCsNd|_|j�|j��Wd�n1s,0Y|j��|j��dSrC)rercr�r`�joinr2r&r%rrrr&�s
(
zBatchSpanProcessor.shutdowncCs<ztt�tt��WSty6t�ttt�tYS0dSr3)	r.r�getr�_DEFAULT_MAX_QUEUE_SIZE�
ValueErrorr?r@� _ENV_VAR_INT_VALUE_ERROR_MESSAGErrrrrV�s�z*BatchSpanProcessor._default_max_queue_sizecCs<ztt�tt��WSty6t�ttt�tYS0dSr3)	r.rr�r�_DEFAULT_SCHEDULE_DELAY_MILLISr�r?r@r�rrrrrW�s
��z1BatchSpanProcessor._default_schedule_delay_milliscCs<ztt�tt��WSty6t�ttt�tYS0dSr3)	r.rr�r
�_DEFAULT_MAX_EXPORT_BATCH_SIZEr�r?r@r�rrrrrX�s���z1BatchSpanProcessor._default_max_export_batch_sizecCs<ztt�tt��WSty6t�ttt�tYS0dSr3)	r.rr�r�_DEFAULT_EXPORT_TIMEOUT_MILLISr�r?r@r�rrrrrY�s
��z1BatchSpanProcessor._default_export_timeout_milliscCsD|dkrtd��|dkr td��|dkr0td��||kr@td��dS)Nrz*max_queue_size must be a positive integer.z'schedule_delay_millis must be positive.z1max_export_batch_size must be a positive integer.zCmax_export_batch_size must be less than or equal to max_queue_size.)r�)rKrLrMrrrrZ�s�z&BatchSpanProcessor._validate_arguments)NNNN)N)N)!rrrr+rr.�floatr4rr,rrr9rrBrkr_rDru�staticmethodrwr�rxr�ryr/r*r&rVrWrXrYrZrrrrrJ�sR��3�
�/��		





rJc@sjeZdZdZdejdd�feeej	ej
egefd�dd�Zej
eed�d	d
�Zdeed�d
d�ZdS)�ConsoleSpanExporterz�Implementation of :class:`SpanExporter` that prints spans to the
    console.

    This class can be used for diagnostic purposes. It prints the exported
    spans to the console STDOUT.
    NcCs|��tSr3)�to_jsonr)r6rrr�<lambda>�s�zConsoleSpanExporter.<lambda>)�service_name�out�	formattercCs||_||_||_dSr3)r�r�r�)r"r�r�r�rrrr4�szConsoleSpanExporter.__init__rcCs,|D]}|j�|�|��q|j��tjSr3)r��writer��flushrr)r"r r6rrrr#�s
zConsoleSpanExporter.exportrr'cCsdSrCrr)rrrr*�szConsoleSpanExporter.force_flush)r)rrrr+�sys�stdoutr�strr,�IO�Callablerr4r-rr#r.r/r*rrrrr��s	��r�)-r[�loggingrjr�rGr,�enumrrr�timerrZmysql.opentelemetry.contextrrr	r
rZ-mysql.opentelemetry.sdk.environment_variablesrr
rrZmysql.opentelemetry.sdk.tracerrrZmysql.opentelemetry.util._oncerr�r�r�r�r��	getLoggerrr?rrr0rDrorJr�rrrr�<module>s:�
!"
W