begin static method

TraceSpan begin(
  1. String label, {
  2. TraceTag tag = TraceTag.general,
  3. String? extra,
})

Begins a named timing span.

Returns a TraceSpan that logs its duration when TraceSpan.end is called. When tracing is disabled, returns TraceSpan.noop to avoid allocation overhead.

extra is an optional string appended to the log when the span ends.

Implementation

static TraceSpan begin(
  String label, {
  TraceTag tag = TraceTag.general,
  String? extra,
}) {
  if (!enabled || !isTagEnabled(tag)) return TraceSpan.noop;
  return TraceSpan._(label, tag, Stopwatch(), extra);
}