diff --git a/crates/router/src/events/api_logs.rs b/crates/router/src/events/api_logs.rs index 873102e81ec2..27a90028ba6a 100644 --- a/crates/router/src/events/api_logs.rs +++ b/crates/router/src/events/api_logs.rs @@ -38,6 +38,7 @@ pub struct ApiEvent { response: Option, #[serde(flatten)] event_type: ApiEventsType, + hs_latency: Option, } impl ApiEvent { @@ -49,6 +50,7 @@ impl ApiEvent { status_code: i64, request: serde_json::Value, response: Option, + hs_latency: Option, auth_type: AuthenticationType, event_type: ApiEventsType, http_req: &HttpRequest, @@ -72,6 +74,7 @@ impl ApiEvent { .and_then(|user_agent_value| user_agent_value.to_str().ok().map(ToOwned::to_owned)), url_path: http_req.path().to_string(), event_type, + hs_latency, } } } diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index bb0e70b4b27b..321bf909ea0c 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -830,6 +830,7 @@ where .as_millis(); let mut serialized_response = None; + let mut overhead_latency = None; let status_code = match output.as_ref() { Ok(res) => { if let ApplicationResponse::Json(data) = res { @@ -839,6 +840,19 @@ where .attach_printable("Failed to serialize json response") .change_context(errors::ApiErrorResponse::InternalServerError.switch())?, ); + } else if let ApplicationResponse::JsonWithHeaders((data, headers)) = res { + serialized_response.replace( + masking::masked_serialize(&data) + .into_report() + .attach_printable("Failed to serialize json response") + .change_context(errors::ApiErrorResponse::InternalServerError.switch())?, + ); + + if let Some((_, value)) = headers.iter().find(|(key, _)| key == X_HS_LATENCY) { + if let Ok(external_latency) = value.parse::() { + overhead_latency.replace(external_latency); + } + } } event_type = res.get_api_event_type().or(event_type); @@ -854,6 +868,7 @@ where status_code, serialized_request, serialized_response, + overhead_latency, auth_type, event_type.unwrap_or(ApiEventsType::Miscellaneous), request,