Package io.opentelemetry.api.common
Class Attributes
- java.lang.Object
-
- io.opentelemetry.api.common.Attributes
-
- All Implemented Interfaces:
ReadableAttributes
@Immutable public abstract class Attributes extends Object implements ReadableAttributes
An immutable container for attributes.The keys are
AttributeKey
s and the values are Object instances that match the type of the provided key.Null keys will be silently dropped.
Note: The behavior of null-valued attributes is undefined, and hence strongly discouraged.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Attributes.Builder
Enables the creation of anAttributes
instance with an arbitrary number of key-value pairs.
-
Constructor Summary
Constructors Constructor Description Attributes()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static Attributes.Builder
builder()
Returns a newAttributes.Builder
instance for creating arbitraryAttributes
.static Attributes.Builder
builder(ReadableAttributes attributes)
Returns a newAttributes.Builder
instance from ReadableAttributes.static Attributes
empty()
Returns aAttributes
instance with no attributes.void
forEach(AttributeConsumer consumer)
Iterates over all the key-value pairs of attributes contained by this instance.<T> T
get(AttributeKey<T> key)
V
get(K key)
boolean
isEmpty()
static <T> Attributes
of(AttributeKey<T> key, T value)
Returns aAttributes
instance with a single key-value pair.static <T,U>
Attributesof(AttributeKey<T> key1, T value1, AttributeKey<U> key2, U value2)
Returns aAttributes
instance with two key-value pairs.static <T,U,V>
Attributesof(AttributeKey<T> key1, T value1, AttributeKey<U> key2, U value2, AttributeKey<V> key3, V value3)
Returns aAttributes
instance with three key-value pairs.static <T,U,V,W>
Attributesof(AttributeKey<T> key1, T value1, AttributeKey<U> key2, U value2, AttributeKey<V> key3, V value3, AttributeKey<W> key4, W value4)
Returns aAttributes
instance with four key-value pairs.static <T,U,V,W,X>
Attributesof(AttributeKey<T> key1, T value1, AttributeKey<U> key2, U value2, AttributeKey<V> key3, V value3, AttributeKey<W> key4, W value4, AttributeKey<X> key5, X value5)
Returns aAttributes
instance with five key-value pairs.static <T,U,V,W,X,Y>
Attributesof(AttributeKey<T> key1, T value1, AttributeKey<U> key2, U value2, AttributeKey<V> key3, V value3, AttributeKey<W> key4, W value4, AttributeKey<X> key5, X value5, AttributeKey<Y> key6, Y value6)
Returns aAttributes
instance with the given key-value pairs.int
size()
abstract Attributes.Builder
toBuilder()
Returns a newAttributes.Builder
instance populated with the data of thisAttributes
.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.opentelemetry.api.common.ReadableAttributes
isEmpty, size
-
-
-
-
Method Detail
-
get
public <T> T get(AttributeKey<T> key)
- Specified by:
get
in interfaceReadableAttributes
-
forEach
public void forEach(AttributeConsumer consumer)
Description copied from interface:ReadableAttributes
Iterates over all the key-value pairs of attributes contained by this instance.- Specified by:
forEach
in interfaceReadableAttributes
-
empty
public static Attributes empty()
Returns aAttributes
instance with no attributes.
-
of
public static <T> Attributes of(AttributeKey<T> key, T value)
Returns aAttributes
instance with a single key-value pair.
-
of
public static <T,U> Attributes of(AttributeKey<T> key1, T value1, AttributeKey<U> key2, U value2)
Returns aAttributes
instance with two key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.
-
of
public static <T,U,V> Attributes of(AttributeKey<T> key1, T value1, AttributeKey<U> key2, U value2, AttributeKey<V> key3, V value3)
Returns aAttributes
instance with three key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.
-
of
public static <T,U,V,W> Attributes of(AttributeKey<T> key1, T value1, AttributeKey<U> key2, U value2, AttributeKey<V> key3, V value3, AttributeKey<W> key4, W value4)
Returns aAttributes
instance with four key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.
-
of
public static <T,U,V,W,X> Attributes of(AttributeKey<T> key1, T value1, AttributeKey<U> key2, U value2, AttributeKey<V> key3, V value3, AttributeKey<W> key4, W value4, AttributeKey<X> key5, X value5)
Returns aAttributes
instance with five key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.
-
of
public static <T,U,V,W,X,Y> Attributes of(AttributeKey<T> key1, T value1, AttributeKey<U> key2, U value2, AttributeKey<V> key3, V value3, AttributeKey<W> key4, W value4, AttributeKey<X> key5, X value5, AttributeKey<Y> key6, Y value6)
Returns aAttributes
instance with the given key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.
-
builder
public static Attributes.Builder builder()
Returns a newAttributes.Builder
instance for creating arbitraryAttributes
.
-
builder
public static Attributes.Builder builder(ReadableAttributes attributes)
Returns a newAttributes.Builder
instance from ReadableAttributes.
-
toBuilder
public abstract Attributes.Builder toBuilder()
Returns a newAttributes.Builder
instance populated with the data of thisAttributes
.
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
get
@Nullable public V get(K key)
-
-