
    g              
       :   d dl Z d dlZd dlZ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 d dl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 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& d dl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6m7Z7 d dl8m9Z9 d dl:m;Z;m<Z< d dl=m>Z>m?Z?m@Z@mAZA d dlBmCZCmDZD d dlEmFZFmGZG d dlHmZ d dlImJZJ  ej                  eL      ZMdZNdZOdZPdZQdZRdZSdZT G d d      ZU G d deU      ZV G d deU      ZW G d d e j                        ZY G d! d"eY      ZZd# Z[d$eDd%ej                  d&e]fd'Z^ G d( d)      Z_ G d* d+      Z` e`e`j                  e`j                  e`j                  e`j                  e`j                  e`j                  e`j                  e`j                  ,      Zbe`j                  de-eO      Zd G d- d.e"j                  e_      Ze G d/ d0ee      Zf G d1 d2e"j                        Zg G d3 d4e"j                        Zhy)5    N)environ)time_ns)MappingProxyTypeTracebackType)AnyCallableDictIteratorListMutableMapping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_SDK_DISABLED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)EXCEPTION_ESCAPEDEXCEPTION_MESSAGEEXCEPTION_STACKTRACEEXCEPTION_TYPE)
NoOpTracerSpanContext)Status
StatusCode)types)_agnosticcontextmanager    c                   d    e Zd ZdZ	 ddddeej                     ddfdZddZdd	Z	dd
e
defdZy)SpanProcessora   Interface 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returnc                      y)az  Called when a :class:`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:`opentelemetry.trace.Span` that just started.
            parent_context: The parent context of the span that just started.
        N selfr7   r9   s      U/var/www/openai/venv/lib/python3.12/site-packages/opentelemetry/sdk/trace/__init__.pyon_startzSpanProcessor.on_startd           c                      y)a&  Called when a :class:`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:`opentelemetry.trace.Span` that just ended.
        Nr<   r>   r7   s     r?   on_endzSpanProcessor.on_ends   rA   rB   c                      y)zJCalled when a :class:`opentelemetry.sdk.trace.TracerProvider` is shutdown.Nr<   r>   s    r?   shutdownzSpanProcessor.shutdown}   rA   rB   timeout_millisc                      y)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.
        Nr<   r>   rI   s     r?   force_flushzSpanProcessor.force_flush   rA   rB   Nr7   ReadableSpanr:   Nr:   Ni0u  )__name__
__module____qualname____doc__r   context_apiContextr@   rE   rH   intboolrL   r<   rB   r?   r6   r6   [   sV     9= !!4!45 
	Y
# 
$ 
rB   r6   c                       e Zd ZU dZeedf   ed<   d ZdeddfdZ	 dd	d
de	e
j                     ddfdZddZddZddedefdZy)SynchronousMultiSpanProcessorzImplementation 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.
    ._span_processorsc                 D    d| _         t        j                         | _        y )Nr<   )r\   	threadingLock_lockrG   s    r?   __init__z&SynchronousMultiSpanProcessor.__init__   s     !#^^%
rB   span_processorr:   Nc                 r    | j                   5  | xj                  |fz  c_        ddd       y# 1 sw Y   yxY wz:Adds a SpanProcessor to the list handled by this instance.Nr`   r\   r>   rb   s     r?   add_span_processorz0SynchronousMultiSpanProcessor.add_span_processor   '    ZZ!!n%66! ZZ   -6r7   r8   r9   c                 L    | j                   D ]  }|j                  ||        y )Nr9   )r\   r@   )r>   r7   r9   sps       r?   r@   z&SynchronousMultiSpanProcessor.on_start   s$    
 ''BKK^K< (rB   c                 H    | j                   D ]  }|j                  |        y rM   )r\   rE   )r>   r7   rl   s      r?   rE   z$SynchronousMultiSpanProcessor.on_end   s    ''BIIdO (rB   c                 F    | j                   D ]  }|j                           y)z7Sequentially shuts down all underlying span processors.N)r\   rH   )r>   rl   s     r?   rH   z&SynchronousMultiSpanProcessor.shutdown   s    ''BKKM (rB   rI   c                     t               |dz  z   }| j                  D ],  }t               }||k\  r y|j                  ||z
  dz        r, y y)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@B FT)r   r\   rL   )r>   rI   deadline_nsrl   current_time_nss        r?   rL   z)SynchronousMultiSpanProcessor.force_flush   sU     i.7"::''B%iO+->>;#@W"LM ( rB   rM   rN   rP   rQ   )rR   rS   rT   rU   r   r6   __annotations__ra   rg   r   rV   rW   r@   rE   rH   rX   rY   rL   r<   rB   r?   r[   r[      s     M3.//&7 74 7 9=== !!4!45= 
	=
# $ rB   r[   c                       e Zd ZdZddefdZdeddfdZdeeged	   f   d
e	de	fdZ
	 ddddeej                     ddfdZddZddZddedefdZy)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_threadsc                     d| _         t        j                         | _        t        j
                  j                  |      | _        y )Nr<   )max_workers)r\   r^   r_   r`   
concurrentfuturesThreadPoolExecutor	_executor)r>   ru   s     r?   ra   z%ConcurrentMultiSpanProcessor.__init__   s:     !#^^%
#++>># ? 
rB   rb   r:   Nc                 r    | j                   5  | xj                  |fz  c_        ddd       y# 1 sw Y   yxY wrd   re   rf   s     r?   rg   z/ConcurrentMultiSpanProcessor.add_span_processor   rh   ri   func).Nargskwargsc                     g }| j                   D ]9  } | j                  j                   ||      g|i |}|j                  |       ; |D ]  }|j	                           y rM   )r\   r{   submitappendresult)r>   r}   r~   r   ry   rl   futures          r?   _submit_and_awaitz.ConcurrentMultiSpanProcessor._submit_and_await   s^     ''B*T^^**48EdEfEFNN6" ( FMMO rB   r7   r8   r9   c                 .    | j                  d ||       y )Nc                     | j                   S rM   )r@   rl   s    r?   <lambda>z7ConcurrentMultiSpanProcessor.on_start.<locals>.<lambda>   s    r{{rB   rk   r   r=   s      r?   r@   z%ConcurrentMultiSpanProcessor.on_start   s    
 	"D 	 	
rB   c                 *    | j                  d |       y )Nc                     | j                   S rM   )rE   r   s    r?   r   z5ConcurrentMultiSpanProcessor.on_end.<locals>.<lambda>  s    "))rB   r   rD   s     r?   rE   z#ConcurrentMultiSpanProcessor.on_end   s    3T:rB   c                 (    | j                  d        y)z6Shuts down all underlying span processors in parallel.c                     | j                   S rM   )rH   r   s    r?   r   z7ConcurrentMultiSpanProcessor.shutdown.<locals>.<lambda>  s    "++rB   Nr   rG   s    r?   rH   z%ConcurrentMultiSpanProcessor.shutdown  s    56rB   rI   c                     g }| j                   D ]9  }| j                  j                  |j                  |      }|j	                  |       ; |dz  }t
        j                  j                  ||      \  }}|ry|D ]  }|j                         r y y)aF  Calls 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)	r\   r{   r   rL   r   rx   ry   waitr   )r>   rI   ry   rl   r   timeout_secdone_futuresnot_done_futuress           r?   rL   z(ConcurrentMultiSpanProcessor.force_flush  s     ''B^^**2>>>JFNN6" ( %s*)3););)@)@[*
&& "F==? # rB   )   rM   rN   rP   rQ   )rR   rS   rT   rU   rX   ra   r6   rg   r   r   r   r   rV   rW   r@   rE   rH   rY   rL   r<   rB   r?   rt   rt      s    

C 
7 74 7
(;;<  	  9=

 !!4!45
 
	
;7# $ rB   rt   c                       e Zd Zd	dedee   ddfdZedefd       Zedefd       Z	ee
j                  dej                  fd              Zy)
	EventBaseNname	timestampr:   c                 D    || _         |t               | _        y || _        y rM   )_namer   
_timestamp)r>   r   r   s      r?   ra   zEventBase.__init__&  s    
%iDO'DOrB   c                     | j                   S rM   r   rG   s    r?   r   zEventBase.name-      zzrB   c                     | j                   S rM   )r   rG   s    r?   r   zEventBase.timestamp1  s    rB   c                      y rM   r<   rG   s    r?   
attributeszEventBase.attributes5  s     	rB   rM   )rR   rS   rT   strr   rX   ra   propertyr   r   abcabstractmethodr1   
Attributesr   r<   rB   r?   r   r   %  s    (S (Xc] (d ( c   3   E,,   rB   r   c                        e Zd ZdZddefdedej                  dee	   dee	   ddf
 fdZ
edej                  fd	       Zede	fd
       Z xZS )Eventa  A 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.
    Nr   r   r   limitr:   c                 4    t         |   ||       || _        y rM   )superra   _attributes)r>   r   r   r   r   	__class__s        r?   ra   zEvent.__init__F  s     	y)%rB   c                     | j                   S rM   )r   rG   s    r?   r   zEvent.attributesP      rB   c                 d    t        | j                  t              r| j                  j                  S yNr   
isinstancer   r   droppedrG   s    r?   dropped_attributeszEvent.dropped_attributesT  (    d&&(9:##+++rB   )rR   rS   rT   rU   (_DEFAULT_OTEL_SPAN_ATTRIBUTE_COUNT_LIMITr   r1   r   r   rX   ra   r   r   r   __classcell__r   s   @r?   r   r   ;  s     (,#'G&& $$& C=	&
 }& 
&  E,,     C  rB   r   c                       fd}|S )Nc                     d}| j                   5  | j                   | g|i | nd}d d d        |r!t        j                  dj                         y y # 1 sw Y   -xY w)NFTz"Tried calling %s on an ended span.)r`   	_end_timeloggerwarningrR   )r>   r~   r   already_endedr}   s       r?   wrapperz"_check_span_ended.<locals>.wrapper\  sZ    ZZ~~%T+D+F+ $	  NN?O  Zs   AA!r<   )r}   r   s   ` r?   _check_span_endedr   [  s    	P NrB   r   r   r:   c                 X    t        | xr | j                  xs |xs | j                        S rM   )rY   is_validtrace_stater   r   s     r?   _is_valid_linkr   j  s-    MW%%L**K8K8K rB   c                   8   e Zd ZdZddddddej
                  j                  d eej                        dddfde
deej                     deej                     dee   dej                  d	ee   d
eej$                     dej
                  dee   dedee   dee   dee   ddfdZedefd       Zedefd       Zedefd       Zede
fd       Zd Zed        Zedej
                  fd       Zedeej                     fd       Zedee   fd       Z edee   fd       Z!edej                  fd       Z"edej                  fd       Z#edee   fd       Z$edeej$                     fd        Z%edefd!       Z&e e'd"d#$      dee   fd%              Z(edee   fd&       Z)d-d'efd(Z*e+dede,e
e
f   fd)       Z-e+dej                  dee,e
e.f      fd*       Z/e+d	ee   de0e,e
e.f      fd+       Z1e+d
eej$                     de0e,e
e.f      fd,       Z2y).rO   zProvides read-only access to span attributes.

    Users should NOT be creating these objects directly. `ReadableSpan`s are created as
    a direct result from using the tracing pipeline via the `Tracer`.

    Nr<   r   r   parentresourcer   eventslinkskindinstrumentation_infostatus
start_timeend_timeinstrumentation_scoper:   c                    || _         || _        || _        |	| _        || _        || _        || _        || _        || _        || _	        || _
        |"t        j                  i       | _        |
| _        y || _        |
| _        y rM   )r   _context_kind_instrumentation_info_instrumentation_scope_parent_start_timer   r   _events_linksr"   create	_resource_status)r>   r   r   r   r   r   r   r   r   r   r   r   r   r   s                 r?   ra   zReadableSpan.__init__x  s      

%9"&;#%!%%__R0DN  &DNrB   c                 d    t        | j                  t              r| j                  j                  S yr   r   rG   s    r?   r   zReadableSpan.dropped_attributes  r   rB   c                 d    t        | j                  t              r| j                  j                  S yr   )r   r   r&   r   rG   s    r?   dropped_eventszReadableSpan.dropped_events  s#    dllK0<<'''rB   c                 d    t        | j                  t              r| j                  j                  S yr   )r   r   r&   r   rG   s    r?   dropped_linkszReadableSpan.dropped_links  s#    dkk;/;;&&&rB   c                     | j                   S rM   r   rG   s    r?   r   zReadableSpan.name  r   rB   c                     | j                   S rM   r   rG   s    r?   get_span_contextzReadableSpan.get_span_context      }}rB   c                     | j                   S rM   r   rG   s    r?   r   zReadableSpan.context  s    }}rB   c                     | j                   S rM   )r   rG   s    r?   r   zReadableSpan.kind  r   rB   c                     | j                   S rM   )r   rG   s    r?   r   zReadableSpan.parent      ||rB   c                     | j                   S rM   )r   rG   s    r?   r   zReadableSpan.start_time  r   rB   c                     | j                   S rM   r   rG   s    r?   r   zReadableSpan.end_time      ~~rB   c                     | j                   S rM   )r   rG   s    r?   r   zReadableSpan.status  r   rB   c                 4    t        | j                  xs i       S rM   )r   r   rG   s    r?   r   zReadableSpan.attributes  s     0 0 6B77rB   c                 :    t        d | j                  D              S )Nc              3       K   | ]  }|  y wrM   r<   ).0events     r?   	<genexpr>z&ReadableSpan.events.<locals>.<genexpr>  s     5uU   )tupler   rG   s    r?   r   zReadableSpan.events  s    5555rB   c                 :    t        d | j                  D              S )Nc              3       K   | ]  }|  y wrM   r<   )r   links     r?   r   z%ReadableSpan.links.<locals>.<genexpr>  s     2kdTkr   )r   r   rG   s    r?   r   zReadableSpan.links  s    2dkk222rB   c                     | j                   S rM   r   rG   s    r?   r   zReadableSpan.resource  r   rB   z1.11.1z$You should use instrumentation_scope)versionreasonc                     | j                   S rM   )r   rG   s    r?   r   z!ReadableSpan.instrumentation_info  s    
 )))rB   c                     | j                   S rM   )r   rG   s    r?   r   z"ReadableSpan.instrumentation_scope  s    ***rB   indentc                    d }| j                   ,dt        j                  | j                   j                         }d }| j                  rt        j                  | j                        }d }| j                  rt        j                  | j                        }dt        | j                  j                  j                        i}| j                  j                  r| j                  j                  |d<   | j                  | j                  r| j                  | j                        nd t        | j                         ||||| j#                  | j$                        | j'                  | j(                        | j+                  | j,                        t/        j0                  | j2                  j5                               d}t/        j6                  ||      S )N0xstatus_codedescription)r   r   r   	parent_idr   r   r   r   r   r   r   )r  )r   	trace_apiformat_span_idspan_idr   r   ns_to_iso_strr   r   r   r  r   r  r   r   _format_contextr   _format_attributesr   _format_eventsr   _format_linksr   jsonloadsr   to_jsondumps)r>   r  r  r   r   r   f_spans          r?   r  zReadableSpan.to_json  sb   	;;"Y55dkk6I6IJKLI
++D,<,<=J>>))$..9H 3t||77<<=
 <<##$(LL$<$<F=! JJ7;}}$$T]]3$		N"$ 11$2B2BC))$,,7''4

4==#8#8#:;
  zz&00rB   c                     dt        j                  | j                         dt        j                  | j                         t        | j                        dS )Nr  )trace_idr
  r   )r  format_trace_idr  r	  r
  reprr   r   s    r?   r  zReadableSpan._format_context
  sR     Y66w7G7GHIJI44W__EFG 3 34
 	
rB   c                 @    | t        | t              st        |       S | S rM   )r   dict)r   s    r?   r  zReadableSpan._format_attributes  s$     !*Z*F
##rB   c                     | D cg c]L  }|j                   t        j                  |j                        t        j                  |j                        dN c}S c c}w )N)r   r   r   )r   r   r  r   r8   r  r   )r   r   s     r?   r  zReadableSpan._format_events  s_      	
   

!//@"55$$  	
 		
 	
s   AAc                     | D cg c]A  }t         j                  |j                        t         j                  |j                        dC c}S c c}w )Nr   )r8   r  r   r  r   )r   r   s     r?   r  zReadableSpan._format_links'  s[     

   //LL #55OO	 

 
	
 

s   AA)   )3rR   rS   rT   rU   r  SpanKindINTERNALr/   r0   UNSETr   r   r.   r"   r1   r   r   r   Linkr'   rX   r(   ra   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  staticmethodr	   r  r   r  r   r  r  r<   rB   r?   rO   rO   p  s    4826'+'+"$*,#,#5#5#>#>>B
 0 01$("&@D )//0 ../	
 8$ $$  	'    '':;  SM 3-  ((<= 
B C  
   
 s  
 c     i((   !6!67    HSM     (3-   	((   8E,, 8 8 6 6 6 3x	/ 3 3 (   !G*h/B&C * * +x0D'E + +#1c #1J 
 
c3h 
 
 $$	$sCx.	!  

x 

4S#X3G 

 

 
Xinn5 
$tCH~:N 
 
rB   rO   c                       e Zd ZdZdZ	 	 	 	 	 	 	 	 ddee   dee   dee   dee   dee   d	ee   d
ee   dee   fdZd Ze		 ddee   de
dee   dee   fd       Zy)
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	                 (   | j                  |t        t              | _        | j                  |t        t
              | _        | j                  |t              }	|	|	nt        | _	        | j                  |t        |	|	nt              | _        | j                  |t        |	|	nt              | _        | j                  |t         |	|	nt"              | _        | j                  |t&              | _        | j                  |t*        | j(                        | _        y rM   )_from_env_if_absentr    $_DEFAULT_OTEL_SPAN_EVENT_COUNT_LIMITr'  r!   #_DEFAULT_OTEL_SPAN_LINK_COUNT_LIMITr(  r   #_DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMITr&  r   r   r)  r   )_DEFAULT_OTEL_EVENT_ATTRIBUTE_COUNT_LIMITr*  r   (_DEFAULT_OTEL_LINK_ATTRIBUTE_COUNT_LIMITr+  r   r,  r   r-  )
r>   r&  r'  r(  r)  r*  r+  r,  r-  global_max_attributess
             r?   ra   zSpanLimits.__init__c  s-    22'0

 11&/
 !% 8 86!

 %0 "4 	 $(#;#;+ )4 &=$
  %)$<$< , )4 &>%
! $(#;#;+ )4 &=$
  %)$<$< -%
! *.)A)A%2%%	*
&rB   c                     t        |       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=))	typerR   r)  r*  r+  r&  r'  r(  r,  rG   s    r?   __repr__zSpanLimits.__repr__  s    t*%%&&;D<T<T;UUmnr  oH  oH  nI  I_  `d  `x  `x  _y  yJ  KO  K^  K^  J_  _l  mq  m|  m|  l}  }I  JN  JX  JX  IY  Yp  qu  qJ  qJ  pK  KL  M  	MrB   valueenv_vardefaultr:   c                 b   || j                   k(  ry d}|R|t        vr|S t        j                  |d      j                         j	                         }|t
        k(  ry 	 t        |      }|dk  rt        |j                  ||            |S # t        $ r t        |j                  ||            w xY w)Nz-{0} must be a non-negative integer but got {}r4   r   )	r   r   getstriplower_ENV_VALUE_UNSETrX   
ValueErrorformat)clsr:  r;  r<  err_msg	str_values         r?   r/  zSpanLimits._from_env_if_absent  s     CIIA =g%GR0668>>@I,,EI 19W^^GU;<<  E !CDDEs   B	 	%B.)NNNNNNNNrM   )rR   rS   rT   rU   r   r   rX   ra   r9  classmethodr   r/  r<   rB   r?   r$  r$  6  s    (T E )-$(#'-1.2-1.237G
 G
 SMG
 C=	G

 &c]G
 'smG
 &c]G
 'smG
 $,C=G
RM JNSM,/:B3-	# rB   r$  )r&  r'  r(  r)  r*  r+  r,  r-  c            !           e Zd ZdZ fdZdddddddej                  j                   e       ddde	dfde
dej                  deej                     d	eej                     d
ddee   dej"                  deee      deej(                     dej                  dedee   dededee   ddf  fdZd Zd Zdeej(                     fdZd Zdee
ej<                  f   ddfdZde
dej<                  ddfdZ e!de"ddfd        Z#	 	 d8de
dej"                  d!ee$   ddfd"Z%e!d#ej(                  ddfd$       Z&	 d9dedej"                  ddfd%Z'de(fd&Z)	 	 d8d'ee$   d(ee*jV                     ddfd)Z,d9d*ee$   ddfd+Z-e!de
ddfd,       Z.defd-Z/e!	 d9d.e0jb                  e2e3f   d/e0j                  e
   ddfd0       Z4d1ee5e6      d2ee6   d3ee7   ddf fd4Z8	 	 	 d:d5e6dej"                  d!ee$   d6eddf
d7Z9 xZ:S );r8   a3  See `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 `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`
    c                 H    | t         u rt        d      t        |   |       S )Nz'Span must be instantiated via a tracer.)r8   	TypeErrorr   __new__)rD  r~   r   r   s      r?   rK  zSpan.__new__  s%    $;EFFws##rB   Nr<   Tr   r   r   samplertrace_configr   r   r   r   r   rb   r   record_exceptionset_status_on_exceptionr   r:   c           	         |t        j                  i       }t        |   ||||
|||       || _        || _        || _        || _        || _        || _	        t        j                         | _        t        | j                  j                  |d| j                  j                        | _        | j#                         | _        |rg|D ]b  }t        | j                  j&                  |j(                  | j                  j*                        |_        | j$                  j-                  |       d | j/                  |	      | _        y )N)r   r   r   r   r   r   r   F)	immutablemax_value_lenrR  )r"   r   r   ra   _sampler_trace_config_record_exception_set_status_on_exception_span_processor_limitsr^   r_   r`   r   r)  r-  r   _new_eventsr   r*  r   r,  r   
_new_linksr   )r>   r   r   r   rL  rM  r   r   r   r   r   rb   r   rN  rO  limitsr   r   r   s                     r?   ra   zSpan.__init__  s    & r*H!5"7 	 	
  )!1(?%-^^%
,LL,,,,@@	
 '')$5LL55$$"&,,"C"C%!
 ##E*   ooe,rB   c                 f    t        |       j                   d| j                   d| j                   dS )Nz(name="z", context=r7  )r8  rR   r   r   rG   s    r?   r9  zSpan.__repr__2  s/    t*%%&gdjj\T]]OSTUUrB   c                 @    t        | j                  j                        S rM   )r&   rY  r'  rG   s    r?   rZ  zSpan._new_events5  s    4<<2233rB   c                    |st        | j                  j                        S g }|D ]|  }|st        |j                  |j
                        s't        | j                  j                  |j
                  | j                  j                        |_	        |j                  |       ~ t        j                  | j                  j                  |      S )NrS  )r&   rY  r(  r   r   r   r   r+  r,  r   r   from_seq)r>   r   valid_linksr   s       r?   r[  zSpan._new_links8  s    t||5566Dt||T__E#4LL44OO"&,,"C"C$ 
 ""4(  ##DLL$:$:KHHrB   c                     | j                   S rM   r   rG   s    r?   r   zSpan.get_span_contextI  r   rB   c                     | j                   5  | j                  t        j                  d       	 d d d        y |j	                         D ]  \  }}|| j
                  |<    	 d d d        y # 1 sw Y   y xY w)Nz Setting attribute on ended span.)r`   r   r   r   itemsr   )r>   r   keyr:  s       r?   set_attributeszSpan.set_attributesL  s_     ZZ~~)AB Z
 )..0
U(-  % 1 ZZs   #A*'A**A3re  r:  c                 (    | j                  ||i      S rM   )rf  )r>   re  r:  s      r?   set_attributezSpan.set_attributeW  s    ""C<00rB   r   c                 :    | j                   j                  |       y rM   )r   r   )r>   r   s     r?   
_add_eventzSpan._add_eventZ  s    E"rB   r   c                     t        | j                  j                  || j                  j                        }| j	                  t        |||             y )NrS  r   r   r   )r   rY  r*  r,  rj  r   )r>   r   r   r   s       r?   	add_eventzSpan.add_event^  sJ     'LL--,,;;


 	%#	
rB   r   c                 :    | j                   j                  |       y rM   )r   r   )r>   r   s     r?   	_add_linkzSpan._add_linkq  s    4 rB   c                     t        ||      sy t        | j                  j                  || j                  j                        }| j                  t        j                  ||             y )NrS  r   )r   r   rY  r+  r,  ro  r  r!  )r>   r   r   s      r?   add_linkzSpan.add_linku  sX    
 gz2&LL,,,,;;


 	NN%	
rB   c                 6   t        | j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                        S )N)r   r   r   r   r   r   r   r   r   r   r   r   r   )rO   r   r   r   r   r   r   r   r   r   r   r   r   r   rG   s    r?   _readable_spanzSpan._readable_span  sr    MM<<^^''<<++<<''^^!%!;!;"&"="=
 	
rB   r   r9   c                     | j                   5  | j                  t        j                  d       	 d d d        y ||n	t	               | _        d d d        | j
                  j                  | |       y # 1 sw Y   'xY w)Nz"Calling start() on a started span.rk   )r`   r   r   r   r   rX  r@   )r>   r   r9   s      r?   startz
Span.start  sl    
 ZZ+CD Z
 )4
') 	  	%%d>%J Zs   #A2A22A;r   c                 B   | j                   5  | j                  t        d      | j                  t        j                  d       	 d d d        y ||n	t               | _        d d d        | j                  j                  | j                                y # 1 sw Y   3xY w)Nz$Calling end() on a not started span.zCalling end() on an ended span.)
r`   r   RuntimeErrorr   r   r   r   rX  rE   rs  )r>   r   s     r?   endzSpan.end  s    ZZ'"#IJJ~~)@A Z *2)=X79DN  	##D$7$7$9: Zs   :BBBc                     || _         y rM   r   )r>   r   s     r?   update_namezSpan.update_name  s	    
rB   c                     | j                   d u S rM   r   rG   s    r?   is_recordingzSpan.is_recording  s    ~~%%rB   r   r  c                    t        |t              ro| j                  r&| j                  j                  t        j
                  u s|j                  t        j                  u ry |t        j                  d|       || _        y t        |t              rW| j                  r&| j                  j                  t        j
                  u s|t        j                  u ry t        ||      | _        y y )NzJDescription %s ignored. Use either `Status` or `(StatusCode, Description)`)	r   r/   r   r  r0   OKr   r   r   )r>   r   r  s      r?   
set_statuszSpan.set_status  s     ff%LL,,
=%%)9)99&` "DL
+LL,,
=Z---!&+6DL ,rB   exc_typeexc_valexc_tbc                    |t| j                         rd| j                  r| j                  |d       | j                  r9| j	                  t        t        j                  |j                   d|              t        | )  |||       y)z3Ends context manager and calls `end` on the `Span`.NT)	exceptionescapedz: )r  r  )r|  rV  rN  rW  r  r/   r0   ERRORrR   r   __exit__)r>   r  r  r  r   s       r?   r  zSpan.__exit__  s     4#4#4#6 %%%%%F ,,$.$4$4'/'8'8&9G9$E 	7F3rB   r  r  c           
         dj                  t        j                  t        |      ||j                              }t        |      j
                  }t        |      j                  }|r|dk7  r| d| n|}t        |t        t        |      t        |t        t        |      i}	|r|	j                  |       | j                  d|	|       y)z%Records an exception as a span event.r4   )r:  tbbuiltins.r  rl  N)join	tracebackformat_exceptionr8  __traceback__rS   rT   r,   r*   r   r+   r)   updaterm  )
r>   r  r   r   r  
stacktracemodulequalnameexception_typer   s
             r?   rN  zSpan.record_exception  s     WW&&YyY5L5L


 i++	?// &J. haz" 	 Ns9~ *s7|	B
 z*	 	 	
rB   )NNrM   )NNF);rR   rS   rT   rU   rK  r  r  r  r6   _UnsetLimitsr   r.   r   r#   Samplerr"   r1   r   r   r   r!  r'   rY   r(   ra   r9  rZ  r[  r   r	   AttributeValuerf  rh  r   r   rj  rX   rm  ro  rq  rO   rs  rV   rW   ru  rx  rz  r|  typingr   r/   r0   r  r   BaseExceptionr   r  rN  r   r   s   @r?   r8   r8     s   *$ 37.2!'+'+,0*,#,#5#5#>#>(5>B!%(,@D#5-5- &&5- ../	5-
 (**+5- 5- 8$5- $$5- %)5- 	'5-   5- &5- '':;5- 5- "&5-"  ((<=#5-$ 
%5-nV4I 8 I"	.sE$8$889	.		.1 1U-A-A 1d 1 #	 #d # # (,#'	

 $$
 C=	

 

& !inn ! ! ! (,

 $$
 
	
(
 
& %)8<KSMK !!4!45K 
	K
;HSM 
;T 
;    &d &  -17VZ/07 __S)7 
	7 7:44./4 -(4 '	4
 
46 (,#'
 
 $$
 C=	

 
 

rB   r8   c                       e Zd ZdZy)_SpanzProtected implementation of `opentelemetry.trace.Span`.

    This constructor exists to prevent the instantiation of the `Span` class
    by other mechanisms than through the `Tracer`.
    N)rR   rS   rT   rU   r<   rB   r?   r  r    s    rB   r  c                   ,   e Zd ZdZdej
                  dedeee	f   de
dededed	d
fdZed
ej"                  j$                  d
dd
dddfdedeej,                     dej"                  dej0                  deeej4                        dee   dededed	eej<                     fd       Zd
ej"                  j$                  d
dd
ddfdedeej,                     dej"                  dej0                  deeej4                        dee   deded	ej<                  fdZ y
)Tracerz!See `opentelemetry.trace.Tracer`.rL  r   rb   id_generatorr   span_limitsr   r:   Nc                 f    || _         || _        || _        || _        || _        || _        || _        y rM   )rL  r   rb   r  r   _span_limitsr   )r>   rL  r   rb   r  r   r  r   s           r?   ra   zTracer.__init__  s:      ,($8!'&;#rB   r<   Tr   r   r   r   r   r   rN  rO  end_on_exitc
           
   #      K   | j                  ||||||||      }
t        j                  |
|	||      5 }
|
 d d d        y # 1 sw Y   y xY ww)N)r   r   r   r   r   r   rN  rO  )r  rN  rO  )
start_spanr  use_span)r>   r   r   r   r   r   r   rN  rO  r  r7   s              r?   start_as_current_spanzTracer.start_as_current_span3  sh      !!-$;  	
 #-$;	

 J
 
 
s   3AA	AAAc	                    t        j                  |      j                         }	|	%t        |	t         j                        st        d      |	|	j                  sd }	| j                  j                         }
n|	j                  }
| j                  j                  ||
||||      }|j                  j                         r-t        j                  t         j                  j                        n,t        j                  t         j                  j                         }t        j                  |
| j                  j#                         d||j$                        }|j                  j'                         rt)        |||	| j                  | j*                  |j,                  j/                         | j0                  ||| j2                  ||| j4                  | j6                        }|j9                  ||       |S t        j:                  |      }|S )Nz2parent_span_context must be a SpanContext or None.F)	is_remotetrace_flagsr   )r   r   r   rL  r   r   rb   r   r   r   rN  rO  r\  r   )r   r9   r   )r  get_current_spanr   r   r.   rJ  r   r  generate_trace_idr  rL  should_sampledecision
is_sampled
TraceFlagsSAMPLEDDEFAULTgenerate_span_idr   r|  r  r   r   copyrb   r   r  r   ru  NonRecordingSpan)r>   r   r   r   r   r   r   rN  rO  parent_span_contextr  sampling_resultr  span_contextr7   s                  r?   r  zTracer.start_spanR  s    (88



 	 *:!6!64
 D 
 &.A.J.J"&((::<H*33H ,,44XtT:u
 ''224   !5!5!=!=>%%i&:&:&B&BC 	
 !,,..0#'33
 ##002$**55::<#22%)%>%>!1(?((&*&A&AD  JJ*WJE  --lCDrB   )!rR   rS   rT   rU   r#   r  r"   r   r[   rt   r$   r'   r$  r(   ra   r2   r  r  r  r   r   rV   rW   r1   r   r   r!  rX   rY   r
   r8   r  r  r<   rB   r?   r  r    s   +<!!< < )+GG
	< "< 2<  <  4< 
<(  26#,#5#5#>#>'+46$(!%(,  +--.   	
 $$ 01 SM  "&  
)..	! B 26#,#5#5#>#>'+46$(!%(,JJ +--.J   	J
 $$J 01J SMJ J "&J 
JrB   r  c                   >   e Zd ZdZ	 	 	 	 	 	 ddeej                     dee   dede	e
edf   dee   dee   d	dfd
Zed	efd       Z	 	 	 ddedej                  e   dej                  e   dej                  ej(                     d	df
dZded	dfdZd Zdded	efdZy)TracerProviderz)See `opentelemetry.trace.TracerProvider`.NrL  r   shutdown_on_exitactive_span_processorr  r  r:   c                    |xs
 t               | _        |t               | _        n|| _        |t	        j
                  i       | _        n|| _        |st        j                         }|| _	        |xs
 t               | _        t        j                  t        d      }|j                         j!                         dk(  | _        d | _        |r%t'        j(                  | j*                        | _        y y )Nr4   true)r[   _active_span_processorr%   r  r"   r   r   r#   _get_from_env_or_defaultrL  r$  r  r   r>  r   r@  r?  	_disabled_atexit_handleratexitregisterrH   )r>   rL  r   r  r  r  r  disableds           r?   ra   zTracerProvider.__init__  s     "D%B%D 	#  1 3D ,D%__R0DN%DN779G'7:<;;0"5!)//1V;##)??4==#AD  rB   c                     | j                   S rM   r   rG   s    r?   r   zTracerProvider.resource  r   rB   instrumenting_module_nameinstrumenting_library_version
schema_urlr   ztrace_api.Tracerc                 p   | j                   rt        j                  d       t               S |sd}t        j	                  d       |d}t        ddt        d       t        |||      }t        | j                  | j                  | j                  | j                  || j                  t        ||||            S )NzSDK is disabled.r4   z+get_tracer called with missing module name.ignorezoCall to deprecated method __init__. \(You should use InstrumentationScope\) -- Deprecated since version 1.11.1.zopentelemetry.sdk.trace)messagecategoryr  )r  r   r   r-   errorr   DeprecationWarningr'   r  rL  r   r  r  r  r(   )r>   r  r  r  r   r   s         r?   
get_tracerzTracerProvider.get_tracer  s     >>NN-.<((*%LLFG(0,.)N (,	
  3%) 
 LLMM''  )-	
 	
rB   rb   c                 :    | j                   j                  |       y)zRegisters a new :class:`SpanProcessor` for this `TracerProvider`.

        The span processors are invoked in the same order they are registered.
        N)r  rg   rf   s     r?   rg   z!TracerProvider.add_span_processor  s     	##66~FrB   c                     | j                   j                          | j                  't        j                  | j                         d| _        yy)z;Shut down the span processors added to the tracer provider.N)r  rH   r  r  
unregisterrG   s    r?   rH   zTracerProvider.shutdown   sA    ##,,.+d223#'D  ,rB   rI   c                 8    | j                   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  rL   rK   s     r?   rL   zTracerProvider.force_flush  s    $ **66~FFrB   )NNTNNN)NNNrQ   )rR   rS   rT   rU   r   r#   r  r"   rY   r   r[   rt   r$   r$  ra   r   r   r   r  r1   r   r  r6   rg   rH   rX   rL   r<   rB   r?   r  r    sF   3 /3'+!% .2,0B(**+B 8$B 	B
  %)+GM 
B {+B j)B 
BB (   ?C+/8<-
#&-
 (.s';-
 OOC(	-

 OOE$4$45-
 
-
^G G4 G(G# G$ GrB   r  )ir   r  concurrent.futuresrx   r  loggingr^   r  r  osr   timer   r1   r   r   r   r   r	   r
   r   r   r   r   r   r   r   warningsr   r   opentelemetryr   rV   r   r  opentelemetry.attributesr   opentelemetry.sdkr   'opentelemetry.sdk.environment_variablesr   r   r   r   r   r   r   r    r!   opentelemetry.sdk.resourcesr"   opentelemetry.sdk.tracer#   $opentelemetry.sdk.trace.id_generatorr$   r%   opentelemetry.sdk.utilr&   &opentelemetry.sdk.util.instrumentationr'   r(   5opentelemetry.semconv.attributes.exception_attributesr)   r*   r+   r,   opentelemetry.tracer-   r.   opentelemetry.trace.statusr/   r0   opentelemetry.utilopentelemetry.util._decoratorr2   	getLoggerrR   r   r2  r   r3  r4  r0  r1  rA  r6   r[   rt   ABCr   r   r   r   rY   r   rO   r$  r   r  r/  SPAN_ATTRIBUTE_COUNT_LIMITr8   r  r  r  r<   rB   r?   <module>r     s              1    $ ! 0 , 6 "
 
 
 1 , O .  8 9 $ A			8	$&) #+. (,/ )+. ('* $&) #  / /h=M =@S= Sl ,I @K U5E5E $ C
 C
LS Sl ##"((#))"((#))(..	 (;;#, r
9>>< r
j	D @Y @FzGY-- zGrB   