Package io.opentelemetry.api.common
Interface Attributes
-
@Immutable public interface Attributes
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.
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
AttributesBuilder
.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description Map<AttributeKey<?>,Object>
asMap()
Returns a read-only view of thisAttributes
as aMap
.static AttributesBuilder
builder()
Returns a newAttributesBuilder
instance for creating arbitraryAttributes
.static Attributes
empty()
Returns aAttributes
instance with no attributes.void
forEach(BiConsumer<AttributeKey<?>,Object> consumer)
Iterates over all the key-value pairs of attributes contained by this instance.<T> T
get(AttributeKey<T> key)
Returns the value for the givenAttributeKey
, ornull
if not found.boolean
isEmpty()
Whether there are any attributes contained in this.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()
The number of attributes contained in this.AttributesBuilder
toBuilder()
Returns a newAttributesBuilder
instance populated with the data of thisAttributes
.
-
-
-
Method Detail
-
get
<T> T get(AttributeKey<T> key)
Returns the value for the givenAttributeKey
, ornull
if not found.
-
forEach
void forEach(BiConsumer<AttributeKey<?>,Object> consumer)
Iterates over all the key-value pairs of attributes contained by this instance.
-
size
int size()
The number of attributes contained in this.
-
isEmpty
boolean isEmpty()
Whether there are any attributes contained in this.
-
asMap
Map<AttributeKey<?>,Object> asMap()
Returns a read-only view of thisAttributes
as aMap
.
-
empty
static Attributes empty()
Returns aAttributes
instance with no attributes.
-
of
static <T> Attributes of(AttributeKey<T> key, T value)
Returns aAttributes
instance with a single key-value pair.
-
of
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
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
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
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
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
static AttributesBuilder builder()
Returns a newAttributesBuilder
instance for creating arbitraryAttributes
.
-
toBuilder
AttributesBuilder toBuilder()
Returns a newAttributesBuilder
instance populated with the data of thisAttributes
.
-
-