opentelemetry.context package

Module contents

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.

Parameters
  • key (str) – The key of the value to retrieve.

  • context (Optional[Context]) – The context from which to retrieve the value, if None, the current context is used.

Return type

object

opentelemetry.context.set_value(key, value, context=None)[source]

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.

Parameters
  • key (str) – The key of the entry to set

  • value (object) – The value of the entry to set

  • context (Optional[Context]) – The context to copy, if None, the current context is used

Return type

Context

opentelemetry.context.remove_value(key, context=None)[source]

To remove a value, this method returns a new context with the key cleared. Note that the removed value still remains present in the old context.

Parameters
  • key (str) – The key of the entry to remove

  • context (Optional[Context]) – The context to copy, if None, the current context is used

Return type

Context

opentelemetry.context.get_current()[source]

To access the context associated with program execution, the RuntimeContext API provides a function which takes no arguments and returns a RuntimeContext.

Return type

Context

opentelemetry.context.set_current(context)[source]

To associate a context with program execution, the Context API provides a function which takes a Context.

Parameters

context (Context) – The context to use as current.

Return type

Context

opentelemetry.context.with_current_context(func)[source]

Capture the current context and apply it to the provided func.

Return type

Callable[…, object]