Span class

A single timed operation within a distributed trace.

final span = Span(
  operationName: 'GET /api/users',
  serviceName: 'flutter-app',
  kind: SpanKind.client,
  traceId: generateTraceId(),
  parentSpanId: null,
);
// ... do work ...
span.end();

Constructors

Span({required String operationName, required String serviceName, required SpanKind kind, required String traceId, String? parentSpanId, Map<String, dynamic>? attributes})
Creates a new Span.
Span.withId({required String id, required String operationName, required String serviceName, required SpanKind kind, required String traceId, String? parentSpanId, Map<String, dynamic>? attributes})
Creates a Span with a specific ID (for testing).

Properties

attributes Map<String, dynamic>
Current span attributes (unmodifiable view).
no setter
durationMs int?
Duration in milliseconds, or null if the span is still active.
no setter
endTime DateTime?
The end time, or null if the span is still active.
no setter
events List<SpanEvent>
Current span events (unmodifiable view).
no setter
hashCode int
The hash code for this object.
no setterinherited
id String
16-character hex span ID.
final
isEnded bool
Whether this span has been ended.
no setter
kind SpanKind
Span kind.
final
operationName String
Operation name (e.g. "GET /api/users", "screen.render").
getter/setter pair
parentSpanId String?
Parent span ID, or null for root spans.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
serviceName String
Service name (e.g. "flutter-app").
final
startTime DateTime
Wall-clock start time.
final
status SpanStatus
Current span status.
no setter
statusMessage String?
Current status message.
no setter
traceId String
32-character hex trace ID (shared across all spans in a trace).
final

Methods

addEvent(String name, {Map<String, dynamic>? attributes}) → void
Adds a timestamped event to the span.
end() → void
Ends the span, calculating its duration.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setAttribute(String key, dynamic value) → void
Sets a single attribute on the span.
setAttributes(Map<String, dynamic> attrs) → void
Sets multiple attributes on the span.
setStatus(SpanStatus status, [String? message]) → void
Sets the span's status.
toJson() Map<String, dynamic>
Serializes the span to the JSON payload format expected by POST /api/ingest/spans.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited