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.StringasString()Return a string encoding of thisValue.ValueTypegetType()Returns the type of thisValue.TgetValue()Returns the value for thisValue.static Value<java.lang.Boolean>of(boolean value)Returns anValuefor thebooleanvalue.static Value<java.nio.ByteBuffer>of(byte[] value)Returns anValuefor thebyte[]value.static Value<java.lang.Double>of(double value)Returns anValuefor thedoublevalue.static Value<java.lang.Long>of(long value)Returns anValuefor thelongvalue.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 anValuefor theStringvalue.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 anValuefor theStringvalue.
-
of
static Value<java.util.List<KeyValue>> of(KeyValue... value)
Returns anValuefor the array ofKeyValuevalues.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.STRINGreturnsStringValueType.BOOLEANreturnsbooleanValueType.LONGreturnslongValueType.DOUBLEreturnsdoubleValueType.ARRAYreturnsListofValueValueType.KEY_VALUE_LISTreturnsListofKeyValueValueType.BYTESreturns 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.
-
-