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);