Bug: [REFACTOR] add info logs to log the grpc request and response




diff --git a/crates/external_services/src/grpc_client.rs b/crates/external_services/src/grpc_client.rs
index 404685025ed..7a627d3ab27 100644
--- a/crates/external_services/src/grpc_client.rs
+++ b/crates/external_services/src/grpc_client.rs
@@ -128,3 +128,13 @@ impl<T> AddHeaders for tonic::Request<T> {
         });
     }
 }
+
+#[cfg(feature = "dynamic_routing")]
+pub(crate) fn create_grpc_request<T: Debug>(message: T, headers: GrpcHeaders) -> tonic::Request<T> {
+    let mut request = tonic::Request::new(message);
+    request.add_headers_to_grpc_request(headers);
+
+    logger::info!(dynamic_routing_request=?request);
+
+    request
+}
diff --git a/crates/external_services/src/grpc_client/dynamic_routing/elimination_rate_client.rs b/crates/external_services/src/grpc_client/dynamic_routing/elimination_rate_client.rs
index bc5ce499727..17b332448e7 100644
--- a/crates/external_services/src/grpc_client/dynamic_routing/elimination_rate_client.rs
+++ b/crates/external_services/src/grpc_client/dynamic_routing/elimination_rate_client.rs
@@ -9,6 +9,7 @@ pub use elimination_rate::{
     LabelWithBucketName, UpdateEliminationBucketRequest, UpdateEliminationBucketResponse,
 };
 use error_stack::ResultExt;
+use router_env::{instrument, logger, tracing};
 #[allow(
     missing_docs,
     unused_qualifications,
@@ -21,7 +22,7 @@ pub mod elimination_rate {
 }
 
 use super::{Client, DynamicRoutingError, DynamicRoutingResult};
-use crate::grpc_client::{AddHeaders, GrpcHeaders};
+use crate::grpc_client::{self, GrpcHeaders};
 
 /// The trait Elimination Based Routing would have the functions required to support performance, calculation and invalidation bucket
 #[async_trait::async_trait]
@@ -54,6 +55,7 @@ pub trait EliminationBasedRouting: dyn_clone::DynClone + Send + Sync {
 
 #[async_trait::async_trait]
 impl EliminationBasedRouting for EliminationAnalyserClient<Client> {
+    #[instrument(skip_all)]
     async fn perform_elimination_routing(
         &self,
         id: String,
@@ -69,14 +71,15 @@ impl EliminationBasedRouting for EliminationAnalyserClient<Client> {
 
         let config = configs.map(ForeignTryFrom::foreign_try_from).transpose()?;
 
-        let mut request = tonic::Request::new(EliminationRequest {
-            id,
-            params,
-            labels,
-            config,
-        });
-
-        request.add_headers_to_grpc_request(headers);
+        let request = grpc_client::create_grpc_request(
+            EliminationRequest {
+                id,
+                params,
+                labels,
+                config,
+            },
+            headers,
+        );
 
         let response = self
             .clone()
@@ -87,9 +90,12 @@ impl EliminationBasedRouting for EliminationAnalyserClient<Client> {
             ))?
             .into_inner();
 
+        logger::info!(dynamic_routing_response=?response);
+
         Ok(response)
     }
 
+    #[instrument(skip_all)]
     async fn update_elimination_bucket_config(
         &self,
         id: String,
@@ -110,14 +116,15 @@ impl EliminationBasedRouting for EliminationAnalyserClient<Client> {
             })
             .collect::<Vec<_>>();
 
-        let mut request = tonic::Request::new(UpdateEliminationBucketRequest {
-            id,
-            params,
-            labels_with_bucket_name,
-            config,
-        });
-
-        request.add_headers_to_grpc_request(headers);
+        let request = grpc_client::create_grpc_request(
+            UpdateEliminationBucketRequest {
+                id,
+                params,
+                labels_with_bucket_name,
+                config,
+            },
+            headers,
+        );
 
         let response = self
             .clone()
@@ -127,16 +134,19 @@ impl EliminationBasedRouting for EliminationAnalyserClient<Client> {
                 "Failed to update the elimination bucket".to_string(),
             ))?
             .into_inner();
+
+        logger::info!(dynamic_routing_response=?response);
+
         Ok(response)
     }
+
+    #[instrument(skip_all)]
     async fn invalidate_elimination_bucket(
         &self,
         id: String,
         headers: GrpcHeaders,
     ) -> DynamicRoutingResult<InvalidateBucketResponse> {
-        let mut request = tonic::Request::new(InvalidateBucketRequest { id });
-
-        request.add_headers_to_grpc_request(headers);
+        let request = grpc_client::create_grpc_request(InvalidateBucketRequest { id }, headers);
 
         let response = self
             .clone()
@@ -146,6 +156,9 @@ impl EliminationBasedRouting for EliminationAnalyserClient<Client> {
                 "Failed to invalidate the elimination bucket".to_string(),
             ))?
             .into_inner();
+
+        logger::info!(dynamic_routing_response=?response);
+
         Ok(response)
     }
 }
diff --git a/crates/external_services/src/grpc_client/dynamic_routing/success_rate_client.rs b/crates/external_services/src/grpc_client/dynamic_routing/success_rate_client.rs
index 3cf06ab63be..fca4ff61fcc 100644
--- a/crates/external_services/src/grpc_client/dynamic_routing/success_rate_client.rs
+++ b/crates/external_services/src/grpc_client/dynamic_routing/success_rate_client.rs
@@ -4,6 +4,7 @@ use api_models::routing::{
 };
 use common_utils::{ext_traits::OptionExt, transformers::ForeignTryFrom};
 use error_stack::ResultExt;
+use router_env::{instrument, logger, tracing};
 pub use success_rate::{
     success_rate_calculator_client::SuccessRateCalculatorClient, CalSuccessRateConfig,
     CalSuccessRateRequest, CalSuccessRateResponse,
@@ -15,13 +16,14 @@ pub use success_rate::{
     missing_docs,
     unused_qualifications,
     clippy::unwrap_used,
-    clippy::as_conversions
+    clippy::as_conversions,
+    clippy::use_self
 )]
 pub mod success_rate {
     tonic::include_proto!("success_rate");
 }
 use super::{Client, DynamicRoutingError, DynamicRoutingResult};
-use crate::grpc_client::{AddHeaders, GrpcHeaders};
+use crate::grpc_client::{self, GrpcHeaders};
 /// The trait Success Based Dynamic Routing would have the functions required to support the calculation and updation window
 #[async_trait::async_trait]
 pub trait SuccessBasedDynamicRouting: dyn_clone::DynClone + Send + Sync {
@@ -53,6 +55,7 @@ pub trait SuccessBasedDynamicRouting: dyn_clone::DynClone + Send + Sync {
 
 #[async_trait::async_trait]
 impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient<Client> {
+    #[instrument(skip_all)]
     async fn calculate_success_rate(
         &self,
         id: String,
@@ -71,14 +74,15 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient<Client> {
             .map(ForeignTryFrom::foreign_try_from)
             .transpose()?;
 
-        let mut request = tonic::Request::new(CalSuccessRateRequest {
-            id,
-            params,
-            labels,
-            config,
-        });
-
-        request.add_headers_to_grpc_request(headers);
+        let request = grpc_client::create_grpc_request(
+            CalSuccessRateRequest {
+                id,
+                params,
+                labels,
+                config,
+            },
+            headers,
+        );
 
         let response = self
             .clone()
@@ -89,9 +93,12 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient<Client> {
             ))?
             .into_inner();
 
+        logger::info!(dynamic_routing_response=?response);
+
         Ok(response)
     }
 
+    #[instrument(skip_all)]
     async fn update_success_rate(
         &self,
         id: String,
@@ -113,14 +120,15 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient<Client> {
             })
             .collect();
 
-        let mut request = tonic::Request::new(UpdateSuccessRateWindowRequest {
-            id,
-            params,
-            labels_with_status,
-            config,
-        });
-
-        request.add_headers_to_grpc_request(headers);
+        let request = grpc_client::create_grpc_request(
+            UpdateSuccessRateWindowRequest {
+                id,
+                params,
+                labels_with_status,
+                config,
+            },
+            headers,
+        );
 
         let response = self
             .clone()
@@ -131,16 +139,18 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient<Client> {
             ))?
             .into_inner();
 
+        logger::info!(dynamic_routing_response=?response);
+
         Ok(response)
     }
+
+    #[instrument(skip_all)]
     async fn invalidate_success_rate_routing_keys(
         &self,
         id: String,
         headers: GrpcHeaders,
     ) -> DynamicRoutingResult<InvalidateWindowsResponse> {
-        let mut request = tonic::Request::new(InvalidateWindowsRequest { id });
-
-        request.add_headers_to_grpc_request(headers);
+        let request = grpc_client::create_grpc_request(InvalidateWindowsRequest { id }, headers);
 
         let response = self
             .clone()
@@ -150,6 +160,9 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient<Client> {
                 "Failed to invalidate the success rate routing keys".to_string(),
             ))?
             .into_inner();
+
+        logger::info!(dynamic_routing_response=?response);
+
         Ok(response)
     }
 }
diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rs
index 45bd0a6a015..271a5679282 100644
--- a/crates/router/src/core/payments/routing.rs
+++ b/crates/router/src/core/payments/routing.rs
@@ -37,6 +37,8 @@ use rand::{
     distributions::{self, Distribution},
     SeedableRng,
 };
+#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
+use router_env::{instrument, tracing};
 use rustc_hash::FxHashMap;
 use storage_impl::redis::cache::{CacheKey, CGRAPH_CACHE, ROUTING_CACHE};
 
@@ -1281,6 +1283,7 @@ pub fn make_dsl_input_for_surcharge(
 
 /// success based dynamic routing
 #[cfg(all(feature = "v1", feature = "dynamic_routing"))]
+#[instrument(skip_all)]
 pub async fn perform_success_based_routing(
     state: &SessionState,
     routable_connectors: Vec<api_routing::RoutableConnectorChoice>,
diff --git a/proto/success_rate.proto b/proto/success_rate.proto
index 38e56e36c0f..f49618bc4b6 100644
--- a/proto/success_rate.proto
+++ b/proto/success_rate.proto
@@ -55,7 +55,11 @@ message CurrentBlockThreshold {
 }
 
 message UpdateSuccessRateWindowResponse {
-    string message = 1;
+   enum UpdationStatus {
+      WINDOW_UPDATION_SUCCEEDED = 0;
+      WINDOW_UPDATION_FAILED = 1;
+   }
+   UpdationStatus status = 1;
 }
 
  // API-3 types
@@ -64,5 +68,9 @@ message InvalidateWindowsRequest {
 }
 
 message InvalidateWindowsResponse {
-    string message = 1;
+   enum InvalidationStatus {
+      WINDOW_INVALIDATION_SUCCEEDED = 0;
+      WINDOW_INVALIDATION_FAILED = 1;
+   }
+   InvalidationStatus status = 1;
 }
\ No newline at end of file

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

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

## Description
<!-- Describe your changes in detail -->
This PR adds the info logs to log the dynamic routing grpc requests and response objects.

### 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
<!--
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.

If you don't have an issue, we'd recommend starting with one first so the PR
can focus on the implementation (unless it is an obvious bug or documentation fix
that will have little conversation).
-->


## How did you test it?
<!--
Did you write an integration/unit/API test to verify the code changes?
Or did you test this change manually (provide relevant screenshots)?
-->

1. Create merchant_account, api_key and mca (any connector)
2. Toggle dynamic routing

```
curl --location --request POST 'http://localhost:8080/account/merchant_1734609410/business_profile/pro_gPTjn9jLm0CxI8ZD1omL/dynamic_routing/success_based/toggle?enable=metrics' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_K70Wr6zqJLbPECg8eEXrnZ43TW41JNUuXYHzRB50geiG0lViLExjxNUld6sgdNd0' \
--data ''
```

3. Set 100% for dynamic_routing volume split

```
curl --location --request POST 'http://localhost:8080/account/merchant_1734609410/business_profile/pro_gPTjn9jLm0CxI8ZD1omL/dynamic_routing/set_volume_split?split=100' \
--header 'api-key: dev_GFInyC2oIihPleQ4CM8u8WOa02PxN5MHR5W1YAZyXxIYTHt8KDq2VPzRNn26JyJI'
```

4. Create a payment

```
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_K70Wr6zqJLbPECg8eEXrnZ43TW41JNUuXYHzRB50geiG0lViLExjxNUld6sgdNd0' \
--data '{
    "amount": 6540,
    "authentication_type": "no_three_ds",
    "confirm": true,
    "currency": "USD",
    "customer_acceptance": {
        "acceptance_type": "online"
    },
    "customer_id": "cus_uYakn3OQTUtAgetLDOE1",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "card_cvc": "123",
            "card_exp_month": "10",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe",
            "card_number": "4242424242424242"
        }
    }
}'
```

Check grafana logs for the payment matching keyword `dynamic_routing_request` and `dynamic_routing_response`

Console request log - 

![image](https://github.com/user-attachments/assets/cadec322-c22d-4288-b87b-c47976a8ac68)

Console response log - 

![image](https://github.com/user-attachments/assets/c0b81c33-70fb-4fae-a7c5-527ff7b1201d)


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