Package io.opentelemetry.api.baggage
Interface Baggage
-
- All Superinterfaces:
io.opentelemetry.context.ImplicitContextKeyed
@Immutable public interface Baggage extends io.opentelemetry.context.ImplicitContextKeyed
A map fromString
toBaggageEntry
that can be used to label anything that is associated with a specific operation.For example,
Baggage
s 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 Map<String,BaggageEntry>
asMap()
static BaggageBuilder
builder()
Creates a newBaggageBuilder
for creating Baggage.static Baggage
current()
Returns Baggage from the currentContext
, falling back to empty Baggage if none is in the current Context.static Baggage
empty()
Baggage with no entries.void
forEach(BiConsumer<? super String,? super BaggageEntry> consumer)
Iterates over all the entries in thisBaggage
.static Baggage
fromContext(io.opentelemetry.context.Context context)
static Baggage
fromContextOrNull(io.opentelemetry.context.Context context)
String
getEntryValue(String entryKey)
Returns theString
value associated with the given key, without metadata.default boolean
isEmpty()
Returns whether thisBaggage
is empty, containing no entries.int
size()
Returns the number of entries in thisBaggage
.default io.opentelemetry.context.Context
storeInContext(io.opentelemetry.context.Context context)
BaggageBuilder
toBuilder()
Create a Builder pre-initialized with the contents of this Baggage.
-
-
-
Method Detail
-
empty
static Baggage empty()
Baggage with no entries.
-
builder
static BaggageBuilder builder()
Creates a newBaggageBuilder
for creating Baggage.
-
current
static Baggage current()
Returns Baggage from the currentContext
, falling back to empty Baggage if none is in the current Context.
-
fromContext
static Baggage fromContext(io.opentelemetry.context.Context context)
-
fromContextOrNull
@Nullable static Baggage fromContextOrNull(io.opentelemetry.context.Context context)
-
storeInContext
default io.opentelemetry.context.Context storeInContext(io.opentelemetry.context.Context context)
- Specified by:
storeInContext
in interfaceio.opentelemetry.context.ImplicitContextKeyed
-
size
int size()
Returns the number of entries in thisBaggage
.
-
isEmpty
default boolean isEmpty()
Returns whether thisBaggage
is empty, containing no entries.
-
forEach
void forEach(BiConsumer<? super String,? super BaggageEntry> consumer)
Iterates over all the entries in thisBaggage
.
-
asMap
Map<String,BaggageEntry> asMap()
-
getEntryValue
@Nullable String getEntryValue(String entryKey)
Returns theString
value 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
null
if noEntry
with the givenentryKey
is 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.
-
-