From e0ae11ab86eafa56364e1da9f6dcb238a7a862d3 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 5 Jun 2024 04:54:40 +0100 Subject: [PATCH] fix: add metric labels --- tracing/mainmatter-workshop/README.md | 3 ++- tracing/mainmatter-workshop/src/middleware.rs | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tracing/mainmatter-workshop/README.md b/tracing/mainmatter-workshop/README.md index aa4cadb..fb50b4a 100644 --- a/tracing/mainmatter-workshop/README.md +++ b/tracing/mainmatter-workshop/README.md @@ -13,7 +13,8 @@ As stated in the exercise brief, this example will: - Create a top-level INFO span for each incoming request; - Track the number of concurrent requests using a gauge; - Track request duration using a histogram; - - Track the number of handled requests All metrics should include success/failure as a label. + - Track the number of handled requests +- All metrics should include success/failure as a label. ## Usage diff --git a/tracing/mainmatter-workshop/src/middleware.rs b/tracing/mainmatter-workshop/src/middleware.rs index bef2340..130ded8 100644 --- a/tracing/mainmatter-workshop/src/middleware.rs +++ b/tracing/mainmatter-workshop/src/middleware.rs @@ -31,8 +31,14 @@ pub(crate) async fn request_telemetry( ); }; + let outcome = if res.status().is_success() || res.status().is_redirection() { + "success" + } else { + "failure" + }; + let diff = now.elapsed(); - metrics::histogram!(HISTOGRAM_HTTP_REQUEST_DURATION).record(diff); + metrics::histogram!(HISTOGRAM_HTTP_REQUEST_DURATION, "outcome" => outcome).record(diff); metrics::gauge!(GAUGE_HTTP_CONCURRENT_REQUESTS).decrement(1);