
    gz              	       \   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
 d dlmZ  e j                  e      ZdefdZ e       Zd	edefd
Zddedej(                  e   ddfdZ	 ddedddej(                  e   defdZdefdZdedefdZdeddfdZ ed      Z ed      Zg dZy)    N)environ)uuid4)Context_RuntimeContext)OTEL_PYTHON_CONTEXT)entry_pointsreturnc            
      P   d} t        j                  t        |       }	  t        t	        t        d|                  j                                S # t        $ rL t        j                  d||         t        t	        t        d|                   j                                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     S/var/www/openai/venv/lib/python3.12/site-packages/opentelemetry/context/__init__.py_load_runtime_contextr      s     ,O %8/Jt1+
 $& 	  8	

t1(
 $& 	s   1A AB%$B%keynamec                 4    | 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.
    -)strr   )r   s    r   
create_keyr   F   s     S=3uw<''    keycontextobjectc                 Z    ||j                  |       S t               j                  |       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%   R   s*      '27;;sN8I8I#8NNr   valuec                 Z    |
t               }|j                         }||| <   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*   a   s/      -JJsO:r   c                  *    t         j                         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$   x   s     ''))r   c                 ,    t         j                  |       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   r/   r/      s     ""7++r   tokenc                 x    	 t         j                  |        y# t        $ r t        j	                  d       Y y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   )r0   s    r   r2   r2      s3    5& 5345s    99suppress_instrumentationsuppress_http_instrumentation)r   r/   r   r2   r$   r%   r*   )N)loggingtypingosr   uuidr   opentelemetry.context.contextr   r   #opentelemetry.environment_variablesr   &opentelemetry.util._importlib_metadatar   	getLogger__name__r   r   r,   r   r   Optionalr%   r*   r$   r"   r/   r2   _SUPPRESS_INSTRUMENTATION_KEY"_SUPPRESS_HTTP_INSTRUMENTATION_KEY__all__r-   r   r   <module>rB      s       C C ?			8	$$ $N )* 	( 	( 	(O3 O!9 OX O  DH	(.(@.*W *
,G 
, 
,
5& 
5T 
5  !++E F %/#& "r   