span<T> static method

Future<T> span<T>(
  1. String channel,
  2. Map<String, Object?> payload,
  3. Future<T> body()
)

Runs body and reports it as a timed event on channel — duration in fractional milliseconds under ms, the error under error if it threw. The error is rethrown; this observes, it never swallows.

Implementation

static Future<T> span<T>(
  String channel,
  Map<String, Object?> payload,
  Future<T> Function() body,
) async {
  var watch = Stopwatch()..start();
  Object? error;
  try {
    return await body();
  } catch (e) {
    error = e;
    rethrow;
  } finally {
    _spanEvent(channel, payload, watch, error);
  }
}