File: //var/opt/nydus/ops/mysql/opentelemetry/context/__pycache__/__init__.cpython-39.pyc
a
�,�h� � @ s8 d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl m
Z
mZ d dlm
Z
d dlmZ e �e�Zdae�� Zejdejd ejf d
�Zeed�dd
�Zeed�dd�Zd#eeje
dd�dd�Zd$edeje
e
d�dd�Zee
d�dd��Z ee
e!d�dd��Z"ee!dd�dd ��Z#ed!�Z$ed"�Z%dS )%� N)�wraps)�environ)�uuid4)�Context�_RuntimeContext)�OTEL_PYTHON_CONTEXT)�entry_points�_F.)�bound)�func�returnc sN t � �tjtjtjf tjtjtjf tjtj d�� fdd��}t�t|�S )zvA decorator used to initialize the global RuntimeContext
Returns:
A wrapper of the decorated method.
)�args�kwargsr c s� t �f td u r\d}t�t|�}ztttd|d����� � aW n t yZ t
�d|� Y n0 W d � n1 sp0 Y � | i |��S )NZcontextvars_contextZopentelemetry_context)�group�namezFailed to load context: %s)�_RUNTIME_CONTEXT_LOCK�_RUNTIME_CONTEXTr �getr �next�iterr �load� Exception�logger� exception)r
r Zdefault_contextZconfigured_context�r � �W/opt/nydus/tmp/pip-target-wkfpz8uv/lib64/python/mysql/opentelemetry/context/__init__.py�wrapper* s$ ���� 0z&_load_runtime_context.<locals>.wrapper)r �typing�Tuple�Any�Dict�Optional�castr )r r r r r �_load_runtime_context# s
�r$ )�keynamer c C s | d t t� � 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% r r r �
create_keyL s r( �object)�key�contextr c C s |dur|� | �S 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.
N)r �get_current)r* r+ r r r � get_valueX s r- )r* �valuer+ r c C s&