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 anValuefor thebooleanvalue.static Value<ByteBuffer>of(byte[] value) Returns anValuefor thebyte[]value.of(double value) Returns anValuefor thedoublevalue.of(long value) Returns anValuefor thelongvalue.
-
Method Details
-
of
-
of
Returns anValuefor thebooleanvalue. -
of
Returns anValuefor thelongvalue. -
of
Returns anValuefor thedoublevalue. -
of
Returns anValuefor thebyte[]value. -
of
-
of
-
of
Returns anValuefor the array ofKeyValuevalues.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.STRINGreturnsStringValueType.BOOLEANreturnsbooleanValueType.LONGreturnslongValueType.DOUBLEreturnsdoubleValueType.ARRAYreturnsListofValueValueType.KEY_VALUE_LISTreturnsListofKeyValueValueType.BYTESreturns 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.
-