Package io.opentelemetry.api.baggage
Interface Baggage
-
- All Superinterfaces:
ImplicitContextKeyed
- All Known Implementing Classes:
ImmutableBaggage
@Immutable public interface Baggage extends ImplicitContextKeyed
A map fromStringtoBaggageEntrythat 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
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.util.Map<java.lang.String,BaggageEntry>asMap()Returns a read-only view of thisBaggageas aMap.static BaggageBuilderbuilder()Creates a newBaggageBuilderfor creating Baggage.static Baggagecurrent()Returns Baggage from the currentContext, falling back to empty Baggage if none is in the current Context.static Baggageempty()Baggage with no entries.voidforEach(java.util.function.BiConsumer<? super java.lang.String,? super BaggageEntry> consumer)Iterates over all the entries in thisBaggage.static BaggagefromContext(Context context)static BaggagefromContextOrNull(Context context)default BaggageEntrygetEntry(java.lang.String entryKey)Returns theBaggageEntryassociated with the given key.java.lang.StringgetEntryValue(java.lang.String entryKey)Returns theStringvalue associated with the given key, without metadata.default booleanisEmpty()Returns whether thisBaggageis empty, containing no entries.intsize()Returns the number of entries in thisBaggage.default ContextstoreInContext(Context context)BaggageBuildertoBuilder()Create a Builder pre-initialized with the contents of this Baggage.-
Methods inherited from interface io.opentelemetry.context.ImplicitContextKeyed
makeCurrent
-
-
-
-
Method Detail
-
empty
static Baggage empty()
Baggage with no entries.
-
builder
static BaggageBuilder builder()
Creates a newBaggageBuilderfor creating Baggage.
-
current
static Baggage current()
Returns Baggage from the currentContext, falling back to empty Baggage if none is in the current Context.
-
storeInContext
default Context storeInContext(Context context)
Description copied from interface:ImplicitContextKeyedReturns a newContextcreated by settingthisinto the providedContext. It is generally recommended to callContext.with(ImplicitContextKeyed)instead of this method. The following are equivalent.context.with(myContextValue)myContextValue.storeInContext(context)
- Specified by:
storeInContextin interfaceImplicitContextKeyed
-
size
int size()
Returns the number of entries in thisBaggage.
-
isEmpty
default boolean isEmpty()
Returns whether thisBaggageis empty, containing no entries.
-
forEach
void forEach(java.util.function.BiConsumer<? super java.lang.String,? super BaggageEntry> consumer)
Iterates over all the entries in thisBaggage.
-
asMap
java.util.Map<java.lang.String,BaggageEntry> asMap()
Returns a read-only view of thisBaggageas aMap.
-
getEntryValue
@Nullable java.lang.String getEntryValue(java.lang.String entryKey)
Returns theStringvalue associated with the given key, without metadata.- Parameters:
entryKey- entry key to return the value for.- Returns:
- the value associated with the given key, or
nullif noEntrywith the givenentryKeyis in thisBaggage.
-
toBuilder
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.
-
getEntry
@Nullable default BaggageEntry getEntry(java.lang.String entryKey)
Returns theBaggageEntryassociated with the given key.- Parameters:
entryKey- entry key to return theBaggageEntryfor, ornullif noEntrywith the givenentryKeyis in thisBaggage.- Since:
- 1.43.0
-
-