Newer
Older
use std::{future::Future, time::Instant};
use datadog_statsd::Client;
pub async fn measure_async<T, Fut: Future<Output = anyhow::Result<T>>>(
client: &Client,
metric_name: &str,
f: Fut,
) -> anyhow::Result<T> {
let start = Instant::now();
let res = f.await;
let end = Instant::now();
client.timer(
metric_name,
(end - start).as_millis() as f64,
&Some(vec![&format!("success:{}", res.is_ok())]),
);
res
}