diff --git a/sgl-model-gateway/src/routers/http/router.rs b/sgl-model-gateway/src/routers/http/router.rs index 50e1071ca..2b94f20d8 100644 --- a/sgl-model-gateway/src/routers/http/router.rs +++ b/sgl-model-gateway/src/routers/http/router.rs @@ -213,8 +213,18 @@ impl Router { &self.retry_config, // operation per attempt |_: u32| async { - self.route_typed_request_once(headers, typed_req, route, model_id, is_stream, &info) - .await + let res = self + .route_typed_request_once(headers, typed_req, route, model_id, is_stream, &info) + .await; + + // Need to be outside `route_typed_request_once` because that function has multiple return paths + Metrics::record_router_upstream_response( + metrics_labels::ROUTER_HTTP, + res.status().as_u16(), + extract_error_code_from_response(&res), + ); + + res }, // should_retry predicate |res, _attempt| is_retryable_status(res.status()), @@ -686,6 +696,8 @@ fn convert_reqwest_error(e: reqwest::Error) -> Response { use async_trait::async_trait; +use crate::routers::error::extract_error_code_from_response; + #[async_trait] impl RouterTrait for Router { fn as_any(&self) -> &dyn std::any::Any {