Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(middleware): add support for logging request-id sent in request (#3225)

Nishant Joshi0f72b5527aab
diff --git a/crates/router/src/middleware.rs b/crates/router/src/middleware.rs
index 1576432e26..0f2c5bd2cb 100644
--- a/crates/router/src/middleware.rs
+++ b/crates/router/src/middleware.rs
@@ -43,16 +43,21 @@ where
actix_web::dev::forward_ready!(service);
fn call(&self, req: actix_web::dev::ServiceRequest) -> Self::Future {
+ let old_x_request_id = req.headers().get("x-request-id").cloned();
let mut req = req;
let request_id_fut = req.extract::<router_env::tracing_actix_web::RequestId>();
let response_fut = self.service.call(req);
Box::pin(async move {
let request_id = request_id_fut.await?;
+ let request_id = request_id.as_hyphenated().to_string();
+ if let Some(upstream_request_id) = old_x_request_id {
+ router_env::logger::info!(?request_id, ?upstream_request_id);
+ }
let mut response = response_fut.await?;
response.headers_mut().append(
http::header::HeaderName::from_static("x-request-id"),
- http::HeaderValue::from_str(&request_id.as_hyphenated().to_string())?,
+ http::HeaderValue::from_str(&request_id)?,
);
Ok(response)