Top Description Methods
io.opentelemetry.api.trace

public Interface SpanContext

Known Direct Implementers
io.opentelemetry.api.internal.ImmutableSpanContext
Annotations
@Immutable
Imports
io.opentelemetry.api.internal.ImmutableSpanContext, .OtelEncodingUtils, javax.annotation.concurrent.Immutable

A class that represents a span context. A span context contains the state that must propagate to child Spans and across process boundaries. It contains the identifiers (a trace_id and span_id) associated with the Span and a set of options (currently only whether the context is sampled or not), as well as the traceState and the remote flag.

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. It is strongly suggested that you use the implementation that is provided here via create(String, String, TraceFlags, TraceState) or createFromRemoteParent(String, String, TraceFlags, TraceState).

Method Summary

Modifier and TypeMethod and Description
public static SpanContext

Returns:

a new SpanContext with the given identifiers and options.
create
(String
the trace identifier of the SpanContext.
traceIdHex
,
String
the span identifier of the SpanContext.
spanIdHex
,
TraceFlags
the trace flags of the SpanContext.
traceFlags
,
TraceState
the trace state for the SpanContext.
traceState
)

Creates a new SpanContext with the given identifiers and options.

public static SpanContext

Returns:

a new SpanContext with the given identifiers and options.
createFromRemoteParent
(String
the trace identifier of the SpanContext.
traceIdHex
,
String
the span identifier of the SpanContext.
spanIdHex
,
TraceFlags
the trace flags of the SpanContext.
traceFlags
,
TraceState
the trace state for the SpanContext.
traceState
)

Creates a new SpanContext that was propagated from a remote parent, with the given identifiers and options.

public static SpanContext

Returns:

the invalid SpanContext.
getInvalid
()

Returns the invalid SpanContext that can be used for no-op operations.

public String

Returns:

the span identifier associated with this SpanContext as 16 character lowercase hex (base16) String.
getSpanId
()

Returns the span identifier associated with this SpanContext as 16 character lowercase hex String.

public default byte[]

Returns:

the span identifier associated with this SpanContext as 8-byte array.
getSpanIdBytes
()

Returns the span identifier associated with this SpanContext as 8-byte array.

public TraceFlags

Returns:

the trace flags associated with this SpanContext.
getTraceFlags
()

Returns the trace flags associated with this SpanContext.

public String

Returns:

the trace identifier associated with this SpanContext as lowercase hex.
getTraceId
()

Returns the trace identifier associated with this SpanContext as 32 character lowercase hex String.

public default byte[]

Returns:

the trace identifier associated with this SpanContext as 16-byte array.
getTraceIdBytes
()

Returns the trace identifier associated with this SpanContext as 16-byte array.

public TraceState

Returns:

the TraceState associated with this SpanContext.
getTraceState
()

Returns the TraceState associated with this SpanContext.

public boolean

Returns:

true if the SpanContext was propagated from a remote parent.
isRemote
()

Returns true if the SpanContext was propagated from a remote parent.

public default boolean
isSampled()

Whether the span in this context is sampled.

public default boolean

Returns:

true if this SpanContext is valid.
isValid
()

Returns true if this SpanContext is valid.

Method Detail

createback to summary
public static SpanContext create(String traceIdHex, String spanIdHex, TraceFlags traceFlags, TraceState traceState)

Creates a new SpanContext with the given identifiers and options.

If the traceId or the spanId are invalid (ie. do not conform to the requirements for hexadecimal ids of the appropriate lengths), both will be replaced with the standard "invalid" versions (i.e. all '0's). See SpanId#isValid(CharSequence) and TraceId#isValid(CharSequence) for details.

Parameters
traceIdHex:String

the trace identifier of the SpanContext.

spanIdHex:String

the span identifier of the SpanContext.

traceFlags:TraceFlags

the trace flags of the SpanContext.

traceState:TraceState

the trace state for the SpanContext.

Returns:SpanContext

a new SpanContext with the given identifiers and options.

createFromRemoteParentback to summary
public static SpanContext createFromRemoteParent(String traceIdHex, String spanIdHex, TraceFlags traceFlags, TraceState traceState)

Creates a new SpanContext that was propagated from a remote parent, with the given identifiers and options.

If the traceId or the spanId are invalid (ie. do not conform to the requirements for hexadecimal ids of the appropriate lengths), both will be replaced with the standard "invalid" versions (i.e. all '0's). See SpanId#isValid(CharSequence) and TraceId#isValid(CharSequence) for details.

Parameters
traceIdHex:String

the trace identifier of the SpanContext.

spanIdHex:String

the span identifier of the SpanContext.

traceFlags:TraceFlags

the trace flags of the SpanContext.

traceState:TraceState

the trace state for the SpanContext.

Returns:SpanContext

a new SpanContext with the given identifiers and options.

getInvalidback to summary
public static SpanContext getInvalid()

Returns the invalid SpanContext that can be used for no-op operations.

Returns:SpanContext

the invalid SpanContext.

getSpanIdback to summary
public String getSpanId()

Returns the span identifier associated with this SpanContext as 16 character lowercase hex String.

Returns:String

the span identifier associated with this SpanContext as 16 character lowercase hex (base16) String.

getSpanIdBytesback to summary
public default byte[] getSpanIdBytes()

Returns the span identifier associated with this SpanContext as 8-byte array.

Returns:byte[]

the span identifier associated with this SpanContext as 8-byte array.

getTraceFlagsback to summary
public TraceFlags getTraceFlags()

Returns the trace flags associated with this SpanContext.

Returns:TraceFlags

the trace flags associated with this SpanContext.

getTraceIdback to summary
public String getTraceId()

Returns the trace identifier associated with this SpanContext as 32 character lowercase hex String.

Returns:String

the trace identifier associated with this SpanContext as lowercase hex.

getTraceIdBytesback to summary
public default byte[] getTraceIdBytes()

Returns the trace identifier associated with this SpanContext as 16-byte array.

Returns:byte[]

the trace identifier associated with this SpanContext as 16-byte array.

getTraceStateback to summary
public TraceState getTraceState()

Returns the TraceState associated with this SpanContext.

Returns:TraceState

the TraceState associated with this SpanContext.

isRemoteback to summary
public boolean isRemote()

Returns true if the SpanContext was propagated from a remote parent.

Returns:boolean

true if the SpanContext was propagated from a remote parent.

isSampledback to summary
public default boolean isSampled()

Whether the span in this context is sampled.

isValidback to summary
public default boolean isValid()

Returns true if this SpanContext is valid.

Returns:boolean

true if this SpanContext is valid.