Top Description Methods
io.opentelemetry.api.common

public Interface Attributes

Known Direct Implementers
io.opentelemetry.api.common.ArrayBackedAttributes
Annotations
@SuppressWarnings:rawtypes
@Immutable
Static Imports
io.opentelemetry.api.common.ArrayBackedAttributes.sortAndFilterToAttributes

An immutable container for attributes.

The keys are AttributeKeys 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

Modifier and TypeMethod and Description
public Map<AttributeKey<?>, Object>
asMap()

Returns a read-only view of this Attributes as a Map.

public static AttributesBuilder
builder()

Returns a new AttributesBuilder instance for creating arbitrary Attributes.

public static Attributes
empty()

Returns a Attributes instance with no attributes.

public void
forEach(BiConsumer<? super AttributeKey<?>, ? super Object> consumer)

Iterates over all the key-value pairs of attributes contained by this instance.

public <T> T
get(AttributeKey<T> key)

Returns the value for the given AttributeKey, or null if not found.

public boolean
isEmpty()

Whether there are any attributes contained in this.

public static <T> Attributes
of(AttributeKey<T> key, T value)

Returns a Attributes instance with a single key-value pair.

public static <T, U> Attributes
of(AttributeKey<T> key1, T value1, AttributeKey<U> key2, U value2)

Returns a Attributes instance with two key-value pairs.

public static <T, U, V> Attributes
of(AttributeKey<T> key1, T value1, AttributeKey<U> key2, U value2, AttributeKey<V> key3, V value3)

Returns a Attributes instance with three key-value pairs.

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 a Attributes instance with four key-value pairs.

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 a Attributes instance with five key-value pairs.

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 a Attributes instance with the given key-value pairs.

public int
size()

The number of attributes contained in this.

public AttributesBuilder
toBuilder()

Returns a new AttributesBuilder instance populated with the data of this Attributes.

Method Detail

asMapback to summary
public Map<AttributeKey<?>, Object> asMap()

Returns a read-only view of this Attributes as a Map.

builderback to summary
public static AttributesBuilder builder()

Returns a new AttributesBuilder instance for creating arbitrary Attributes.

emptyback to summary
public static Attributes empty()

Returns a Attributes instance with no attributes.

forEachback to summary
public void forEach(BiConsumer<? super AttributeKey<?>, ? super Object> consumer)

Iterates over all the key-value pairs of attributes contained by this instance.

getback to summary
public <T> T get(AttributeKey<T> key)

Returns the value for the given AttributeKey, or null if not found.

Annotations
@Nullable
isEmptyback to summary
public boolean isEmpty()

Whether there are any attributes contained in this.

ofback to summary
public static <T> Attributes of(AttributeKey<T> key, T value)

Returns a Attributes instance with a single key-value pair.

ofback to summary
public static <T, U> Attributes of(AttributeKey<T> key1, T value1, AttributeKey<U> key2, U value2)

Returns a Attributes instance with two key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.

ofback to summary
public static <T, U, V> Attributes of(AttributeKey<T> key1, T value1, AttributeKey<U> key2, U value2, AttributeKey<V> key3, V value3)

Returns a Attributes instance with three key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.

ofback to summary
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 a Attributes instance with four key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.

ofback to summary
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 a Attributes instance with five key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.

Annotations
@SuppressWarnings:TooManyParameters
ofback to summary
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 a Attributes instance with the given key-value pairs. Order of the keys is not preserved. Duplicate keys will be removed.

Annotations
@SuppressWarnings:TooManyParameters
sizeback to summary
public int size()

The number of attributes contained in this.

toBuilderback to summary
public AttributesBuilder toBuilder()

Returns a new AttributesBuilder instance populated with the data of this Attributes.