otel_ctx (OpenTelemetry API v1.4.0)

View Source

Ctx is responsible for propagating values within a process that are associated with a particular Trace or set of Baggage. OpenTelemetry.Tracer and OpenTelemetry.Baggage handle updating the Context.

Functions in this module include variants that explicitly take a Ctx argument and variants that implicitly use the current context, which is the context stored in the process dictionary.

Summary

Types

A context key.

t/0

A context map.

An opaque token that represents a context.

A context value.

Functions

Attaches the given context to the current process.

Removes all key-value pairs from the current context.

Removes all key-value pairs from the given context.

Detaches the given context from the current process.

Returns the current context.

Gets a value from the current context under the given key.

Gets a value from the current context under the given key, or returns the default value if the key is not present in the current context.

Gets a value from the given context under the given key, or returns the default value if the key is not present in the given context or if Ctx is undefined.

Creates a new context.

Removes the value under the given key from the current context.

Removes the value under the given key from the given context.

Sets a value in the current context under the given key.

Sets a value in the given context under the given key.

Attaches a context and runs a function, detaching the context at the end.

Types

key/0

-type key() :: term().

A context key.

t/0

-type t() :: map() | undefined.

A context map.

token/0

-opaque token()

An opaque token that represents a context.

value/0

-type value() :: term().

A context value.

Functions

attach(Ctx)

-spec attach(t()) -> token().

Attaches the given context to the current process.

Essentially, this sets Ctx as the current context .

clear()

-spec clear() -> ok.

Removes all key-value pairs from the current context.

clear(Ctx)

-spec clear(t()) -> t().

Removes all key-value pairs from the given context.

Returns an empty context.

detach(Token)

-spec detach(token()) -> t() | undefined.

Detaches the given context from the current process.

get_current()

-spec get_current() -> map().

Returns the current context.

get_value(Key)

-spec get_value(term()) -> eqwalizer:dynamic().

Gets a value from the current context under the given key.

get_value(Key, Default)

-spec get_value(term(), term()) -> eqwalizer:dynamic().

Gets a value from the current context under the given key, or returns the default value if the key is not present in the current context.

get_value(Ctx, Key, Default)

-spec get_value(t(), term(), term()) -> eqwalizer:dynamic().

Gets a value from the given context under the given key, or returns the default value if the key is not present in the given context or if Ctx is undefined.

new()

-spec new() -> t().

Creates a new context.

remove(Key)

-spec remove(term()) -> ok.

Removes the value under the given key from the current context.

remove(Ctx, Key)

-spec remove(t(), term()) -> t().

Removes the value under the given key from the given context.

Returns the updated context.

set_value(Key, Value)

-spec set_value(term(), term()) -> ok.

Sets a value in the current context under the given key.

set_value(Ctx, Key, Value)

-spec set_value(t(), term(), term()) -> t().

Sets a value in the given context under the given key.

Returns the updated context.

with_ctx(Ctx, Fun)

-spec with_ctx(t(), fun(() -> term())) -> {term(), t()}.

Attaches a context and runs a function, detaching the context at the end.

Returns the detached context.