use std::{future::Future, time::Instant};
use tower::Layer;
#[derive(Clone, Default)]
pub struct TracingLayer;
impl<S> Layer<S> for TracingLayer {
type Service = TracingService<S>;
fn layer(&self, inner: S) -> Self::Service {
TracingService { inner }
}
}
#[derive(Clone)]
pub struct TracingService<S> {
pub inner: S,
}
pub(crate) async fn with_timing<F, T>(fut: F) -> (T, i64)
where
F: Future<Output = T>,
{
let start = Instant::now();
let result = fut.await;
let latency_ms = start.elapsed().as_millis() as i64;
(result, latency_ms)
}