Interface Baggage

  • All Superinterfaces:
    ImplicitContextKeyed
    All Known Implementing Classes:
    ImmutableBaggage

    @Immutable
    public interface Baggage
    extends ImplicitContextKeyed
    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 Detail

      • empty

        static Baggage empty()
        Baggage with no entries.
      • current

        static Baggage current()
        Returns Baggage from the current Context, falling back to empty Baggage if none is in the current Context.
      • fromContext

        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.
      • fromContextOrNull

        @Nullable
        static Baggage fromContextOrNull​(Context context)
        Returns the Baggage from the specified Context, or null if there is no baggage in the context.
      • size

        int size()
        Returns the number of entries in this Baggage.
      • isEmpty

        default boolean isEmpty()
        Returns whether this Baggage is empty, containing no entries.
      • forEach

        void forEach​(java.util.function.BiConsumer<? super java.lang.String,​? super BaggageEntry> consumer)
        Iterates over all the entries in this Baggage.
      • asMap

        java.util.Map<java.lang.String,​BaggageEntry> asMap()
        Returns a read-only view of this Baggage as a Map.
      • getEntryValue

        @Nullable
        java.lang.String getEntryValue​(java.lang.String entryKey)
        Returns the String 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 no Entry with the given entryKey is in this Baggage.
      • 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 the BaggageEntry associated with the given key.
        Parameters:
        entryKey - entry key to return the BaggageEntry for, or null if no Entry with the given entryKey is in this Baggage.
        Since:
        1.43.0