Unverified Commit aaed4f3b authored by nv-nedelman-1's avatar nv-nedelman-1 Committed by GitHub
Browse files

chore: add frontend per-request logging via on_response callback (#4965)


Signed-off-by: default avatarNicholas Edelman <nedelman@nvidia.com>
parent b06cc313
......@@ -9,6 +9,9 @@ use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
use std::time::Duration;
use axum::body::Body;
use axum::http::Response;
use super::Metrics;
use super::RouteDoc;
use super::metrics;
......@@ -427,7 +430,37 @@ impl HttpServiceConfigBuilder {
all_docs.extend(openapi_docs);
// Add span for tracing
router = router.layer(TraceLayer::new_for_http().make_span_with(make_request_span));
// Add on_response callback for logging response status code
router = router.layer(
TraceLayer::new_for_http()
.make_span_with(make_request_span)
.on_response(
|response: &Response<Body>, latency: Duration, _span: &tracing::Span| {
let status = response.status();
let latency_ms = latency.as_millis();
if status.is_server_error() {
tracing::error!(
status = %status.as_u16(),
latency_ms = %latency_ms,
"request completed with server error"
);
} else if status.is_client_error() {
tracing::warn!(
status = %status.as_u16(),
latency_ms = %latency_ms,
"request completed with client request error"
);
} else {
tracing::debug!(
status = %status.as_u16(),
latency_ms = %latency_ms,
"request completed"
);
}
},
),
);
Ok(HttpService {
state,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment