Interface Labels


  • @Immutable
    public interface Labels
    An immutable container for labels, which are key-value pairs of Strings.

    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 ArrayBackedLabelsBuilder.

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.util.Map<java.lang.String,​java.lang.String> asMap()
      Returns a read-only view of these Labels as a Map.
      static LabelsBuilder builder()
      Creates a new LabelsBuilder instance for creating arbitrary Labels.
      static Labels empty()
      Returns a Labels instance with no attributes.
      void forEach​(java.util.function.BiConsumer<? super java.lang.String,​? super java.lang.String> consumer)
      Iterates over all the key-value pairs of labels contained by this instance.
      java.lang.String get​(java.lang.String key)
      Returns the value for the given key, or null if the key is not present.
      boolean isEmpty()
      Returns whether this instance is empty (contains no labels).
      static Labels of​(java.lang.String... keyValueLabelPairs)
      Returns a Labels instance with the provided keyValueLabelPairs.
      static Labels of​(java.lang.String key, java.lang.String value)
      Returns a Labels instance with a single key-value pair.
      static Labels of​(java.lang.String key1, java.lang.String value1, java.lang.String key2, java.lang.String value2)
      Returns a Labels instance with two key-value pairs.
      static Labels of​(java.lang.String key1, java.lang.String value1, java.lang.String key2, java.lang.String value2, java.lang.String key3, java.lang.String value3)
      Returns a Labels instance with three key-value pairs.
      static Labels of​(java.lang.String key1, java.lang.String value1, java.lang.String key2, java.lang.String value2, java.lang.String key3, java.lang.String value3, java.lang.String key4, java.lang.String value4)
      Returns a Labels instance with four key-value pairs.
      static Labels of​(java.lang.String key1, java.lang.String value1, java.lang.String key2, java.lang.String value2, java.lang.String key3, java.lang.String value3, java.lang.String key4, java.lang.String value4, java.lang.String key5, java.lang.String value5)
      Returns a Labels instance with five key-value pairs.
      int size()
      The number of key-value pairs of labels in this instance.
      LabelsBuilder toBuilder()
      Create a LabelsBuilder pre-populated with the contents of this Labels instance.
    • Method Detail

      • empty

        static Labels empty()
        Returns a Labels instance with no attributes.
      • of

        static Labels of​(java.lang.String key,
                         java.lang.String value)
        Returns a Labels instance with a single key-value pair.
      • of

        static Labels of​(java.lang.String key1,
                         java.lang.String value1,
                         java.lang.String key2,
                         java.lang.String value2)
        Returns a Labels instance with two key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.
      • of

        static Labels of​(java.lang.String key1,
                         java.lang.String value1,
                         java.lang.String key2,
                         java.lang.String value2,
                         java.lang.String key3,
                         java.lang.String value3)
        Returns a Labels instance with three key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.
      • of

        static Labels of​(java.lang.String key1,
                         java.lang.String value1,
                         java.lang.String key2,
                         java.lang.String value2,
                         java.lang.String key3,
                         java.lang.String value3,
                         java.lang.String key4,
                         java.lang.String value4)
        Returns a Labels instance with four key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.
      • of

        static Labels of​(java.lang.String key1,
                         java.lang.String value1,
                         java.lang.String key2,
                         java.lang.String value2,
                         java.lang.String key3,
                         java.lang.String value3,
                         java.lang.String key4,
                         java.lang.String value4,
                         java.lang.String key5,
                         java.lang.String value5)
        Returns a Labels instance with five key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.
      • of

        static Labels of​(java.lang.String... keyValueLabelPairs)
        Returns a Labels instance with the provided keyValueLabelPairs.
      • forEach

        void forEach​(java.util.function.BiConsumer<? super java.lang.String,​? super java.lang.String> consumer)
        Iterates over all the key-value pairs of labels contained by this instance.
      • size

        int size()
        The number of key-value pairs of labels in this instance.
      • get

        @Nullable
        java.lang.String get​(java.lang.String key)
        Returns the value for the given key, or null if the key is not present.
      • isEmpty

        boolean isEmpty()
        Returns whether this instance is empty (contains no labels).
      • asMap

        java.util.Map<java.lang.String,​java.lang.String> asMap()
        Returns a read-only view of these Labels as a Map.