diff --git a/crates/external_services/src/grpc_client.rs b/crates/external_services/src/grpc_client.rs index 404685025ed3..40f2a535692b 100644 --- a/crates/external_services/src/grpc_client.rs +++ b/crates/external_services/src/grpc_client.rs @@ -128,3 +128,12 @@ impl AddHeaders for tonic::Request { }); } } + +pub(crate) fn create_grpc_request(message: T, headers: GrpcHeaders) -> tonic::Request { + 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 bc5ce4997270..17b332448e78 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 { + #[instrument(skip_all)] async fn perform_elimination_routing( &self, id: String, @@ -69,14 +71,15 @@ impl EliminationBasedRouting for EliminationAnalyserClient { 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 { ))? .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 { }) .collect::>(); - 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 { "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 { - 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 { "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 3cf06ab63beb..852e850e4ff0 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, @@ -21,7 +22,7 @@ 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 +54,7 @@ pub trait SuccessBasedDynamicRouting: dyn_clone::DynClone + Send + Sync { #[async_trait::async_trait] impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient { + #[instrument(skip_all)] async fn calculate_success_rate( &self, id: String, @@ -71,14 +73,15 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient { .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 +92,12 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient { ))? .into_inner(); + logger::info!(dynamic_routing_response=?response); + Ok(response) } + #[instrument(skip_all)] async fn update_success_rate( &self, id: String, @@ -113,14 +119,15 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient { }) .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 +138,18 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient { ))? .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 { - 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 +159,9 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient { "Failed to invalidate the success rate routing keys".to_string(), ))? .into_inner(); + + logger::info!(dynamic_routing_response=?response); + Ok(response) } }