diff --git a/src/util/metrics.rs b/src/util/metrics.rs index b882a886..2ba1ed63 100644 --- a/src/util/metrics.rs +++ b/src/util/metrics.rs @@ -3,17 +3,17 @@ use std::time::Instant; use futures::{future::BoxFuture, Future, FutureExt}; use rand::Rng; -use opentelemetry::{metrics::*, trace::TraceId, KeyValue}; +use opentelemetry::{metrics::*, trace::TraceId, Context, KeyValue}; pub trait RecordDuration<'a>: 'a { type Output; fn record_duration( self, - r: &'a ValueRecorder, + r: &'a Histogram, attributes: &'a [KeyValue], ) -> BoxFuture<'a, Self::Output>; - fn bound_record_duration(self, r: &'a BoundValueRecorder) -> BoxFuture<'a, Self::Output>; + fn bound_record_duration(self, r: &'a Histogram) -> BoxFuture<'a, Self::Output>; } impl<'a, T, O> RecordDuration<'a> for T @@ -24,13 +24,14 @@ where fn record_duration( self, - r: &'a ValueRecorder, + r: &'a Histogram, attributes: &'a [KeyValue], ) -> BoxFuture<'a, Self::Output> { async move { let request_start = Instant::now(); let res = self.await; r.record( + &Context::current(), Instant::now() .saturating_duration_since(request_start) .as_secs_f64(), @@ -41,14 +42,16 @@ where .boxed() } - fn bound_record_duration(self, r: &'a BoundValueRecorder) -> BoxFuture<'a, Self::Output> { + fn bound_record_duration(self, r: &'a Histogram) -> BoxFuture<'a, Self::Output> { async move { let request_start = Instant::now(); let res = self.await; r.record( + &Context::current(), Instant::now() .saturating_duration_since(request_start) .as_secs_f64(), + &[], ); res }