Package io.opentelemetry.api.common
Interface Labels
-
@Immutable public interface LabelsAn immutable container for labels, which are key-value pairs ofStrings.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 Map<String,String>asMap()static LabelsBuilderbuilder()Creates a newLabelsBuilderinstance for creating arbitraryLabels.static Labelsempty()Returns aLabelsinstance with no attributes.voidforEach(BiConsumer<String,String> consumer)Iterates over all the key-value pairs of labels contained by this instance.Stringget(String key)Returns the value for the givenkey, ornullif the key is not present.booleanisEmpty()Returns whether this instance is empty (contains no labels).static Labelsof(String... keyValueLabelPairs)Returns aLabelsinstance with the providedkeyValueLabelPairs.static Labelsof(String key, String value)Returns aLabelsinstance with a single key-value pair.static Labelsof(String key1, String value1, String key2, String value2)Returns aLabelsinstance with two key-value pairs.static Labelsof(String key1, String value1, String key2, String value2, String key3, String value3)Returns aLabelsinstance with three key-value pairs.static Labelsof(String key1, String value1, String key2, String value2, String key3, String value3, String key4, String value4)Returns aLabelsinstance with four key-value pairs.static Labelsof(String key1, String value1, String key2, String value2, String key3, String value3, String key4, String value4, String key5, String value5)Returns aLabelsinstance with five key-value pairs.intsize()The number of key-value pairs of labels in this instance.LabelsBuildertoBuilder()Create aLabelsBuilderpre-populated with the contents of this Labels instance.
-
-
-
Method Detail
-
builder
static LabelsBuilder builder()
Creates a newLabelsBuilderinstance for creating arbitraryLabels.
-
of
static Labels of(String key, String value)
Returns aLabelsinstance with a single key-value pair.
-
of
static Labels of(String key1, String value1, String key2, String value2)
Returns aLabelsinstance with two key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.
-
of
static Labels of(String key1, String value1, String key2, String value2, String key3, String value3)
Returns aLabelsinstance with three key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.
-
of
static Labels of(String key1, String value1, String key2, String value2, String key3, String value3, String key4, String value4)
Returns aLabelsinstance with four key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.
-
of
static Labels of(String key1, String value1, String key2, String value2, String key3, String value3, String key4, String value4, String key5, String value5)
Returns aLabelsinstance with five key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.
-
of
static Labels of(String... keyValueLabelPairs)
Returns aLabelsinstance with the providedkeyValueLabelPairs.
-
forEach
void forEach(BiConsumer<String,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 String get(String key)
Returns the value for the givenkey, ornullif the key is not present.
-
isEmpty
boolean isEmpty()
Returns whether this instance is empty (contains no labels).
-
toBuilder
LabelsBuilder toBuilder()
Create aLabelsBuilderpre-populated with the contents of this Labels instance.
-
-