Package io.opentelemetry.api.common
Interface Value<T>
- Type Parameters:
T
- the type. SeegetValue()
for description of types.
public interface Value<T>
Value mirrors the proto AnyValue
message type, and is used to model any type.
It can be used to represent:
- Primitive values via
of(long)
,of(String)
,of(boolean)
,of(double)
. - String-keyed maps (i.e. associative arrays, dictionaries) via
of(KeyValue...)
,of(Map)
. Note, because map values are typeValue
, maps can be nested within other maps. - Arrays (heterogeneous or homogenous) via
of(Value[])
. Note, because array values are typeValue
, arrays can contain primitives, complex types like maps or arrays, or any combination. - Raw bytes via
of(byte[])
Currently, Value is only used as an argument for LogRecordBuilder.setBody(Value)
.
- Since:
- 1.42.0
-
Method Summary
Modifier and TypeMethodDescriptionasString()
Return a string encoding of thisValue
.getType()
Returns the type of thisValue
.getValue()
Returns the value for thisValue
.of
(boolean value) Returns anValue
for theboolean
value.static Value<ByteBuffer>
of
(byte[] value) Returns anValue
for thebyte[]
value.of
(double value) Returns anValue
for thedouble
value.of
(long value) Returns anValue
for thelong
value.
-
Method Details
-
of
-
of
Returns anValue
for theboolean
value. -
of
Returns anValue
for thelong
value. -
of
Returns anValue
for thedouble
value. -
of
Returns anValue
for thebyte[]
value. -
of
-
of
-
of
Returns anValue
for the array ofKeyValue
values.KeyValue.getKey()
values should not repeat - duplicates may be dropped. -
of
-
getType
ValueType getType()Returns the type of thisValue
. Useful for building switch statements. -
getValue
T getValue()Returns the value for thisValue
.The return type varies by
getType()
as described below:ValueType.STRING
returnsString
ValueType.BOOLEAN
returnsboolean
ValueType.LONG
returnslong
ValueType.DOUBLE
returnsdouble
ValueType.ARRAY
returnsList
ofValue
ValueType.KEY_VALUE_LIST
returnsList
ofKeyValue
ValueType.BYTES
returns read onlyByteBuffer
. SeeByteBuffer.asReadOnlyBuffer()
.
-
asString
String asString()Return a string encoding of thisValue
. This is intended to be a fallback serialized representation in case there is no suitable encoding that can utilizegetType()
/getValue()
to serialize specific types.WARNING: No guarantees are made about the encoding of this string response. It MAY change in a future minor release. If you need a reliable string encoding, write your own serializer.
-