Bug: Propage request id to chat service



Send request id to chat service in headers.
diff --git a/crates/common_utils/src/consts.rs b/crates/common_utils/src/consts.rs
index 3ef0ef555e6..28508749f35 100644
--- a/crates/common_utils/src/consts.rs
+++ b/crates/common_utils/src/consts.rs
@@ -152,6 +152,9 @@ pub const APPLEPAY_VALIDATION_URL: &str =
 /// Request ID
 pub const X_REQUEST_ID: &str = "x-request-id";
 
+/// Chat Session ID
+pub const X_CHAT_SESSION_ID: &str = "x-chat-session-id";
+
 /// Merchant ID Header
 pub const X_MERCHANT_ID: &str = "x-merchant-id";
 
diff --git a/crates/router/src/core/chat.rs b/crates/router/src/core/chat.rs
index c30e27f0482..837a259bed4 100644
--- a/crates/router/src/core/chat.rs
+++ b/crates/router/src/core/chat.rs
@@ -11,18 +11,19 @@ use router_env::{instrument, logger, tracing};
 
 use crate::{
     db::errors::chat::ChatErrors,
-    routes::SessionState,
+    routes::{app::SessionStateInfo, SessionState},
     services::{authentication as auth, ApplicationResponse},
 };
 
-#[instrument(skip_all)]
+#[instrument(skip_all, fields(?session_id))]
 pub async fn get_data_from_hyperswitch_ai_workflow(
     state: SessionState,
     user_from_token: auth::UserFromToken,
     req: chat_api::ChatRequest,
+    session_id: Option<&str>,
 ) -> CustomResult<ApplicationResponse<chat_api::ChatResponse>, ChatErrors> {
     let url = format!("{}/webhook", state.conf.chat.hyperswitch_ai_host);
-
+    let request_id = state.get_request_id();
     let request_body = chat_domain::HyperswitchAiDataRequest {
         query: chat_domain::GetDataMessage {
             message: req.message,
@@ -33,12 +34,20 @@ pub async fn get_data_from_hyperswitch_ai_workflow(
     };
     logger::info!("Request for AI service: {:?}", request_body);
 
-    let request = RequestBuilder::new()
+    let mut request_builder = RequestBuilder::new()
         .method(Method::Post)
         .url(&url)
         .attach_default_headers()
-        .set_body(RequestContent::Json(Box::new(request_body.clone())))
-        .build();
+        .set_body(RequestContent::Json(Box::new(request_body.clone())));
+
+    if let Some(request_id) = request_id {
+        request_builder = request_builder.header(consts::X_REQUEST_ID, &request_id);
+    }
+    if let Some(session_id) = session_id {
+        request_builder = request_builder.header(consts::X_CHAT_SESSION_ID, session_id);
+    }
+
+    let request = request_builder.build();
 
     let response = http_client::send_request(
         &state.conf.proxy,
diff --git a/crates/router/src/routes/chat.rs b/crates/router/src/routes/chat.rs
index 555bf007d23..e3970cc6a4c 100644
--- a/crates/router/src/routes/chat.rs
+++ b/crates/router/src/routes/chat.rs
@@ -6,6 +6,7 @@ use router_env::{instrument, tracing, Flow};
 use super::AppState;
 use crate::{
     core::{api_locking, chat as chat_core},
+    routes::metrics,
     services::{
         api,
         authentication::{self as auth},
@@ -20,13 +21,21 @@ pub async fn get_data_from_hyperswitch_ai_workflow(
     payload: web::Json<chat_api::ChatRequest>,
 ) -> HttpResponse {
     let flow = Flow::GetDataFromHyperswitchAiFlow;
+    let session_id = http_req
+        .headers()
+        .get(common_utils::consts::X_CHAT_SESSION_ID)
+        .and_then(|header_value| header_value.to_str().ok());
     Box::pin(api::server_wrap(
         flow.clone(),
         state,
         &http_req,
         payload.into_inner(),
         |state, user: auth::UserFromToken, payload, _| {
-            chat_core::get_data_from_hyperswitch_ai_workflow(state, user, payload)
+            metrics::CHAT_REQUEST_COUNT.add(
+                1,
+                router_env::metric_attributes!(("merchant_id", user.merchant_id.clone())),
+            );
+            chat_core::get_data_from_hyperswitch_ai_workflow(state, user, payload, session_id)
         },
         // At present, the AI service retrieves data scoped to the merchant level
         &auth::JWTAuth {
diff --git a/crates/router/src/routes/metrics.rs b/crates/router/src/routes/metrics.rs
index e8aeef3e406..defb73fa138 100644
--- a/crates/router/src/routes/metrics.rs
+++ b/crates/router/src/routes/metrics.rs
@@ -140,3 +140,6 @@ histogram_metric_f64!(CHECK_NETWORK_TOKEN_STATUS_TIME, GLOBAL_METER);
 
 // A counter to indicate allowed payment method types mismatch
 counter_metric!(PAYMENT_METHOD_TYPES_MISCONFIGURATION_METRIC, GLOBAL_METER);
+
+// AI chat metric to track number of chat request
+counter_metric!(CHAT_REQUEST_COUNT, GLOBAL_METER);

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

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

## Description
Propagation request-id to chat service for consistency.
Propagate chat session id as well in request
Add count metric for chat api


### 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
Closes #8679



## How did you test it?
Tested locally, x-request-id is getting populated correctly
```
curl --location 'http://localhost:8080/chat/ai/data' \
--header 'x-feature: integ-custom' \
--header 'x-chat-session-id: chat-ssdfasdsf' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer JWT' \

--data '{
        
        
        
        
            "message": "success rate"
    
}'
```
<img width="1316" height="855" alt="image" src="https://github.com/user-attachments/assets/4b99e80c-5906-472d-a017-d9c5c8257d7a" />
AI service logs
<img width="1110" height="398" alt="image" src="https://github.com/user-attachments/assets/427f41be-ee48-4e94-b5b8-d6141b6f6400" />
<img width="1092" height="249" alt="image" src="https://github.com/user-attachments/assets/da479ff3-65db-4cec-8af7-a947ab807954" />



## 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
