Interface ExtendedAttributes
"extended" refers an extended set of allowed value types compared to standard Attributes. Notably, ExtendedAttributes values can be of type ExtendedAttributeType.VALUE, allowing attributes backed by Value.
Where standard Attributes are accepted everyone that OpenTelemetry represents key /
value pairs, ExtendedAttributes are only accepted in select places, such as log records
(e.g. ExtendedLogRecordBuilder.setAttribute(ExtendedAttributeKey, Object)).
The keys are ExtendedAttributeKeys 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 ExtendedAttributesBuilder.
Convenience methods are provided for translating to / from Attributes:
asAttributes()converts fromExtendedAttributestoAttributesExtendedAttributesBuilder.putAll(Attributes)converts fromAttributestoExtendedAttributesget(AttributeKey)supports reading values using standardAttributeKey
-
Method Summary
Modifier and TypeMethodDescriptionio.opentelemetry.api.common.AttributesReturn a view of this extended attributes with entries limited to those representable as standard attributes.asMap()Returns a read-only view of thisExtendedAttributesas aMap.static ExtendedAttributesBuilderbuilder()Returns a newExtendedAttributesBuilderinstance for creating arbitraryExtendedAttributes.static ExtendedAttributesempty()Returns aExtendedAttributesinstance with no attributes.voidforEach(BiConsumer<? super ExtendedAttributeKey<?>, ? super Object> consumer) Iterates over all the key-value pairs of attributes contained by this instance.default <T> Tget(io.opentelemetry.api.common.AttributeKey<T> key) Returns the value for the givenAttributeKey, ornullif not found.<T> Tget(ExtendedAttributeKey<T> key) Returns the value for the givenExtendedAttributeKey, ornullif not found.booleanisEmpty()Whether there are any attributes contained in this.intsize()The number of attributes contained in this.Returns a newExtendedAttributesBuilderinstance populated with the data of thisExtendedAttributes.
-
Method Details
-
get
Returns the value for the givenAttributeKey, ornullif not found. -
get
Returns the value for the givenExtendedAttributeKey, ornullif not found.Note: this method will automatically return the corresponding
Valueinstance when passed a key of typeExtendedAttributeType.VALUEand a simple attribute is found. This is the inverse ofExtendedAttributesBuilder.put(ExtendedAttributeKey, Object)when the key isExtendedAttributeType.VALUE.- If
put(ExtendedAttributeKey.stringKey("key"), "a")was called, thenget(ExtendedAttributeKey.valueKey("key"))returnsValue.of("a"). - If
put(ExtendedAttributeKey.longKey("key"), 1L)was called, thenget(ExtendedAttributeKey.valueKey("key"))returnsValue.of(1L). - If
put(ExtendedAttributeKey.doubleKey("key"), 1.0)was called, thenget(ExtendedAttributeKey.valueKey("key"))returnsValue.of(1.0). - If
put(ExtendedAttributeKey.booleanKey("key"), true)was called, thenget(ExtendedAttributeKey.valueKey("key"))returnsValue.of(true). - If
put(ExtendedAttributeKey.stringArrayKey("key"), Arrays.asList("a", "b"))was called, thenget(ExtendedAttributeKey.valueKey("key"))returnsValue.of(Value.of("a"), Value.of("b")). - If
put(ExtendedAttributeKey.longArrayKey("key"), Arrays.asList(1L, 2L))was called, thenget(ExtendedAttributeKey.valueKey("key"))returnsValue.of(Value.of(1L), Value.of(2L)). - If
put(ExtendedAttributeKey.doubleArrayKey("key"), Arrays.asList(1.0, 2.0))was called, thenget(ExtendedAttributeKey.valueKey("key"))returnsValue.of(Value.of(1.0), Value.of(2.0)). - If
put(ExtendedAttributeKey.booleanArrayKey("key"), Arrays.asList(true, false))was called, thenget(ExtendedAttributeKey.valueKey("key"))returnsValue.of(Value.of(true), Value.of(false)).
Further, if
put(ExtendedAttributeKey.valueKey("key"), Value.of(emptyList()))was called, thenget(ExtendedAttributeKey.stringArrayKey("key"))get(ExtendedAttributeKey.longArrayKey("key"))get(ExtendedAttributeKey.booleanArrayKey("key"))get(ExtendedAttributeKey.doubleArrayKey("key"))
all return an empty list (as opposed to
null). - If
-
forEach
Iterates over all the key-value pairs of attributes contained by this instance.Note:
ExtendedAttributeType.VALUEattributes will be represented as simple attributes if possible. SeeExtendedAttributesBuilder.put(ExtendedAttributeKey, Object)for more details. -
size
int size()The number of attributes contained in this. -
isEmpty
boolean isEmpty()Whether there are any attributes contained in this. -
asMap
Map<ExtendedAttributeKey<?>,Object> asMap()Returns a read-only view of thisExtendedAttributesas aMap.Note:
ExtendedAttributeType.VALUEattributes will be represented as simple attributes in this map if possible. SeeExtendedAttributesBuilder.put(ExtendedAttributeKey, Object)for more details. -
asAttributes
io.opentelemetry.api.common.Attributes asAttributes()Return a view of this extended attributes with entries limited to those representable as standard attributes. -
empty
Returns aExtendedAttributesinstance with no attributes. -
builder
Returns a newExtendedAttributesBuilderinstance for creating arbitraryExtendedAttributes.- Returns:
- a new
ExtendedAttributesBuilderinstance
-
toBuilder
ExtendedAttributesBuilder toBuilder()Returns a newExtendedAttributesBuilderinstance populated with the data of thisExtendedAttributes.
-