
    G)fsU                     f   U d Z ddlZddlZddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZmZmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZmZmZ ddlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ ddl,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4  ee5      Z6 G d de      Z7 G d de7      Z8eee8      Z9 G d de	      Z: G d de      Z; G d de;      Z< edd       G d  d!e<             Z= G d" d#e;      Z> G d$ d%e      Z? G d& d'e?      Z@ G d( d)e?      ZA edd*       G d+ d,eA             ZB e2       ZCdaDee;   eEd-<    e>       ZF	 	 	 d>d.eGd/ej                  eG   d0ee;   d1ej                  eG   d2d%f
d3ZHd0e;d4eId2dfd5ZJd0e;d2dfd6ZKd2e;fd7ZLe	 	 	 d?d8e&d9eId:eId;eId2ee&   f
d<       ZMg d=ZNy)@ae	  
The OpenTelemetry tracing API describes the classes used to generate
distributed traces.

The :class:`.Tracer` class controls access to the execution context, and
manages span creation. Each operation in a trace is represented by a
:class:`.Span`, which records the start, end time, and metadata associated with
the operation.

This module provides abstract (i.e. unimplemented) classes required for
tracing, and a concrete no-op :class:`.NonRecordingSpan` that allows applications
to use the API package alone without a supporting implementation.

To get a tracer, you need to provide the package name from which you are
calling the tracer APIs to OpenTelemetry by calling `TracerProvider.get_tracer`
with the calling module name and the version of your package.

The tracer supports creating spans that are "attached" or "detached" from the
context. New spans are "attached" to the context in that they are
created as children of the currently active span, and the newly-created span
can optionally become the new active span::

    from opentelemetry import trace

    tracer = trace.get_tracer(__name__)

    # Create a new root span, set it as the current span in context
    with tracer.start_as_current_span("parent"):
        # Attach a new child and update the current span
        with tracer.start_as_current_span("child"):
            do_work():
        # Close child span, set parent as current
    # Close parent span, set default span as current

When creating a span that's "detached" from the context the active span doesn't
change, and the caller is responsible for managing the span's lifetime::

    # Explicit parent span assignment is done via the Context
    from mysql.opentelemetry.trace import set_span_in_context

    context = set_span_in_context(parent)
    child = tracer.start_span("child", context=context)

    try:
        do_work(span=child)
    finally:
        child.end()

Applications should generally use a single global TracerProvider, and use
either implicit or explicit context propagation consistently throughout.

.. versionadded:: 0.1.0
.. versionchanged:: 0.3.0
    `TracerProvider` was introduced and the global ``tracer`` getter was
    replaced by ``tracer_provider``.
.. versionchanged:: 0.5.0
    ``tracer_provider`` was replaced by `get_tracer_provider`,
    ``set_preferred_tracer_provider_implementation`` was replaced by
    `set_tracer_provider`.
    N)ABCabstractmethod)contextmanager)Enum)	getLogger)IteratorOptionalSequencecast)
deprecated)context)BoundedAttributes)Context)OTEL_PYTHON_TRACER_PROVIDER)	_SPAN_KEYget_current_spanset_span_in_context)DEFAULT_TRACE_OPTIONSDEFAULT_TRACE_STATEINVALID_SPANINVALID_SPAN_CONTEXTINVALID_SPAN_IDINVALID_TRACE_IDNonRecordingSpanSpanSpanContext
TraceFlags
TraceStateformat_span_idformat_trace_id)Status
StatusCode)types)Once)_load_providerc                   Z    e Zd ZddZedd       Zeedej                  fd              Z	y)	_LinkBasereturnNc                     || _         y N_context)selfr   s     _/var/www/html/flask-app/venv/lib/python3.12/site-packages/mysql/opentelemetry/trace/__init__.py__init__z_LinkBase.__init__w   s	        c                     | j                   S r*   r+   r-   s    r.   r   z_LinkBase.contextz   s    }}r0   c                      y r*    r2   s    r.   
attributesz_LinkBase.attributes~   s     	r0   )r   r   r(   N)r(   r   )
__name__
__module____qualname__r/   propertyr   r   r#   
Attributesr5   r4   r0   r.   r'   r'   v   sD        E,,   r0   r'   c                   r     e Zd ZdZ	 d	dddej
                  ddf fdZedej
                  fd       Z xZ	S )
LinkzA link to a `Span`. The attributes of a Link are immutable.

    Args:
        context: `SpanContext` of the `Span` to link to.
        attributes: Link's attributes.
    Nr   r   r5   r(   c                 F    t         |   |       t        |      | _        y )N)r5   )superr/   r   _attributes)r-   r   r5   	__class__s      r.   r/   zLink.__init__   s"    
 	!,!
r0   c                     | j                   S r*   )r?   r2   s    r.   r5   zLink.attributes   s    r0   r*   )
r6   r7   r8   __doc__r#   r:   r/   r9   r5   __classcell__)r@   s   @r.   r<   r<      sU     (,

 $$
 
	
  E,,    r0   r<   c                   $    e Zd ZdZdZdZdZdZdZy)SpanKindzSpecifies additional details on how this span relates to its parent span.

    Note that this enumeration is experimental and likely to change. See
    https://github.com/open-telemetry/opentelemetry-specification/pull/226.
    r               N)	r6   r7   r8   rB   INTERNALSERVERCLIENTPRODUCERCONSUMERr4   r0   r.   rE   rE      s*     H F F
 H
 Hr0   rE   c            
       h    e Zd Ze	 	 ddedej                  e   dej                  e   ddfd       Zy)	TracerProviderNinstrumenting_module_nameinstrumenting_library_version
schema_urlr(   Tracerc                      y)a  Returns a `Tracer` for use by the given instrumentation library.

        For any two calls it is undefined whether the same or different
        `Tracer` instances are returned, even for different library names.

        This function may return different `Tracer` types (e.g. a no-op tracer
        vs.  a functional tracer).

        Args:
            instrumenting_module_name: The uniquely identifiable name for instrumentation
                scope, such as instrumentation library, package, module or class name.
                ``__name__`` may not be used as this can result in
                different tracer names if the tracers are in different files.
                It is better to use a fixed string that can be imported where
                needed and used consistently as the name of the tracer.

                This should *not* be the name of the module that is
                instrumented but the name of the module doing the instrumentation.
                E.g., instead of ``"requests"``, use
                ``"mysql.opentelemetry.instrumentation.requests"``.

            instrumenting_library_version: Optional. The version string of the
                instrumenting library.  Usually this should be the same as
                ``importlib.metadata.version(instrumenting_library_name)``.

            schema_url: Optional. Specifies the Schema URL of the emitted telemetry.
        Nr4   r-   rQ   rR   rS   s       r.   
get_tracerzTracerProvider.get_tracer       r0   NN)r6   r7   r8   r   strtypingr	   rW   r4   r0   r.   rP   rP      sU     ?C+/	 #&  (.s';  OOC(	 
 
   r0   rP   c            	       b    e Zd ZdZ	 	 d	dedej                  e   dej                  e   ddfdZy)
NoOpTracerProvideriThe default TracerProvider, used when no implementation is available.

    All operations are no-op.
    NrQ   rR   rS   r(   rT   c                     t               S r*   )
NoOpTracerrV   s       r.   rW   zNoOpTracerProvider.get_tracer   s     |r0   rY   )r6   r7   r8   rB   rZ   r[   r	   rW   r4   r0   r.   r]   r]      sM     ?C+/	#& (.s'; OOC(	
 
r0   r]   z1.9.0z!You should use NoOpTracerProvider)versionreasonc                       e Zd ZdZy)_DefaultTracerProviderr^   Nr6   r7   r8   rB   r4   r0   r.   rd   rd          r0   rd   c            	       ^    e Zd Z	 	 ddedej
                  e   dej
                  e   ddfdZy)	ProxyTracerProviderNrQ   rR   rS   r(   rT   c                 V    t         rt         j                  |||      S t        |||      S r*   )_TRACER_PROVIDERrW   ProxyTracerrV   s       r.   rW   zProxyTracerProvider.get_tracer   s;     #..)- 
 %)
 	
r0   rY   )r6   r7   r8   rZ   r[   r	   rW   r4   r0   r.   rh   rh      sH     ?C+/	
#&
 (.s';
 OOC(	

 

r0   rh   c                      e Zd ZdZedej                  dddddfdedee	   dede
j                  ded	ee   d
ededdfd       Zeedej                  ddddddfdedee	   dede
j                  ded	ee   d
edededed   fd              Zy)rT   zHandles span creation and in-process context propagation.

    This class provides methods for manipulating the context, creating spans,
    and controlling spans' lifecycles.
    NTnamer   kindr5   links
start_timerecord_exceptionset_status_on_exceptionr(   r   c	                      y)a  Starts a span.

        Create a new span. Start the span without setting it as the current
        span in the context. To start the span and use the context in a single
        method, see :meth:`start_as_current_span`.

        By default the current span in the context will be used as parent, but an
        explicit context can also be specified, by passing in a `Context` containing
        a current `Span`. If there is no current span in the global `Context` or in
        the specified context, the created span will be a root span.

        The span can be used as a context manager. On exiting the context manager,
        the span's end() method will be called.

        Example::

            # trace.get_current_span() will be used as the implicit parent.
            # If none is found, the created span will be a root instance.
            with tracer.start_span("one") as child:
                child.add_event("child's event")

        Args:
            name: The name of the span to be created.
            context: An optional Context containing the span's parent. Defaults to the
                global context.
            kind: The span's kind (relationship to parent). Note that is
                meaningful even if there is no parent.
            attributes: The span's attributes.
            links: Links span to other spans
            start_time: Sets the start time of a span
            record_exception: Whether to record any exceptions raised within the
                context as error event on the span.
            set_status_on_exception: Only relevant if the returned span is used
                in a with/context manager. Defines whether the span status will
                be automatically set to ERROR when an uncaught exception is
                raised in the span with block. The span status won't be set by
                this mechanism if it was previously set manually.

        Returns:
            The newly-created span.
        Nr4   	r-   rm   r   rn   r5   ro   rp   rq   rr   s	            r.   
start_spanzTracer.start_span  rX   r0   end_on_exitc
                      y)a	  Context manager for creating a new span and set it
        as the current span in this tracer's context.

        Exiting the context manager will call the span's end method,
        as well as return the current span to its previous value by
        returning to the previous context.

        Example::

            with tracer.start_as_current_span("one") as parent:
                parent.add_event("parent's event")
                with tracer.start_as_current_span("two") as child:
                    child.add_event("child's event")
                    trace.get_current_span()  # returns child
                trace.get_current_span()      # returns parent
            trace.get_current_span()          # returns previously active span

        This is a convenience method for creating spans attached to the
        tracer's context. Applications that need more control over the span
        lifetime should use :meth:`start_span` instead. For example::

            with tracer.start_as_current_span(name) as span:
                do_work()

        is equivalent to::

            span = tracer.start_span(name)
            with mysql.opentelemetry.trace.use_span(span, end_on_exit=True):
                do_work()

        This can also be used as a decorator::

            @tracer.start_as_current_span("name")
            def function():
                ...

            function()

        Args:
            name: The name of the span to be created.
            context: An optional Context containing the span's parent. Defaults to the
                global context.
            kind: The span's kind (relationship to parent). Note that is
                meaningful even if there is no parent.
            attributes: The span's attributes.
            links: Links span to other spans
            start_time: Sets the start time of a span
            record_exception: Whether to record any exceptions raised within the
                context as error event on the span.
            set_status_on_exception: Only relevant if the returned span is used
                in a with/context manager. Defines whether the span status will
                be automatically set to ERROR when an uncaught exception is
                raised in the span with block. The span status won't be set by
                this mechanism if it was previously set manually.
            end_on_exit: Whether to end the span automatically when leaving the
                context manager.

        Yields:
            The newly-created span.
        Nr4   
r-   rm   r   rn   r5   ro   rp   rq   rr   rv   s
             r.   start_as_current_spanzTracer.start_as_current_spanI  rX   r0   )r6   r7   r8   rB   r   rE   rJ   rZ   r	   r   r#   r:   _Linksintboolru   r   r   ry   r4   r0   r.   rT   rT     s^     &*!**'+$(!%(,33 '"3 	3
 $$3 3 SM3 3 "&3 
3 3j  &*!**'+$(!%(, GG '"G 	G
 $$G G SMG G "&G G 
&	G  Gr0   rT   c                       e Zd Z	 	 d
dedej
                  e   dej
                  e   fdZedefd       Z	de
fdZedee
   fd	       Zy)rk   NrQ   rR   rS   c                 Z    || _         || _        || _        d | _        t	               | _        y r*   )_instrumenting_module_name_instrumenting_library_version_schema_url_real_tracerr`   _noop_tracerrV   s       r.   r/   zProxyTracer.__init__  s/     +D'.K+%.2&Lr0   r(   c                     | j                   r| j                   S t        rFt        j                  | j                  | j                  | j
                        | _         | j                   S | j                  S r*   )r   rj   rW   r   r   r   r   r2   s    r.   _tracerzProxyTracer._tracer  sb    $$$ 0 ; ;//33  !D
 $$$   r0   c                 :     | j                   j                  |i |S r*   )r   ru   )r-   argskwargss      r.   ru   zProxyTracer.start_span  s    &t||&&777r0   c              /   v   K    | j                   j                  |i |5 }| d d d        y # 1 sw Y   y xY wwr*   )r   ry   )r-   r   r   spans       r.   ry   z!ProxyTracer.start_as_current_span  s:     /T\\//@@ 	DJ	 	 	s   9-	969rY   )r6   r7   r8   rZ   r[   r	   r/   r9   rT   r   r   ru   r   r   ry   r4   r0   r.   rk   rk     s    
 ?C+/	
)#&
) (.s';
) OOC(	
) ! ! !8T 8   r0   rk   c                      e Zd ZdZdej
                  dddddfdedee   dede	j                  ded	ee   d
ededdfdZedej
                  ddddddfdedee   dede	j                  ded	ee   d
edededed   fd       Zy)r`   hThe default Tracer, used when no Tracer implementation is available.

    All operations are no-op.
    NTrm   r   rn   r5   ro   rp   rq   rr   r(   r   c	                     t         S r*   r   rt   s	            r.   ru   zNoOpTracer.start_span  s
     r0   rv   c
              #      K   t          y wr*   r   rx   s
             r.   ry   z NoOpTracer.start_as_current_span  s      s   
)r6   r7   r8   rB   rE   rJ   rZ   r	   r   r#   r:   rz   r{   r|   ru   r   r   ry   r4   r0   r.   r`   r`     s:    &*!**'+$(!%(, '" 	
 $$  SM  "& 
  &*!**'+$(!%(,  '" 	
 $$  SM  "&  
&	 r0   r`   zYou should use NoOpTracerc                       e Zd ZdZy)_DefaultTracerr   Nre   r4   r0   r.   r   r     rf   r0   r   rj   rQ   rR   tracer_providerrS   r(   c                 @    |
t               }|j                  | ||      S )zReturns a `Tracer` for use by the given instrumentation library.

    This function is a convenience wrapper for
    mysql.opentelemetry.trace.TracerProvider.get_tracer.

    If tracer_provider is omitted the current configured one is used.
    )get_tracer_providerrW   )rQ   rR   r   rS   s       r.   rW   rW     s-     -/%%!#@* r0   logc                 r     d fd}t         j                  |      }|r|st        j                  d       y y y )Nc                  
     a y r*   )rj   r   s   r.   set_tpz$_set_tracer_provider.<locals>.set_tp  s	    *r0   z3Overriding of current TracerProvider is not allowed)r(   N)_TRACER_PROVIDER_SET_ONCEdo_onceloggerwarning)r   r   r   did_sets   `   r.   _set_tracer_providerr      s3    + (//7G
7LM sr0   c                     t        | d       y)zSets the current global :class:`~.TracerProvider` object.

    This can only be done once, a warning will be logged if any further attempt
    is made.
    Tr   N)r   r   s    r.   set_tracer_providerr     s     d3r0   c                      t         9t        t        j                  vrt        S t        t        d      } t        | d       t        dt               S )z9Gets the current global :class:`~.TracerProvider` object.r   Fr   rP   )rj   r   osenviron_PROXY_TRACER_PROVIDERr%   r   r   r   s    r.   r   r     sG     'bjj8))*8'):+
 	_%8 "233r0   r   rv   rq   rr   c           	   #   :  K   	 t        j                  t        j                  t        |             }	 |  t        j                  |       	 |r| j!                          yy# t        j                  |       w xY w# t
        $ r}}t        | t              rg| j                         rW|r| j                  |       |rB| j                  t        t        j                  t        |      j                   d|               d}~ww xY w# |r| j!                          w w xY ww)a  Takes a non-active span and activates it in the current context.

    Args:
        span: The span that should be activated in the current context.
        end_on_exit: Whether to end the span automatically when leaving the
            context manager scope.
        record_exception: Whether to record any exceptions raised within the
            context as error event on the span.
        set_status_on_exception: Only relevant if the returned span is used
            in a with/context manager. Defines whether the span status will
            be automatically set to ERROR when an uncaught exception is
            raised in the span with block. The span status won't be set by
            this mechanism if it was previously set manually.
    z: )status_codedescriptionN)context_apiattach	set_valuer   detach	Exception
isinstancer   is_recordingrq   
set_statusr!   r"   ERRORtyper6   end)r   rv   rq   rr   tokenexcs         r.   use_spanr   $  s     *"";#8#8D#IJ	&Ju%& HHJ ' u% dD!d&7&7&9%%c* '$.$4$4'+Cy'9'9&:"SE$B 	" HHJ sK   D-A: A  A: D A77A: :	D A8C;;D  D DD)r   r   r   r   r   r   r   r<   r   r   rE   r   r   rP   rT   r   r    r   rW   r   r   r   r   r!   r"   )NNN)FTT)OrB   r   r[   abcr   r   
contextlibr   enumr   loggingr   r   r	   r
   r   r   mysql.opentelemetryr   r   mysql.opentelemetry.attributesr   #mysql.opentelemetry.context.contextr   )mysql.opentelemetry.environment_variablesr   %mysql.opentelemetry.trace.propagationr   r   r   mysql.opentelemetry.trace.spanr   r   r   r   r   r   r   r   r   r   r   r   r     mysql.opentelemetry.trace.statusr!   r"   mysql.opentelemetry.utilr#   mysql.opentelemetry.util._oncer$   #mysql.opentelemetry.util._providersr%   r6   r   r'   r<   rz   rE   rP   r]   rd   rh   rT   rk   r`   r   r   rj   __annotations__r   rZ   rW   r|   r   r   r   r   __all__r4   r0   r.   <module>r      sD  ;z 
  # %   5 5 ! 6 < 7 Q 
    @ * / >	8	  9  . 
(4.	!t :"S "J   G$GH/  I
. 
(FS FR"& "J" "J G$?@Z  A !F -1 (>* 1,. 
 ;?04'+	"#)??3#7 n- $	
 (N. Nt N N4 4D 44^ 4   !$(	-
-- - "	-
 d^- -`r0   