Top Description Methods
io.opentelemetry.api.trace

public Interface TraceState

Known Direct Implementers
io.opentelemetry.api.trace.ArrayBasedTraceState
Annotations
@Immutable
Imports
java.util.Map, java.util.function.BiConsumer, javax.annotation.Nullable, javax.annotation.concurrent.Immutable

Carries tracing-system specific context in a list of key-value pairs. TraceState allows different vendors propagate additional information and inter-operate with their legacy Id formats.

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 TraceState#builder.

Method Summary

Modifier and TypeMethod and Description
public Map<String, String>
asMap()

Returns a read-only view of this TraceState as a Map.

public static TraceStateBuilder
builder()

Returns an empty TraceStateBuilder.

public void
forEach(BiConsumer<String, String> consumer)

Iterates over all the key-value entries contained in this TraceState.

public String

Returns:

the value to which the specified key is mapped, or null if this map contains no mapping for the key.
get
(String
with which the specified value is to be associated
key
)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

public static TraceState

Returns:

the default TraceState with no entries.
getDefault
()

Returns the default TraceState with no entries.

public boolean
isEmpty()

Returns whether this TraceState is empty, containing no entries.

public int
size()

Returns the number of entries in this TraceState.

public TraceStateBuilder

Returns:

a Builder based on this TraceState.
toBuilder
()

Returns a Builder based on this TraceState.

Method Detail

asMapback to summary
public Map<String, String> asMap()

Returns a read-only view of this TraceState as a Map.

builderback to summary
public static TraceStateBuilder builder()

Returns an empty TraceStateBuilder.

forEachback to summary
public void forEach(BiConsumer<String, String> consumer)

Iterates over all the key-value entries contained in this TraceState.

getback to summary
public String get(String key)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Parameters
key:String

with which the specified value is to be associated

Returns:String

the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Annotations
@Nullable
getDefaultback to summary
public static TraceState getDefault()

Returns the default TraceState with no entries.

This method is equivalent to calling #builder().build(), but avoids new allocations.

Returns:TraceState

the default TraceState with no entries.

isEmptyback to summary
public boolean isEmpty()

Returns whether this TraceState is empty, containing no entries.

sizeback to summary
public int size()

Returns the number of entries in this TraceState.

toBuilderback to summary
public TraceStateBuilder toBuilder()

Returns a Builder based on this TraceState.

Returns:TraceStateBuilder

a Builder based on this TraceState.