Package io.opentelemetry.api.trace
Class SpanContext
- java.lang.Object
-
- io.opentelemetry.api.trace.SpanContext
-
@Immutable public abstract class SpanContext extends Object
A 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.
-
-
Constructor Summary
Constructors Constructor Description SpanContext()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcopyTraceFlagsHexTo(char[] dest, int destOffset)static SpanContextcreate(String traceIdHex, String spanIdHex, byte traceFlags, TraceState traceState)Creates a newSpanContextwith the given identifiers and options.static SpanContextcreateFromRemoteParent(String traceIdHex, 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.StringgetSpanIdAsHexString()Returns the span identifier associated with thisSpanContext.byte[]getSpanIdBytes()Returns the byte[] representation of the span identifier associated with thisSpanContext.abstract bytegetTraceFlags()The byte-representation ofTraceFlags.StringgetTraceIdAsHexString()Returns the trace identifier associated with thisSpanContext.byte[]getTraceIdBytes()Returns the byte[] representation of the trace identifier associated with thisSpanContext.abstract TraceStategetTraceState()Returns theTraceStateassociated with thisSpanContext.abstract booleanisRemote()Returnstrueif theSpanContextwas propagated from a remote parent.booleanisSampled()Whether the span in this context is sampled.booleanisValid()Returnstrueif thisSpanContextis valid.
-
-
-
Method Detail
-
getInvalid
public static SpanContext getInvalid()
Returns the invalidSpanContextthat can be used for no-op operations.- Returns:
- the invalid
SpanContext.
-
create
public static SpanContext create(String traceIdHex, 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
public static SpanContext createFromRemoteParent(String traceIdHex, 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
public String getTraceIdAsHexString()
Returns the trace identifier associated with thisSpanContext.- Returns:
- the trace identifier associated with this
SpanContext.
-
getTraceIdBytes
@Memoized public byte[] getTraceIdBytes()
Returns the byte[] representation of the trace identifier associated with thisSpanContext.
-
getSpanIdAsHexString
public String getSpanIdAsHexString()
Returns the span identifier associated with thisSpanContext.- Returns:
- the span identifier associated with this
SpanContext.
-
getSpanIdBytes
@Memoized public byte[] getSpanIdBytes()
Returns the byte[] representation of the span identifier associated with thisSpanContext.
-
isSampled
public boolean isSampled()
Whether the span in this context is sampled.
-
getTraceFlags
public abstract byte getTraceFlags()
The byte-representation ofTraceFlags.
-
copyTraceFlagsHexTo
public void copyTraceFlagsHexTo(char[] dest, int destOffset)
-
getTraceState
public abstract TraceState getTraceState()
Returns theTraceStateassociated with thisSpanContext.- Returns:
- the
TraceStateassociated with thisSpanContext.
-
isValid
@Memoized public boolean isValid()
Returnstrueif thisSpanContextis valid.- Returns:
trueif thisSpanContextis valid.
-
isRemote
public abstract boolean isRemote()
Returnstrueif theSpanContextwas propagated from a remote parent.- Returns:
trueif theSpanContextwas propagated from a remote parent.
-
-