Top Description Methods
io.opentelemetry.api.baggage

public Interface Baggage

extends ImplicitContextKeyed
Known Direct Implementers
io.opentelemetry.api.baggage.ImmutableBaggage
Annotations
@Immutable
Imports
io.opentelemetry.context.Context, .ImplicitContextKeyed, java.util.Map, java.util.function.BiConsumer, javax.annotation.Nullable, javax.annotation.concurrent.Immutable

A map from String to BaggageEntry that can be used to label anything that is associated with a specific operation.

For example, Baggages can be used to label stats, log messages, or debugging information.

Implementations of this interface *must* be immutable and have well-defined value-based equals/hashCode implementations. If an implementation does not strictly conform to these requirements, behavior of the OpenTelemetry APIs and default SDK cannot be guaranteed.

For this reason, it is strongly suggested that you use the implementation that is provided here via the factory methods and the BaggageBuilder.

Method Summary

Modifier and TypeMethod and Description
public Map<String, BaggageEntry>
asMap()

Returns a read-only view of this Baggage as a Map.

public static BaggageBuilder
builder()

Creates a new BaggageBuilder for creating Baggage.

public static Baggage
current()

Returns Baggage from the current Context, falling back to empty Baggage if none is in the current Context.

public static Baggage
empty()

Baggage with no entries.

public void
forEach(BiConsumer<? super String, ? super BaggageEntry> consumer)

Iterates over all the entries in this Baggage.

public static Baggage
fromContext(Context context)

Returns the Baggage from the specified Context, falling back to a empty Baggage if there is no baggage in the context.

public static Baggage
fromContextOrNull(Context context)

Returns the Baggage from the specified Context, or null if there is no baggage in the context.

public default BaggageEntry
getEntry(String
entry key to return the BaggageEntry for, or null if no Entry with the given entryKey is in this Baggage.
entryKey
)

Returns the BaggageEntry associated with the given key.

public String

Returns:

the value associated with the given key, or null if no Entry with the given entryKey is in this Baggage.
getEntryValue
(String
entry key to return the value for.
entryKey
)

Returns the String value associated with the given key, without metadata.

public default boolean
isEmpty()

Returns whether this Baggage is empty, containing no entries.

public int
size()

Returns the number of entries in this Baggage.

public default Context
storeInContext(Context context)

Implements io.opentelemetry.context.ImplicitContextKeyed.storeInContext.

Returns a new Context created by setting this into the provided Context.

public BaggageBuilder
toBuilder()

Create a Builder pre-initialized with the contents of this Baggage.

Inherited from io.opentelemetry.context.ImplicitContextKeyed:
makeCurrent

Method Detail

asMapback to summary
public Map<String, BaggageEntry> asMap()

Returns a read-only view of this Baggage as a Map.

builderback to summary
public static BaggageBuilder builder()

Creates a new BaggageBuilder for creating Baggage.

currentback to summary
public static Baggage current()

Returns Baggage from the current Context, falling back to empty Baggage if none is in the current Context.

emptyback to summary
public static Baggage empty()

Baggage with no entries.

forEachback to summary
public void forEach(BiConsumer<? super String, ? super BaggageEntry> consumer)

Iterates over all the entries in this Baggage.

fromContextback to summary
public static Baggage fromContext(Context context)

Returns the Baggage from the specified Context, falling back to a empty Baggage if there is no baggage in the context.

fromContextOrNullback to summary
public static Baggage fromContextOrNull(Context context)

Returns the Baggage from the specified Context, or null if there is no baggage in the context.

Annotations
@Nullable
getEntryback to summary
public default BaggageEntry getEntry(String entryKey)

Returns the BaggageEntry associated with the given key.

Parameters
entryKey:String

entry key to return the BaggageEntry for, or null if no Entry with the given entryKey is in this Baggage.

Annotations
@Nullable
Since
1.43.0
getEntryValueback to summary
public String getEntryValue(String entryKey)

Returns the String value associated with the given key, without metadata.

Parameters
entryKey:String

entry key to return the value for.

Returns:String

the value associated with the given key, or null if no Entry with the given entryKey is in this Baggage.

Annotations
@Nullable
isEmptyback to summary
public default boolean isEmpty()

Returns whether this Baggage is empty, containing no entries.

sizeback to summary
public int size()

Returns the number of entries in this Baggage.

storeInContextback to summary
public default Context storeInContext(Context context)

Implements io.opentelemetry.context.ImplicitContextKeyed.storeInContext.

Doc from io.opentelemetry.context.ImplicitContextKeyed.storeInContext.

Returns a new Context created by setting this into the provided Context. It is generally recommended to call Context#with(ImplicitContextKeyed) instead of this method. The following are equivalent.

  • context.with(myContextValue)
  • myContextValue.storeInContext(context)
Annotations
@Override
toBuilderback to summary
public BaggageBuilder toBuilder()

Create a Builder pre-initialized with the contents of this Baggage. The returned Builder will be set to not use an implicit parent, so any parent assignment must be done manually.