Package io.opentelemetry.api.common
Interface Value<T>
-
- Type Parameters:
T
- the type. SeegetValue()
for description of types.
- All Known Implementing Classes:
KeyValueList
,ValueArray
,ValueBoolean
,ValueBytes
,ValueDouble
,ValueLong
,ValueString
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
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.String
asString()
Return a string encoding of thisValue
.ValueType
getType()
Returns the type of thisValue
.T
getValue()
Returns the value for thisValue
.static Value<java.lang.Boolean>
of(boolean value)
Returns anValue
for theboolean
value.static Value<java.nio.ByteBuffer>
of(byte[] value)
Returns anValue
for thebyte[]
value.static Value<java.lang.Double>
of(double value)
Returns anValue
for thedouble
value.static Value<java.lang.Long>
of(long value)
Returns anValue
for thelong
value.static Value<java.util.List<KeyValue>>
of(KeyValue... value)
static Value<java.util.List<Value<?>>>
of(Value<?>... value)
static Value<java.lang.String>
of(java.lang.String value)
Returns anValue
for theString
value.static Value<java.util.List<Value<?>>>
of(java.util.List<Value<?>> value)
static Value<java.util.List<KeyValue>>
of(java.util.Map<java.lang.String,Value<?>> value)
-
-
-
Method Detail
-
of
static Value<java.lang.String> of(java.lang.String value)
Returns anValue
for theString
value.
-
of
static Value<java.util.List<KeyValue>> of(KeyValue... value)
Returns anValue
for the array ofKeyValue
values.KeyValue.getKey()
values should not repeat - duplicates may be dropped.
-
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
java.lang.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.
-
-