From 3131052678cf117eb5d33d8c67928943c12b96cb Mon Sep 17 00:00:00 2001 From: Jonathan Davies Date: Fri, 27 Jan 2023 16:42:06 +0000 Subject: [PATCH] api/generic_server.rs: Ported to opentelemetry 0.18. --- src/api/generic_server.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/api/generic_server.rs b/src/api/generic_server.rs index 62fe4e5a..cb7ee63f 100644 --- a/src/api/generic_server.rs +++ b/src/api/generic_server.rs @@ -13,7 +13,7 @@ use hyper::{HeaderMap, StatusCode}; use opentelemetry::{ global, - metrics::{Counter, ValueRecorder}, + metrics::{Counter, Histogram}, trace::{FutureExt, SpanRef, TraceContextExt, Tracer}, Context, KeyValue, }; @@ -55,7 +55,7 @@ pub(crate) struct ApiServer { // Metrics request_counter: Counter, error_counter: Counter, - request_duration: ValueRecorder, + request_duration: Histogram, } impl ApiServer { @@ -79,7 +79,7 @@ impl ApiServer { )) .init(), request_duration: meter - .f64_value_recorder(format!("api.{}.request_duration", A::API_NAME)) + .f64_histogram(format!("api.{}.request_duration", A::API_NAME)) .with_description(format!( "Duration of API calls to the various {} API endpoints", A::API_NAME_DISPLAY @@ -190,7 +190,8 @@ impl ApiServer { .record_duration(&self.request_duration, &metrics_tags[..]) .await; - self.request_counter.add(1, &metrics_tags[..]); + self.request_counter + .add(¤t_context, 1, &metrics_tags[..]); let status_code = match &res { Ok(r) => r.status(), @@ -198,6 +199,7 @@ impl ApiServer { }; if status_code.is_client_error() || status_code.is_server_error() { self.error_counter.add( + ¤t_context, 1, &[ metrics_tags[0].clone(),