#OpenTelemetry Baggage API

    This package models the baggage values that move alongside trace context across process boundaries.

    #Main types

    • BaggageMetadata: metadata text attached to one baggage item
    • KeyValueMetadata: one baggage key, value, and metadata triple
    • Baggage: immutable baggage container

    #Limits and validation

    The implementation enforces a few constraints when inserting entries:

    • at most 64 entries
    • at most 8192 bytes across the serialized key/value pairs
    • key length at most 256 characters
    • value length at most 256 characters

    Invalid keys or values, entry-count overflow, and total-size overflow do not raise errors. The original baggage value is returned unchanged.

    #Method behavior

    #BaggageMetadata

    • BaggageMetadata::new(metadata): trims surrounding whitespace and stores the remaining text
    • BaggageMetadata::as_string(): returns the stored metadata text
    • Default::default(): returns empty metadata

    #KeyValueMetadata

    • KeyValueMetadata::new(key, value, metadata?): packages one baggage entry description; validation happens when the entry is inserted into a Baggage

    #Baggage

    • Baggage::new(): returns an empty baggage value
    • Baggage::insert(key, value): inserts or replaces one entry with empty metadata
    • Baggage::insert_with_metadata(key, value, metadata): inserts or replaces one entry with metadata; invalid input leaves the baggage unchanged
    • Baggage::remove(key): returns a new baggage value without key
    • Baggage::get(key): returns only the entry value
    • Baggage::get_with_metadata(key): returns both the value and metadata
    • Baggage::entries(): returns a detached array of entries
    • Baggage::len(): returns the number of entries
    • Baggage::is_empty(): reports whether there are no entries

    #When to use this package

    Use interface/baggage when you need the public OpenTelemetry baggage model. The SDK uses the same public baggage and context types, so application and library code can pass baggage through interface/context without conversion.

    Baggage

    pub struct Baggage {
    entries : Map[String, KeyValueMetadata]
    kv_content_len : Int
    } derive(Eq, ToJson,
    Debug
    )

    Immutable baggage map used for cross-process propagation.

    The implementation enforces OpenTelemetry-style limits on key count and serialized size. Updates that violate those limits leave the baggage unchanged. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#overview
    impl Default for Baggage

    Baggage::entries

    fn Baggage::entries(self : Baggage) -> Array[KeyValueMetadata]

    Returns all baggage entries as an array.

    The returned array is detached from the internal map. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#get-all-values

    Baggage::get

    fn Baggage::get(self : Baggage, key : StringView) -> String?

    Looks up the string value for key. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#get-value

    Baggage::get_with_metadata

    fn Baggage::get_with_metadata(self : Baggage, key : StringView) -> (String, BaggageMetadata)?

    Looks up the value and metadata for key. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#get-all-values

    Baggage::insert

    fn Baggage::insert(self : Baggage, key : StringView, value : StringView) -> Baggage

    Inserts one baggage item with empty metadata.

    Invalid keys or values, entry-count overflow, and total-size overflow leave the baggage unchanged. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#set-value

    Baggage::insert_with_metadata

    fn Baggage::insert_with_metadata(self : Baggage, key : StringView, value : StringView, metadata : BaggageMetadata) -> Baggage

    Inserts or replaces one baggage item together with explicit metadata.

    Keys are trimmed before validation. Invalid data or limit violations return the original baggage unchanged. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#set-value

    Baggage::is_empty

    fn Baggage::is_empty(self : Baggage) -> Bool

    Returns whether the baggage contains no entries. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#get-all-values

    Baggage::len

    fn Baggage::len(self : Baggage) -> Int

    Returns the current number of baggage entries. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#get-all-values

    Baggage::new

    fn Baggage::new() -> Baggage

    Returns an empty baggage value. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#overview

    Baggage::remove

    fn Baggage::remove(self : Baggage, key : StringView) -> Baggage

    Returns a new baggage value without key.

    Removing a missing key still returns a fresh baggage value with the same contents. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#remove-value

    BaggageMetadata

    pub struct BaggageMetadata {
    metadata : String
    } derive(Compare, Eq, Hash, ToJson,
    Debug
    )

    Metadata attached to one baggage entry.

    The stored text is trimmed when constructed. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#overview

    BaggageMetadata::as_string

    fn BaggageMetadata::as_string(self : BaggageMetadata) -> String

    Returns the stored metadata text. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#overview

    BaggageMetadata::new

    fn BaggageMetadata::new(metadata : StringView) -> BaggageMetadata

    Creates metadata from one text fragment after trimming surrounding whitespace. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#set-value

    KeyValueMetadata

    One baggage entry together with its metadata payload. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#overview

    KeyValueMetadata::new

    fn KeyValueMetadata::new(key : StringView, value : StringView, metadata? : BaggageMetadata) -> KeyValueMetadata

    Creates one baggage entry description.

    This only packages the data. Validation happens when the entry is inserted into a Baggage. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#set-value

    Source Files