
    G)f1H                        d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlm	Z	m
Z
 d dlmZ dZ ej                  e      ZdZ ej                  e      ZdZ ej                  d      Z ej                  d	e d
e d      Z ej(                  e      ZdededefdZ G d de j4                        Z G d de      Zej=                         Z G d dej@                  eef         Z!e!j=                         Z"ddz  dz
  Z#dZ$ G d dejJ                  eeeddef         Z& G d de      Z'd Z(d Z) e&e)e(dee"      Z* e'e*      Z+d edefd!Z,d"edefd#Z-y)$    N)OrderedDict)Status
StatusCode)typeszU[a-z][_0-9a-z\-\*\/]{0,255}|[a-z0-9][_0-9a-z\-\*\/]{0,240}@[a-z][_0-9a-z\-\*\/]{0,13}zA[\x20-\x2b\x2d-\x3c\x3e-\x7e]{0,255}[\x21-\x2b\x2d-\x3c\x3e-\x7e]    z[ \t]*,[ \t]*(z)(=)(z)[ 	]*keyvaluereturnc                     t        | t              xrB t        j                  |       d uxr) t        |t              xr t        j                  |      d uS N)
isinstancestr_KEY_PATTERN	fullmatch_VALUE_PATTERN)r	   r
   s     [/var/www/html/flask-app/venv/lib/python3.12/site-packages/mysql/opentelemetry/trace/span.py_is_valid_pairr   .   sR    3 	8""3't3	8uc"	8 $$U+47	    c                   b   e Zd ZdZej
                  ddej                  e   ddfd       Z	ej
                  dd       Z
ej
                  dej                  eej                  f   ddfd       Zej
                  d	ed
ej                  ddfd       Zej
                  	 	 ddedej"                  dej                  e   ddfd       Zej
                  deddfd       Zej
                  defd       Zej
                  	 ddej,                  eef   dej                  e   ddfd       Zej
                  	 	 	 ddedej"                  dej                  e   deddf
d       Zd dZdej                  ej:                  e      dej                  e   dej                  ej@                     ddfdZ!y)!Spanz4A span represents a single operation within a trace.Nend_timer   c                      y)a  Sets the current time as the span's end time.

        The span's end time is the wall time at which the operation finished.

        Only the first call to `end` should modify the span, and
        implementations are free to ignore or raise on further calls.
        N selfr   s     r   endzSpan.end:       r   c                      y)a  Gets the span's SpanContext.

        Get an immutable, serializable identifier for this span that can be
        used to create new child spans.

        Returns:
            A :class:`opentelemetry.trace.SpanContext` with a copy of this span's immutable state.
        Nr   r   s    r   get_span_contextzSpan.get_span_contextD   r   r   
attributesc                      y)a  Sets Attributes.

        Sets Attributes with the key and value passed as arguments dict.

        Note: The behavior of `None` value attributes is undefined, and hence
        strongly discouraged. It is also preferred to set attributes at span
        creation, instead of calling this method later since samplers can only
        consider information already present during span creation.
        Nr   r   r"   s     r   set_attributeszSpan.set_attributesO   r   r   r	   r
   c                      y)a  Sets an Attribute.

        Sets a single Attribute with the key and value passed as arguments.

        Note: The behavior of `None` value attributes is undefined, and hence
        strongly discouraged. It is also preferred to set attributes at span
        creation, instead of calling this method later since samplers can only
        consider information already present during span creation.
        Nr   r   r	   r
   s      r   set_attributezSpan.set_attribute]   r   r   name	timestampc                      y)zAdds an `Event`.

        Adds a single `Event` with the name and, optionally, a timestamp and
        attributes passed as arguments. Implementations should generate a
        timestamp if the `timestamp` argument is omitted.
        Nr   r   r)   r"   r*   s       r   	add_eventzSpan.add_eventi   r   r   c                      y)zUpdates the `Span` name.

        This will override the name provided via :func:`opentelemetry.trace.Tracer.start_span`.

        Upon this update, any sampling behavior based on Span name will depend
        on the implementation.
        Nr   r   r)   s     r   update_namezSpan.update_namew   r   r   c                      y)zReturns whether this span will be recorded.

        Returns true if this Span is active and recording information like
        events with the add_event operation and attributes using set_attribute.
        Nr   r    s    r   is_recordingzSpan.is_recording   r   r   statusdescriptionc                      y)zbSets the Status of the Span. If used, this will override the default
        Span status.
        Nr   r   r3   r4   s      r   
set_statuszSpan.set_status   r   r   	exceptionescapedc                      y)z%Records an exception as a span event.Nr   r   r8   r"   r*   r9   s        r   record_exceptionzSpan.record_exception   r   r   c                     | S )z^Invoked when `Span` is used as a context manager.

        Returns the `Span` itself.
        r   r    s    r   	__enter__zSpan.__enter__   s	    
 r   exc_typeexc_valexc_tbc                 $    | j                          y)z3Ends context manager and calls `end` on the `Span`.N)r   )r   r?   r@   rA   s       r   __exit__zSpan.__exit__   s     	
r   r   r   SpanContextNNNNF)r   r   )"__name__
__module____qualname____doc__abcabstractmethodtypingOptionalintr   r!   Dictr   r   AttributeValuer%   r(   
Attributesr-   r0   boolr2   Unionr   r   r7   	Exceptionr<   r>   TypeBaseExceptionpython_typesTracebackTyperC   r   r   r   r   r   7   sq   >FOOC0 D   	  	 ++c5+?+?&?@	  		 	U-A-A 	d 	 	 	 (,*.	 $$ ??3'	
 
  	    	d   	 -1VZ/0 __S) 
	  	 (,*.44 $$4 ??3'	4
 4 
4 4//&++m"<= /  : :;	
 
r   r   c                   @    e Zd ZdZdZdZedd       Zede	fd       Z
y)	
TraceFlagsar  A bitmask that represents options specific to the trace.

    The only supported option is the "sampled" flag (``0x01``). If set, this
    flag indicates that the trace may have been sampled upstream.

    See the `W3C Trace Context - Traceparent`_ spec for details.

    .. _W3C Trace Context - Traceparent:
        https://www.w3.org/TR/trace-context/#trace-flags
    r      r   c                 &     | | j                         S r   )DEFAULTclss    r   get_defaultzTraceFlags.get_default   s    3;;r   c                 :    t        | t        j                  z        S r   )rT   r\   SAMPLEDr    s    r   sampledzTraceFlags.sampled   s    D:---..r   Nr   r\   )rH   rI   rJ   rK   r_   rd   classmethodrb   propertyrT   re   r   r   r   r\   r\      s@    	 GG    / / /r   r\   c                      e Zd ZdZ	 ddej
                  ej                  ej                  eef         ddfdZ	de
defdZdedefd	Zdej                  e   fd
ZdefdZdefdZdededd fdZdededd fdZdedd fdZdefdZedej0                  e   dd fd       Zedd       Zdej6                  e   fdZdej:                  eef   fdZdej>                  e   fdZ y)
TraceStatea  A list of key-value pairs representing vendor-specific trace info.

    Keys and values are strings of up to 256 printable US-ASCII characters.
    Implementations should conform to the `W3C Trace Context - Tracestate`_
    spec, which describes additional restrictions on valid field values.

    .. _W3C Trace Context - Tracestate:
        https://www.w3.org/TR/trace-context/#tracestate-field
    Nentriesr   c                 F   t               | _        |y t        |      t        kD  rt        j                  dt               y |D ]]  \  }}t        ||      r5|| j                  v rt        j                  d|       7|| j                  |<   Gt        j                  d||       _ y )Nz,There can't be more than %s key/value pairs.zDuplicate key: %s found.&Invalid key/value pair (%s, %s) found.)r   _dictlen%_TRACECONTEXT_MAXIMUM_TRACESTATE_KEYS_loggerwarningr   )r   rk   r	   r
   s       r   __init__zTraceState.__init__   s     !]
?w<??OO>5 ! 	VJCc5)$**$OO$>D"'

3 H#uU	Vr   itemc                     || j                   v S r   rn   )r   rt   s     r   __contains__zTraceState.__contains__   s    tzz!!r   r	   c                      | j                   |   S r   rv   )r   r	   s     r   __getitem__zTraceState.__getitem__   s    zz#r   c                 ,    t        | j                        S r   )iterrn   r    s    r   __iter__zTraceState.__iter__   s    DJJr   c                 ,    t        | j                        S r   )ro   rn   r    s    r   __len__zTraceState.__len__   s    4::r   c           	          | j                   j                         D cg c]  \  }}d| d| d }}}t        |      S c c}}w )Nz{key=z, value=})rn   itemsr   )r   r	   r
   pairss       r   __repr__zTraceState.__repr__   sE    CG::CSCSCUVZS%6#hugR0VV5z Ws   ?r
   c                 R   t        ||      st        j                  d||       | S t        |       t        k\  rt        j                  d       | S || j
                  v rt        j                  d|       | S ||fgt        | j
                  j                               z   }t        |      S )a  Adds a key-value pair to tracestate. The provided pair should
        adhere to w3c tracestate identifiers format.

        Args:
            key: A valid tracestate key to add
            value: A valid tracestate value to add

        Returns:
            A new TraceState with the modifications applied.

            If the provided key-value pair is invalid or results in tracestate
            that violates tracecontext specification, they are discarded and
            same tracestate will be returned.
        rm   z'There can't be more 32 key/value pairs.z#The provided key %s already exists.)	r   rq   rr   ro   rp   rn   listr   rj   )r   r	   r
   	new_states       r   addzTraceState.add   s     c5)OODc5QKt9==OOEFK$**OOA3GK5\NT$***:*:*<%==	)$$r   c                     t        ||      st        j                  d||       | S | j                  j	                         }|||<   |j                  |d       t        |j                               }t        |      S )a  Updates a key-value pair in tracestate. The provided pair should
        adhere to w3c tracestate identifiers format.

        Args:
            key: A valid tracestate key to update
            value: A valid tracestate value to update for key

        Returns:
            A new TraceState with the modifications applied.

            If the provided key-value pair is invalid or results in tracestate
            that violates tracecontext specification, they are discarded and
            same tracestate will be returned.
        rm   F)last)	r   rq   rr   rn   copymove_to_endr   r   rj   )r   r	   r
   
prev_stater   s        r   updatezTraceState.update  sn     c5)OODc5QKZZ__&

3s/))+,	)$$r   c                     || j                   vrt        j                  d|       | S | j                   j                         }|j	                  |       t        |j                               }t        |      S )a  Deletes a key-value from tracestate.

        Args:
            key: A valid tracestate key to remove key-value pair from tracestate

        Returns:
            A new TraceState with the modifications applied.

            If the provided key-value pair is invalid or results in tracestate
            that violates tracecontext specification, they are discarded and
            same tracestate will be returned.
        z"The provided key %s doesn't exist.)rn   rq   rr   r   popr   r   rj   )r   r	   r   r   s       r   deletezTraceState.delete1  s^     djj OO@#FKZZ__&
s))+,	)$$r   c                 b    dj                  d | j                  j                         D              S )zCreates a w3c tracestate header from a TraceState.

        Returns:
            A string that adheres to the w3c tracestate
            header format.
        ,c              3   2   K   | ]  \  }}|d z   |z     yw)=Nr   ).0r	   r
   s      r   	<genexpr>z'TraceState.to_header.<locals>.<genexpr>M  s     Ojc5c	E)Os   )joinrn   r   r    s    r   	to_headerzTraceState.to_headerF  s&     xxODJJ<L<L<NOOOr   header_listc                 n   t               }|D ]  }t        j                  t        |      }|D ]g  }|st        j                  |      }|s!t        j                  d|        |        c c S |j                         }|\  }}	}
||v r |        c c S |
||<   i   | t        |j                                     S )a  Parses one or more w3c tracestate header into a TraceState.

        Args:
            header_list: one or more w3c tracestate headers.

        Returns:
            A valid TraceState that contains values extracted from
            the tracestate header.

            If the format of one headers is illegal, all values will
            be discarded and an empty tracestate will be returned.

            If the number of keys is beyond the maximum, all values
            will be discarded and an empty tracestate will be returned.
        z2Member doesn't match the w3c identifiers format %s)r   resplit_delimiter_pattern_member_patternr   rq   rr   groupsr   r   )ra   r   r   headermembersmembermatchr   r	   _eqr
   s              r   from_headerzTraceState.from_headerO  s    " ! 	#F(*1CV(LG! #'11&9OOL 5L16"(S%%<5L"c
!#	#& 4&''r   c                      |        S r   r   r`   s    r   rb   zTraceState.get_defaultv  s	    ur   c                 6    | j                   j                         S r   )rn   keysr    s    r   r   zTraceState.keysz  s    zz  r   c                 6    | j                   j                         S r   )rn   r   r    s    r   r   zTraceState.items}  s    zz!!r   c                 6    | j                   j                         S r   )rn   valuesr    s    r   r   zTraceState.values  s    zz  ""r   r   r   rj   )!rH   rI   rJ   rK   rN   rO   SequenceTupler   rs   objectrT   rw   ry   Iteratorr|   rP   r~   r   r   r   r   r   rg   Listr   rb   KeysViewr   	ItemsViewr   
ValuesViewr   r   r   r   rj   rj      sv    MQVc3h1G!HIV 
V." "D "s s  &//#.   # %s %3 %< %:%# %c %l %0%# %, %*P3 P $(fkk#&6 $(< $( $(L  !fooc* !"v''S1 "#))#. #r   rj         r]   l    c                   B   e Zd ZdZeefdedededej                  d   dej                  d   d	d fd
Z
d	ej                  eeeddf   fdZed	efd       Zed	efd       Zed	efd       Zedd       Zedd       Zed	efd       Zded	dfdZded	dfdZd	efdZy)rE   a  The state of a Span to propagate between processes.

    This class includes the immutable attributes of a :class:`.Span` that must
    be propagated to a span's children and across process boundaries.

    Args:
        trace_id: The ID of the trace that this span belongs to.
        span_id: This span's ID.
        is_remote: True if propagated from a remote parent.
        trace_flags: Trace options to propagate.
        trace_state: Tracing-system-specific info to propagate.
    trace_idspan_id	is_remotetrace_flagsr\   trace_staterj   r   c           	          |t         }|t        }t        |cxk  xr	 t        k  nc xr t        |cxk  xr	 t
        k  nc }t        j                  | ||||||f      S r   )DEFAULT_TRACE_OPTIONSDEFAULT_TRACE_STATEINVALID_TRACE_ID_TRACE_ID_MAX_VALUEINVALID_SPAN_ID_SPAN_ID_MAX_VALUEtuple__new__)ra   r   r   r   r   r   is_valids          r   r   zSpanContext.__new__  si     /K-K x>+>> @'?-?? 	
 }}w	;XN
 	
r   c                 t    | j                   | j                  | j                  | j                  | j                  fS r   r   r   r   r   r   r    s    r   __getnewargs__zSpanContext.__getnewargs__  s5     MMLLNN
 	
r   c                     | d   S )Nr   r   r    s    r   r   zSpanContext.trace_id      Awr   c                     | d   S )Nr]   r   r    s    r   r   zSpanContext.span_id  r   r   c                     | d   S )Nr   r   r    s    r   r   zSpanContext.is_remote  r   r   c                     | d   S )N   r   r    s    r   r   zSpanContext.trace_flags  r   r   c                     | d   S )N   r   r    s    r   r   zSpanContext.trace_state  r   r   c                     | d   S )N   r   r    s    r   r   zSpanContext.is_valid  r   r   argsNc                 2    t         j                  dd       y Nz.Immutable type, ignoring call to set attributeT)
stack_inforq   debugr   r   s     r   __setattr__zSpanContext.__setattr__      FSWXr   c                 2    t         j                  dd       y r   r   r   s     r   __delattr__zSpanContext.__delattr__  r   r   c                     t        |       j                   dt        | j                         dt	        | j
                         d| j                  dd| j                  d| j                   dS )Nz(trace_id=0xz, span_id=0xz, trace_flags=0x02xz, trace_state=z, is_remote=))	typerH   format_trace_idr   format_span_idr   r   r   r   r    s    r   r   zSpanContext.__repr__  s    t*%%&l?4==3Q2RR^_mnrnznz_{^|  }M  NR  N^  N^  _b  Mc  cq  rv  rB  rB  qE  EQ  RV  R`  R`  Qa  ab  c  	cr   rf   r   )rH   rI   rJ   rK   r   r   rP   rT   rN   rO   r   r   r   rh   r   r   r   r   r   r   r   r   r   r   r   r   r   rE   rE     sP   $ 6K5H

 
 	

 __\2
 __\2
 

.	
	c3lL@	A	
 #      4       $  Y Y YY Y Yc# cr   rE   c                      e Zd ZdZddZddZdefdZddej                  e
   ddfdZd	ej                  eej                  f   ddfd
Zdedej                  ddfdZ	 	 dded	ej$                  dej                  e
   ddfdZdeddfdZ	 ddej*                  eef   dej                  e   ddfdZ	 	 	 dded	ej$                  dej                  e
   deddf
dZdefdZy)NonRecordingSpanz~The Span that is used when no Span implementation is available.

    All operations are no-op except context propagation.
    r   Nc                     || _         y r   _context)r   contexts     r   rs   zNonRecordingSpan.__init__  s	    r   c                     | j                   S r   r   r    s    r   r!   z!NonRecordingSpan.get_span_context  s    }}r   c                      y)NFr   r    s    r   r2   zNonRecordingSpan.is_recording  s    r   r   c                      y r   r   r   s     r   r   zNonRecordingSpan.end      r   r"   c                      y r   r   r$   s     r   r%   zNonRecordingSpan.set_attributes  s     	r   r	   r
   c                      y r   r   r'   s      r   r(   zNonRecordingSpan.set_attribute  r   r   r)   r*   c                      y r   r   r,   s       r   r-   zNonRecordingSpan.add_event  s     	r   c                      y r   r   r/   s     r   r0   zNonRecordingSpan.update_name  r   r   r3   r4   c                      y r   r   r6   s      r   r7   zNonRecordingSpan.set_status   s    
 	r   r8   r9   c                      y r   r   r;   s        r   r<   z!NonRecordingSpan.record_exception  s     	r   c                 "    d| j                   dS )NzNonRecordingSpan(r   r   r    s    r   r   zNonRecordingSpan.__repr__  s    "4=="3155r   )r   rE   r   NrD   r   rF   rG   )rH   rI   rJ   rK   rs   r!   rT   r2   rN   rO   rP   r   rQ   r   r   rR   r%   r(   rS   r-   r0   rU   r   r   r7   rV   r<   r   r   r   r   r   r     so   
 d FOOC0 D  ++c5+?+?&?@	
 U-A-A d  (,*.	 $$ ??3'	
 
   -1VZ/0 __S) 
	 (,*. $$ ??3'	
  
6# 6r   r   Fr   r   c                     t        | d      S )zConvenience trace ID formatting method
    Args:
        trace_id: Trace ID int

    Returns:
        The trace ID as 32-byte hexadecimal string
    032xformat)r   s    r   r   r      s     (F##r   r   c                     t        | d      S )zConvenience span ID formatting method
    Args:
        span_id: Span ID int

    Returns:
        The span ID as 16-byte hexadecimal string
    016xr   )r   s    r   r   r   +  s     '6""r   ).rL   loggingr   r   rY   rN   collectionsr    mysql.opentelemetry.trace.statusr   r   mysql.opentelemetry.util_KEY_FORMATcompiler   _VALUE_FORMATr   rp   r   r   	getLoggerrH   rq   r   rT   r   ABCr   rP   r\   rb   r   Mappingrj   r   r   r   r   rE   r   r   r   INVALID_SPAN_CONTEXTINVALID_SPANr   r   r   r   r   <module>r     s   
  	   # ? *A  rzz+& UM* )+ %RZZ 01 "**qU=/IJ
'

H
% C D u377 up/ /0 #..0 w#S) w#t !,,. fqj  Oc&,,sC|\4OP Ocd66t 66r %5 "%#    45$c $c $#C #C #r   