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/connector/opentelemetry/__pycache__/context_propagation.cpython-39.pyc
a

�,�h��@s�dZddlmZmZmZddlmZmZervddlm	Z	e	rZddl
mZddlm
Z
mZnddlmZddlm
Z
mZer�dd	lmZeed
�dd�Zeed
�dd�ZdS)z$Trace context propagation utilities.�)�
TYPE_CHECKING�Any�Callable�)�OTEL_ENABLED�TRACEPARENT_HEADER_NAME)�OTEL_SYSTEM_AVAILABLE)�trace)�format_span_id�format_trace_id�)�MySQLConnectionAbstract)�span�returncCs6|��}d}t|j�}t|j�}d}d�||||g�S)ahBuild a traceparent header according to the provided span.

    The context information from the provided span is used to build the traceparent
    header that will be propagated to the MySQL server. For particulars regarding
    the header creation, refer to [1].

    This method assumes version 0 of the W3C specification.

    Args:
        span (opentelemetry.trace.span.Span): current span in trace.

    Returns:
        traceparent_header (str): HTTP header field that identifies requests in a
        tracing system.

    References:
        [1]: https://www.w3.org/TR/trace-context/#traceparent-header
    Z00�-)Zget_span_contextr�trace_idr
�span_id�join)r�ctx�versionrrZtrace_flags�r�d/opt/nydus/tmp/pip-target-wkfpz8uv/lib64/python/mysql/connector/opentelemetry/context_propagation.py�build_traceparent_header7s

r)�methodrcsdtttd��fdd�}|S)a�Perform trace context propagation.

    The trace context is propagated via query attributes. The `traceparent` header
    from W3C specification [1] is used, in this sense, the attribute name is
    `traceparent` (is RESERVED, avoid using it), and its value is built as per
    instructed in [1].

    If opentelemetry API/SDK is unavailable or there is no recording span,
    trace context propagation is skipped.

    References:
        [1]: https://www.w3.org/TR/trace-context/#traceparent-header
    r
)�cnx�args�kwargsrc	s�tr
|js �|g|�Ri|��St��}d}|��rLt|�}|jt|fd�z.�|g|�Ri|��}W|dur�|jtd�n|dur�|jtd�0|S)zContext propagation decorator.N)�value)�name)	rZotel_context_propagationr	Zget_current_spanZis_recordingrZquery_attrs_appendrZquery_attrs_remove)rrrZcurrent_spanZ	tp_header�result�rrr�wrappercs
�z)with_context_propagation.<locals>.wrapper)r)rr!rr r�with_context_propagationTsr"N)�__doc__�typingrrr�	constantsrrZinstrumentationrZ
opentelemetryr	Zopentelemetry.trace.spanr
rZmysql.opentelemetryZmysql.opentelemetry.trace.spanZ	abstractsr
�strrr"rrrr�<module>s