Skip to content
Snippets Groups Projects
lib.rs 487 B
Newer Older
Stephen D's avatar
Stephen D committed
use std::{future::Future, time::Instant};

use datadog_statsd::Client;

Stephen D's avatar
Stephen D committed
pub mod lookup;
Stephen D's avatar
Stephen D committed

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
}