1
0
mirror of https://github.com/actix/examples synced 2024-11-23 22:41:07 +01:00

fix: add metric labels

This commit is contained in:
Rob Ede 2024-06-05 04:54:40 +01:00
parent 8e0b57e658
commit e0ae11ab86
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
2 changed files with 9 additions and 2 deletions

View File

@ -13,7 +13,8 @@ As stated in the exercise brief, this example will:
- Create a top-level INFO span for each incoming request; - Create a top-level INFO span for each incoming request;
- Track the number of concurrent requests using a gauge; - Track the number of concurrent requests using a gauge;
- Track request duration using a histogram; - 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 ## Usage

View File

@ -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(); 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); metrics::gauge!(GAUGE_HTTP_CONCURRENT_REQUESTS).decrement(1);