
    i                    *   d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZ d dlmZ  ej        e          Zd!dZ e            Zd"dZd#d$dZ	 d#d%dZd&dZd'dZd(dZ ed          Z ed          Z ed          Zg d ZdS ))    )annotationsN)Token)environ)uuid4)Context_RuntimeContext)OTEL_PYTHON_CONTEXT)entry_pointsreturnr   c            
        d} t          j        t          |           }	  t          t	          t          d|                                                                          S # t          $ rd t          	                    d||             t          t	          t          d|                                                                           cY S w xY w)zWInitialize the RuntimeContext

    Returns:
        An instance of RuntimeContext.
    contextvars_contextopentelemetry_context)groupnamez*Failed to load context: %s, fallback to %s)
r   getr	   nextiterr
   load	Exceptionlogger	exception)default_contextconfigured_contexts     Q/var/www/icac/venv/lib/python3.11/site-packages/opentelemetry/context/__init__.py_load_runtime_contextr      s	    ,O %8/JJt1+   
 
 $&&  	    8	
 	
 	

t1(   
 
 $&&  	 	 	s   AA# #A+CCkeynamestrc                D    | dz   t          t                                z   S )ae  To allow cross-cutting concern to control access to their local state,
    the RuntimeContext API provides a function which takes a keyname as input,
    and returns a unique key.
    Args:
        keyname: The key name is for debugging purposes and is not required to be unique.
    Returns:
        A unique string representing the newly created key.
    -)r   r   )r   s    r   
create_keyr    I   s     S=3uww<<''    keycontexttyping.Optional[Context]'object'c                r    ||                     |           n t                                           |           S )av  To access the local state of a concern, the RuntimeContext API
    provides a function which takes a context and a key as input,
    and returns a value.

    Args:
        key: The key of the value to retrieve.
        context: The context from which to retrieve the value, if None, the current context is used.

    Returns:
        The value associated with the key.
    )r   get_current)r"   r#   s     r   	get_valuer(   U   s2      '27;;s8I8I#8N8NNr!   valuer   c                r    |t                      }|                                }||| <   t          |          S )a  To record the local state of a cross-cutting concern, the
    RuntimeContext API provides a function which takes a context, a
    key, and a value as input, and returns an updated context
    which contains the new value.

    Args:
        key: The key of the entry to set.
        value: The value of the entry to set.
        context: The context to copy, if None, the current context is used.

    Returns:
        A new `Context` containing the value set.
    )r'   copyr   )r"   r)   r#   
new_valuess       r   	set_valuer-   d   s6      --JJsO:r!   c                 4    t                                           S )zTo access the context associated with program execution,
    the Context API provides a function which takes no arguments
    and returns a Context.

    Returns:
        The current `Context` object.
    )_RUNTIME_CONTEXTr'    r!   r   r'   r'   {   s     '')))r!   Token[Context]c                6    t                               |           S )a  Associates a Context with the caller's current execution unit. Returns
    a token that can be used to restore the previous Context.

    Args:
        context: The Context to set as current.

    Returns:
        A token that can be used with `detach` to reset the context.
    )r/   attach)r#   s    r   r3   r3      s     ""7+++r!   tokenNonec                    	 t                               |            dS # t          $ r t                              d           Y dS w xY w)zResets the Context associated with the caller's current execution unit
    to the value it had before attaching a specified Context.

    Args:
        token: The Token that was returned by a previous call to attach a Context.
    zFailed to detach contextN)r/   detachr   r   r   )r4   s    r   r7   r7      sZ    5&&&&& 5 5 534444445s    $AAon_emit_recursion_countsuppress_instrumentationsuppress_http_instrumentation)r   r3   r    r7   r'   r(   r-   )r   r   )r   r   r   r   )N)r"   r   r#   r$   r   r%   )r"   r   r)   r%   r#   r$   r   r   )r   r   )r#   r   r   r1   )r4   r1   r   r5   ) 
__future__r   loggingtypingcontextvarsr   osr   uuidr   opentelemetry.context.contextr   r   #opentelemetry.environment_variablesr	   &opentelemetry.util._importlib_metadatar
   	getLogger__name__r   r   r/   r    r(   r-   r'   r3   r7   _ON_EMIT_RECURSION_COUNT_KEY_SUPPRESS_INSTRUMENTATION_KEY"_SUPPRESS_HTTP_INSTRUMENTATION_KEY__all__r0   r!   r   <module>rJ      s   # " " " " "                     C B B B B B B B C C C C C C ? ? ? ? ? ?		8	$	$$ $ $ $N )(** 	( 	( 	( 	(O O O O O  DH    .* * * *
, 
, 
, 
,
5 
5 
5 
5   *z*CDD  *
+E F F %/Z#& & "  r!   