Package io.opentelemetry.api.trace
Interface SpanContext
-
@Immutable public interface SpanContextA class that represents a span context. A span context contains the state that must propagate to childSpans and across process boundaries. It contains the identifiers (atrace_idandspan_id) associated with theSpanand a set of options (currently only whether the context is sampled or not), as well as thetraceStateand theremoteflag.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, byte, TraceState)orcreateFromRemoteParent(String, String, byte, TraceState).
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidcopyTraceFlagsHexTo(char[] dest, int destOffset)static SpanContextcreate(java.lang.String traceIdHex, java.lang.String spanIdHex, byte traceFlags, TraceState traceState)Creates a newSpanContextwith the given identifiers and options.static SpanContextcreateFromRemoteParent(java.lang.String traceIdHex, java.lang.String spanIdHex, byte traceFlags, TraceState traceState)Creates a newSpanContextthat was propagated from a remote parent, with the given identifiers and options.static SpanContextgetInvalid()Returns the invalidSpanContextthat can be used for no-op operations.java.lang.StringgetSpanIdAsHexString()Returns the span identifier associated with thisSpanContext.default byte[]getSpanIdBytes()Returns the byte[] representation of the span identifier associated with thisSpanContext.bytegetTraceFlags()The byte-representation ofTraceFlags.java.lang.StringgetTraceIdAsHexString()Returns the trace identifier associated with thisSpanContext.default byte[]getTraceIdBytes()Returns the byte[] representation of the trace identifier associated with thisSpanContext.TraceStategetTraceState()Returns theTraceStateassociated with thisSpanContext.booleanisRemote()Returnstrueif theSpanContextwas propagated from a remote parent.default booleanisSampled()Whether the span in this context is sampled.default booleanisValid()Returnstrueif thisSpanContextis valid.
-
-
-
Method Detail
-
getInvalid
static SpanContext getInvalid()
Returns the invalidSpanContextthat can be used for no-op operations.- Returns:
- the invalid
SpanContext.
-
create
static SpanContext create(java.lang.String traceIdHex, java.lang.String spanIdHex, byte traceFlags, TraceState traceState)
Creates a newSpanContextwith the given identifiers and options.- Parameters:
traceIdHex- the trace identifier of the span context.spanIdHex- the span identifier of the span context.traceFlags- the byte representation of theTraceFlagstraceState- the trace state for the span context.- Returns:
- a new
SpanContextwith the given identifiers and options.
-
createFromRemoteParent
static SpanContext createFromRemoteParent(java.lang.String traceIdHex, java.lang.String spanIdHex, byte traceFlags, TraceState traceState)
Creates a newSpanContextthat was propagated from a remote parent, with the given identifiers and options.- Parameters:
traceIdHex- the trace identifier of the span context.spanIdHex- the span identifier of the span context.traceFlags- the byte representation of theTraceFlagstraceState- the trace state for the span context.- Returns:
- a new
SpanContextwith the given identifiers and options.
-
getTraceIdAsHexString
java.lang.String getTraceIdAsHexString()
Returns the trace identifier associated with thisSpanContext.- Returns:
- the trace identifier associated with this
SpanContext.
-
getTraceIdBytes
default byte[] getTraceIdBytes()
Returns the byte[] representation of the trace identifier associated with thisSpanContext.
-
getSpanIdAsHexString
java.lang.String getSpanIdAsHexString()
Returns the span identifier associated with thisSpanContext.- Returns:
- the span identifier associated with this
SpanContext.
-
getSpanIdBytes
default byte[] getSpanIdBytes()
Returns the byte[] representation of the span identifier associated with thisSpanContext.
-
isSampled
default boolean isSampled()
Whether the span in this context is sampled.
-
getTraceFlags
byte getTraceFlags()
The byte-representation ofTraceFlags.
-
copyTraceFlagsHexTo
default void copyTraceFlagsHexTo(char[] dest, int destOffset)
-
getTraceState
TraceState getTraceState()
Returns theTraceStateassociated with thisSpanContext.- Returns:
- the
TraceStateassociated with thisSpanContext.
-
isValid
default boolean isValid()
Returnstrueif thisSpanContextis valid.- Returns:
trueif thisSpanContextis valid.
-
isRemote
boolean isRemote()
Returnstrueif theSpanContextwas propagated from a remote parent.- Returns:
trueif theSpanContextwas propagated from a remote parent.
-
-