SpanContext contains the state that must propagate to child spans and across process boundaries. It includes the identifiers (trace_id and span_id) associated with the span, a set of flags, and the remote flag.
Overview
A span context is an immutable object that represents the distributed tracing context. It is propagated both in-process to child spans and across process boundaries through context propagation mechanisms. See the OpenTelemetry specification for more details.Properties
traceId
Type:ByteVector
Returns the trace identifier associated with this SpanContext as a 16-byte vector.
traceIdHex
Type:String
Returns the trace identifier associated with this SpanContext as a 32 character lowercase hex string.
spanId
Type:ByteVector
Returns the span identifier associated with this SpanContext as an 8-byte vector.
spanIdHex
Type:String
Returns the span identifier associated with this SpanContext as a 16 character lowercase hex string.
traceFlags
Type:TraceFlags
Returns details about the trace associated with this SpanContext as an 8-bit field.
traceState
Type:TraceState
Returns the trace state associated with this SpanContext.
isSampled
Type:Boolean
Returns true if this SpanContext is sampled.
isValid
Type:Boolean
Returns true if this SpanContext is valid. A valid span context has valid trace and span identifiers.
isRemote
Type:Boolean
Returns true if this SpanContext was propagated from a remote parent.
Companion Object
apply
The trace identifier of the span context (must be 16 bytes)
The span identifier of the span context (must be 8 bytes)
The trace flags of the span context
The trace state of the span context
Whether the span is propagated from a remote parent or not
SpanContext
Creates a new SpanContext with the given identifiers and options.
If the traceId or the spanId are invalid (i.e., do not conform to the requirements for hexadecimal ids of the appropriate lengths), both will be replaced with the standard “invalid” versions (all ‘0’s).
invalid
Type:SpanContext
A constant representing an invalid span context with all-zero identifiers.
TraceId Utilities
TraceId.Bytes
Type:Int
The number of bytes in a trace ID (16).
TraceId.HexLength
Type:Int
The length of a trace ID hex string (32).
TraceId.Invalid
Type:ByteVector
The invalid trace ID (all zeros).
TraceId.fromLongs
The high 8 bytes of the trace ID
The low 8 bytes of the trace ID
ByteVector
Creates a trace ID from two Long values.
TraceId.fromHex
The hexadecimal string representation of the trace ID
Option[ByteVector]
Creates a trace ID from a hex string. Returns None when the input isn’t valid hex or the ID is invalid.
TraceId.isValid
The trace ID to validate
Boolean
Checks whether a trace ID has the correct length and is not the invalid ID.
SpanId Utilities
SpanId.Bytes
Type:Int
The number of bytes in a span ID (8).
SpanId.HexLength
Type:Int
The length of a span ID hex string (16).
SpanId.Invalid
Type:ByteVector
The invalid span ID (all zeros).
SpanId.fromLong
The Long value to convert to a span ID
ByteVector
Creates a span ID from a Long value.
SpanId.fromHex
The hexadecimal string representation of the span ID
Option[ByteVector]
Creates a span ID from a hex string. Returns None when the input isn’t valid hex or the ID is invalid.
SpanId.isValid
The span ID to validate
Boolean
Checks whether a span ID has the correct length and is not the invalid ID.