Span class abstract

A single unit of work with a start and end time, contributing to a distributed trace.

Concrete instances are created by a Tracer (via startSpan or startActiveSpan) — application code never implements this directly.

Constructors

Span()

Properties

hashCode → int
The hash code for this object.
no setterinherited
isRecording → bool
Whether this span is still open (i.e. end has not been called). A non-recording span (e.g. end already called, or a no-op implementation) silently ignores further mutation.
no setter
name → String
This span's name.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
spanContext → SpanContext
This span's trace/span IDs.
no setter

Methods

addEvent(String name, {Map<String, Object?>? attributes, DateTime? timestamp}) → void
Records a timestamped event on this span. A no-op once the span has ended.
end([DateTime? endTime]) → void
Ends the span, snapshotting it for export. Calling this more than once is a safe no-op — only the first call has any effect.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
recordException(Object exception, {StackTrace? stackTrace, Map<String, Object?>? attributes}) → void
Records exception (and optionally stackTrace) as an exception event, following the OTel exception semantic conventions. Does not by itself change setStatus — callers that want an error status still call setStatus explicitly (this is what Tracer.startActiveSpan does when body throws).
setAttribute(String key, Object? value) → void
Sets a single attribute. A no-op once the span has ended.
setAttributes(Map<String, Object?> attributes) → void
Merges attributes onto this span's attribute set. A no-op once the span has ended.
setStatus(StatusCode code, {String? description}) → void
Sets the span's final status. A no-op once the span has ended.
toString() → String
A string representation of this object.
inherited

Operators

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

Static Properties

current → Span?
The span active in the current async Zone, or null if none is. Set implicitly by Tracer.startActiveSpan (via runWithSpan) for the duration of the active operation, which is what makes trace-to-log correlation automatic without every call site threading a span through manually.
no setter

Static Methods

runWithSpan<T>(Span span, Future<T> body()) → Future<T>
Runs body with span as current for its duration, including across await gaps (Dart zones are "sticky": an async function keeps running in the zone that was active when it started).