async/observability_utils library
Observability helpers: wrap operations with timing and outcome hooks — roadmap #680.
Every app eventually sprinkles final sw = Stopwatch()..start(); … log(...)
around the same operations. These wrappers centralize that: run the work,
measure how long it took, hand the duration and the outcome to optional
hooks (for logging, metrics, tracing), and return the result unchanged — or
rethrow the original error after reporting it. The wrappers add timing only;
they never swallow a failure.
Functions
-
observeAsync<
T> (Future< T> operation(), {void onSuccess(Duration elapsed, T result)?, void onError(Duration elapsed, Object error, StackTrace stackTrace)?}) → Future<T> -
Runs the async
operation, measures its wall-clock duration, and reports the outcome through the optional hooks, then returns the result (or rethrows the operation's error afteronError). -
observeSync<
T> (T operation(), {void onSuccess(Duration elapsed, T result)?, void onError(Duration elapsed, Object error, StackTrace stackTrace)?}) → T -
Synchronous counterpart of observeAsync: times
operation, reports the outcome through the optional hooks, and returns the result (or rethrows afteronError). Audited: 2026-06-12 11:26 EDT