instrument_baggage (instrument v1.0.0)

View Source

Baggage propagation for OpenTelemetry-compatible instrumentation.

Baggage is used to propagate key-value pairs across service boundaries. It is stored as part of the context and can be encoded/decoded using W3C Baggage format.

Summary

Functions

Clears all baggage.

Decodes W3C Baggage header format to baggage. Stops adding entries past the spec-mandated maximums (180 entries / 8192 bytes).

Encodes baggage to W3C Baggage header format. Format: key1=value1;metadata1,key2=value2

Extracts baggage from a context.

Gets a value from the current baggage.

Gets a value from the current baggage with a default.

Gets all baggage entries.

Removes a key from the current baggage.

Sets a value in the current baggage (no metadata).

Sets a value in the current baggage with metadata. No-op if it would push the baggage over the W3C entry-count or byte-size limits and the key is not already present (updates to existing keys are always accepted).

Puts baggage into a context.

Types

baggage/0

-type baggage() :: #{baggage_key() => baggage_entry()}.

baggage_entry/0

-type baggage_entry() :: {baggage_value(), metadata()}.

baggage_key/0

-type baggage_key() :: binary() | atom() | string().

baggage_value/0

-type baggage_value() :: binary() | atom() | string() | number().

metadata/0

-type metadata() :: #{binary() => binary()}.

Functions

clear()

-spec clear() -> ok.

Clears all baggage.

decode(Header)

-spec decode(binary() | string()) -> baggage().

Decodes W3C Baggage header format to baggage. Stops adding entries past the spec-mandated maximums (180 entries / 8192 bytes).

encode(Baggage)

-spec encode(baggage()) -> binary().

Encodes baggage to W3C Baggage header format. Format: key1=value1;metadata1,key2=value2

from_context(Ctx)

-spec from_context(instrument_context:context()) -> baggage().

Extracts baggage from a context.

get(Key)

-spec get(baggage_key()) -> baggage_value() | undefined.

Gets a value from the current baggage.

get(Key, Default)

-spec get(baggage_key(), term()) -> baggage_value() | term().

Gets a value from the current baggage with a default.

get_all()

-spec get_all() -> #{baggage_key() => baggage_value()}.

Gets all baggage entries.

remove(Key)

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

Removes a key from the current baggage.

set(Key, Value)

-spec set(baggage_key(), baggage_value()) -> ok.

Sets a value in the current baggage (no metadata).

set(Key, Value, Metadata)

-spec set(baggage_key(), baggage_value(), metadata()) -> ok.

Sets a value in the current baggage with metadata. No-op if it would push the baggage over the W3C entry-count or byte-size limits and the key is not already present (updates to existing keys are always accepted).

to_context(Ctx, Baggage)

Puts baggage into a context.