opentelemetry.context package
Submodules
Module contents
- opentelemetry.context.attach(context)[source]
Associates a Context with the caller’s current execution unit. Returns a token that can be used to restore the previous Context.
- Parameters:
context – The Context to set as current.
- Returns:
A token that can be used with
detach
to reset the context.
- opentelemetry.context.create_key(keyname)[source]
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. :type keyname:
str
:param keyname: The key name is for debugging purposes and is not required to be unique.- Return type:
- Returns:
A unique string representing the newly created key.
- opentelemetry.context.detach(token)[source]
Resets the Context associated with the caller’s current execution unit to the value it had before attaching a specified Context.
- Parameters:
token – The Token that was returned by a previous call to attach a Context.
- opentelemetry.context.get_current()[source]
To access the context associated with program execution, the Context API provides a function which takes no arguments and returns a Context.
- Return type:
- Returns:
The current Context object.
- opentelemetry.context.get_value(key, context=None)[source]
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.