TraceContext class final

Identifies a span and the trace it belongs to.

Propagated across process boundaries — into an isolate, into an HTTP header, into a job queue — so that work performed elsewhere still joins the same trace.

Annotations
  • @immutable

Constructors

TraceContext({required String traceId, required String spanId, String? parentSpanId, bool sampled = true, String? traceState})
Creates a trace context.
const

Properties

hashCode → int
The hash code for this object.
no setteroverride
parentSpanId → String?
Identifier of the enclosing span, absent for a root span.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sampled → bool
Whether this trace is being recorded.
final
spanId → String
Identifier of this span.
final
traceId → String
Identifier shared by every span in the run.
final
traceState → String?
The W3C tracestate header, carried through untouched.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toHeaders() → Map<String, String>
The headers that continue this trace in an outgoing request.
toJson() → JsonMap
Serialises the context for propagation.
toString() → String
A string representation of this object.
override
toTraceParent() → String
Renders the context as a W3C traceparent header value.

Operators

operator ==(Object other) → bool
The equality operator.
override

Static Methods

fromHeaders(Map<String, String> headers) → TraceContext?
Reads a context from request headers, matching names case-insensitively.
fromJson(JsonMap json) → TraceContext
Restores a context produced by toJson.
fromTraceParent(String value, {String? traceState}) → TraceContext?
Parses a W3C traceparent header value, or returns null.