Interface TraceState
Implementation is optimized for a small list of key-value pairs.
Key is opaque string up to 256 characters printable. It MUST begin with a lowercase letter, and can only contain lowercase letters a-z, digits 0-9, underscores _, dashes -, asterisks *, and forward slashes /.
Value is opaque string up to 256 characters printable ASCII RFC0020 characters (i.e., the range 0x20 to 0x7E) except comma , and =.
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.
Implementations of this interface that do not conform to the W3C specification risk incompatibility with W3C-compatible implementations.
For these reasons, it is strongly suggested that you use the implementation that is provided
here via the builder()
.
-
Method Summary
Modifier and TypeMethodDescriptionasMap()
Returns a read-only view of thisTraceState
as aMap
.static TraceStateBuilder
builder()
Returns an emptyTraceStateBuilder
.void
forEach
(BiConsumer<String, String> consumer) Iterates over all the key-value entries contained in thisTraceState
.Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.static TraceState
Returns the defaultTraceState
with no entries.boolean
isEmpty()
Returns whether thisTraceState
is empty, containing no entries.int
size()
Returns the number of entries in thisTraceState
.Returns aBuilder
based on thisTraceState
.
-
Method Details
-
getDefault
Returns the defaultTraceState
with no entries.This method is equivalent to calling
#builder().build()
, but avoids new allocations.- Returns:
- the default
TraceState
with no entries.
-
builder
Returns an emptyTraceStateBuilder
. -
get
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.- Parameters:
key
- with which the specified value is to be associated- Returns:
- the value to which the specified key is mapped, or null if this map contains no mapping for the key.
-
size
int size()Returns the number of entries in thisTraceState
. -
isEmpty
boolean isEmpty()Returns whether thisTraceState
is empty, containing no entries. -
forEach
Iterates over all the key-value entries contained in thisTraceState
. -
asMap
Returns a read-only view of thisTraceState
as aMap
. -
toBuilder
TraceStateBuilder toBuilder()Returns aBuilder
based on thisTraceState
.- Returns:
- a
Builder
based on thisTraceState
.
-