Skip to main content

timer

Macro timer 

Source
macro_rules! timer {
    ($name:literal $(, $tag:ident = $tv:expr)* $(,)?) => { ... };
}
Expand description

Starts a timer that records elapsed time in fractional seconds as a distribution metric.

Returns a TimerGuard that captures Instant::now() at creation. Call .record() to record the metric with the tag success:true, or let it drop to record with success:false.

If you want to override this behavior and record the metric with success:true even on drop, call .success() on the guard.

Tags can also be added after creation via .tag(), which is useful when some tag values depend on the outcome of the timed operation.

ยงSyntax

use objectstore_metrics::timer;

let guard = timer!("server.requests.duration");
let guard = timer!("server.requests.duration", route = "/v1/test");
// ... do work ...
guard.record(); // records elapsed time with success:true
use objectstore_metrics::timer;

let guard = timer!("server.requests.duration", route = "/v1/test");
// ... determine backend ...
let guard = guard.tag("backend", "gcs");
guard.record();

Tag keys are identifiers; tag values must implement Into<SharedString>.