Bug: [FEATURE] add support to forward x-request-id to keymanager service



### Feature Description

To ease debugging the keymanager service, x-request-id from application should be forwarded in the header while calling encryption service. This will be used by the keymanager service for the requests instead of creating one of its own.

### Possible Implementation

Pass x-request-id In the headers while calling keymanager service

### Have you spent some time checking if this feature request has been raised before?

- [X] I checked and didn't find a similar issue

### Have you read the Contributing Guidelines?

- [X] I have read the [Contributing Guidelines](https://github.com/juspay/hyperswitch/blob/main/docs/CONTRIBUTING.md)

### Are you willing to submit a PR?

Yes, I am willing to submit a PR!
diff --git a/crates/common_utils/Cargo.toml b/crates/common_utils/Cargo.toml
index eee1bd573ef..c6e29801b2f 100644
--- a/crates/common_utils/Cargo.toml
+++ b/crates/common_utils/Cargo.toml
@@ -12,6 +12,7 @@ default = ["v1"]
 keymanager = ["dep:router_env"]
 keymanager_mtls = ["reqwest/rustls-tls"]
 encryption_service = ["dep:router_env"]
+km_forward_x_request_id = ["dep:router_env", "router_env/actix_web"]
 signals = ["dep:signal-hook-tokio", "dep:signal-hook", "dep:tokio", "dep:router_env", "dep:futures"]
 async_ext = ["dep:async-trait", "dep:futures"]
 logs = ["dep:router_env"]
diff --git a/crates/common_utils/src/keymanager.rs b/crates/common_utils/src/keymanager.rs
index 9d6e9315074..53761951791 100644
--- a/crates/common_utils/src/keymanager.rs
+++ b/crates/common_utils/src/keymanager.rs
@@ -23,6 +23,8 @@ use crate::{
 const CONTENT_TYPE: &str = "Content-Type";
 static ENCRYPTION_API_CLIENT: OnceCell<reqwest::Client> = OnceCell::new();
 static DEFAULT_ENCRYPTION_VERSION: &str = "v1";
+#[cfg(feature = "km_forward_x_request_id")]
+const X_REQUEST_ID: &str = "X-Request-Id";
 
 /// Get keymanager client constructed from the url and state
 #[instrument(skip_all)]
@@ -104,18 +106,25 @@ where
     let url = format!("{}/{endpoint}", &state.url);
 
     logger::info!(key_manager_request=?request_body);
-
+    let mut header = vec![];
+    header.push((
+        HeaderName::from_str(CONTENT_TYPE)
+            .change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
+        HeaderValue::from_str("application/json")
+            .change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
+    ));
+    #[cfg(feature = "km_forward_x_request_id")]
+    if let Some(request_id) = state.request_id {
+        header.push((
+            HeaderName::from_str(X_REQUEST_ID)
+                .change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
+            HeaderValue::from_str(request_id.as_hyphenated().to_string().as_str())
+                .change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
+        ))
+    }
     let response = send_encryption_request(
         state,
-        HeaderMap::from_iter(
-            vec![(
-                HeaderName::from_str(CONTENT_TYPE)
-                    .change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
-                HeaderValue::from_str("application/json")
-                    .change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
-            )]
-            .into_iter(),
-        ),
+        HeaderMap::from_iter(header.into_iter()),
         url,
         method,
         request_body,
diff --git a/crates/common_utils/src/types/keymanager.rs b/crates/common_utils/src/types/keymanager.rs
index 05305b53707..abcb7aa87f7 100644
--- a/crates/common_utils/src/types/keymanager.rs
+++ b/crates/common_utils/src/types/keymanager.rs
@@ -6,6 +6,8 @@ use base64::Engine;
 use masking::{ExposeInterface, PeekInterface, Secret, Strategy, StrongSecret};
 #[cfg(feature = "encryption_service")]
 use router_env::logger;
+#[cfg(feature = "km_forward_x_request_id")]
+use router_env::tracing_actix_web::RequestId;
 use rustc_hash::FxHashMap;
 use serde::{
     de::{self, Unexpected, Visitor},
@@ -26,6 +28,8 @@ pub struct KeyManagerState {
     pub enabled: Option<bool>,
     pub url: String,
     pub client_idle_timeout: Option<u64>,
+    #[cfg(feature = "km_forward_x_request_id")]
+    pub request_id: Option<RequestId>,
     #[cfg(feature = "keymanager_mtls")]
     pub ca: Secret<String>,
     #[cfg(feature = "keymanager_mtls")]
diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.toml
index 7da8327b5b8..a614e5d1e7a 100644
--- a/crates/router/Cargo.toml
+++ b/crates/router/Cargo.toml
@@ -10,7 +10,7 @@ license.workspace = true
 
 [features]
 default = ["common_default", "v1"]
-common_default = ["kv_store", "stripe", "oltp", "olap", "accounts_cache", "dummy_connector", "payouts", "payout_retry", "retry", "frm", "tls", "partial-auth"]
+common_default = ["kv_store", "stripe", "oltp", "olap", "accounts_cache", "dummy_connector", "payouts", "payout_retry", "retry", "frm", "tls", "partial-auth", "km_forward_x_request_id"]
 olap = ["hyperswitch_domain_models/olap", "storage_impl/olap", "scheduler/olap", "api_models/olap", "dep:analytics"]
 tls = ["actix-web/rustls-0_22"]
 email = ["external_services/email", "scheduler/email", "olap"]
@@ -18,6 +18,7 @@ email = ["external_services/email", "scheduler/email", "olap"]
 keymanager_create = []
 keymanager_mtls = ["reqwest/rustls-tls", "common_utils/keymanager_mtls"]
 encryption_service = ["hyperswitch_domain_models/encryption_service", "common_utils/encryption_service"]
+km_forward_x_request_id = ["common_utils/km_forward_x_request_id"]
 frm = ["api_models/frm", "hyperswitch_domain_models/frm", "hyperswitch_connectors/frm", "hyperswitch_interfaces/frm"]
 stripe = []
 release = ["stripe", "email", "accounts_cache", "kv_store", "vergen", "recon", "external_services/aws_kms", "external_services/aws_s3", "keymanager_mtls", "keymanager_create", "encryption_service"]
diff --git a/crates/router/src/types/domain/types.rs b/crates/router/src/types/domain/types.rs
index 10657adc122..082e8df4bfc 100644
--- a/crates/router/src/types/domain/types.rs
+++ b/crates/router/src/types/domain/types.rs
@@ -10,6 +10,8 @@ impl From<&crate::SessionState> for KeyManagerState {
             enabled: conf.enabled,
             url: conf.url.clone(),
             client_idle_timeout: state.conf.proxy.idle_pool_connection_timeout,
+            #[cfg(feature = "km_forward_x_request_id")]
+            request_id: state.request_id,
             #[cfg(feature = "keymanager_mtls")]
             cert: conf.cert.clone(),
             #[cfg(feature = "keymanager_mtls")]

## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [ ] Bugfix
- [ ] New feature
- [x] Enhancement
- [ ] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
To ease debugging the keymanager service, x-request-id from application will be forwarded in the header while calling encryption service. This will be used by the keymanager service for the requests instead of creating one of its own.


### Additional Changes

- [ ] This PR modifies the API contract
- [ ] This PR modifies the database schema
- [ ] This PR modifies application configuration/environment variables

<!--
Provide links to the files with corresponding changes.

Following are the paths where you can find config files:
1. `config`
2. `crates/router/src/configs`
3. `loadtest/config`
-->


## Motivation and Context
For debugging keymanager service


## How did you test it?
Manually enabling logging in the key manager. x-request-id from the router can be used for debugging key manger service.
![Screenshot 2024-09-05 at 12 29 43 PM](https://github.com/user-attachments/assets/46ae387d-1ed9-4958-a90d-9816b124d498)
<img width="423" alt="Screenshot 2024-09-05 at 12 30 00 PM" src="https://github.com/user-attachments/assets/96377881-7fb0-46d4-886f-ce5ed1f8fb5c">


## Checklist
<!-- Put an `x` in the boxes that apply -->

- [x] I formatted the code `cargo +nightly fmt --all`
- [x] I addressed lints thrown by `cargo clippy`
- [x] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible
