mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	fix(middleware): add support for logging request-id sent in request (#3225)
This commit is contained in:
		| @ -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) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Nishant Joshi
					Nishant Joshi