Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(routing): make shadow DE logs attributable, is_equal truthful, and DE timeout effective (#13695)
Prajjwal Kumar1f7744686b37
diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rsindex 4975d1bf6f..5fb761dddb 100644--- a/crates/router/src/core/payments/routing.rs+++ b/crates/router/src/core/payments/routing.rs@@ -1660,6 +1660,8 @@ pub async fn perform_hybrid_routing_if_enabled(if state.conf.open_router.static_routing_enabled&& state.conf.open_router.shadow_routing_enabled{+ use router_env::tracing::Instrument;+let payment_id = payment_dsl_input.payment_attempt.payment_id@@ -1670,19 +1672,28 @@ pub async fn perform_hybrid_routing_if_enabled(let shadow_backend_input = backend_input.clone();let shadow_fallback = fallback_config.to_vec();let shadow_static_connectors = static_connectors.to_vec();-- tokio::spawn(async move {- utils::shadow_decision_engine_routing(- shadow_state,- shadow_profile,- payment_id,- shadow_backend_input,- shadow_fallback,- shadow_static_connectors,- static_is_volume_split,- )- .await;- });+ let shadow_span = router_env::tracing::info_span!(+ "shadow_decision_engine_routing",+ de_shadow = true,+ profile_id = %business_profile.get_id().get_string_repr(),+ merchant_id = %business_profile.merchant_id.get_string_repr(),+ payment_id = %payment_id,+ );+ tokio::spawn(+ async move {+ utils::shadow_decision_engine_routing(+ shadow_state,+ shadow_profile,+ payment_id,+ shadow_backend_input,+ shadow_fallback,+ shadow_static_connectors,+ static_is_volume_split,+ )+ .await;+ }+ .instrument(shadow_span),+ );}(static_connectors.to_vec(), static_approach)diff --git a/crates/router/src/core/payments/routing/utils.rs b/crates/router/src/core/payments/routing/utils.rsindex 9ac75a30b1..a1df85c5ce 100644--- a/crates/router/src/core/payments/routing/utils.rs+++ b/crates/router/src/core/payments/routing/utils.rs@@ -176,7 +176,7 @@ pub async fn build_and_send_decision_engine_http_request<Req, Res, ErrRes>(http_method: services::Method,path: &str,request_body: Option<Req>,- _timeout: Option<u64>,+ timeout: Option<u64>,context_message: &str,events_wrapper: Option<RoutingEventsWrapper<Req>>,) -> RoutingResult<RoutingEventsResponse<Res>>@@ -211,7 +211,6 @@ where}let http_request = request_builder.build();- logger::info!(?http_request, decision_engine_request_path = %path, "decision_engine: Constructed Decision Engine API request details ({})", context_message);let should_parse_response = events_wrapper.as_ref().map(|wrapper| wrapper.parse_response)@@ -232,7 +231,7 @@ wherelet closure = || async {let request_start = std::time::Instant::now();let response =- services::call_connector_api(state, http_request, "Decision Engine API call", None)+ services::call_connector_api(state, http_request, "Decision Engine API call", timeout).await.change_context(errors::RoutingError::OpenRouterCallFailed)?;@@ -252,11 +251,6 @@ wherematch response {Ok(resp) => {- logger::debug!(- "decision_engine: Received response from Decision Engine API ({:?})",- String::from_utf8_lossy(&resp.response) // For logging- );-let resp = should_parse_response.then(|| {if std::any::TypeId::of::<Res>() == std::any::TypeId::of::<String>()@@ -358,15 +352,14 @@ impl DecisionEngineApiHandler for EuclidApiClient {).await?;- let parsed_response =- event_response- .response- .as_ref()- .ok_or(errors::RoutingError::OpenRouterError(- "Response from decision engine API is empty".to_string(),- ))?;+ // Reject an empty DE response even though the parsed value itself is unused here.+ event_response+ .response+ .as_ref()+ .ok_or(errors::RoutingError::OpenRouterError(+ "Response from decision engine API is empty".to_string(),+ ))?;- logger::debug!(parsed_response = ?parsed_response, response_type = %std::any::type_name::<Res>(), euclid_request_path = %path, "decision_engine_euclid: Successfully parsed response from Euclid API");Ok(event_response)}}@@ -679,7 +672,6 @@ pub async fn perform_decision_euclid_routing(routing_event.set_routable_connectors(euclid_response.evaluated_output.clone());state.event_handler.log_event(&routing_event);- logger::debug!(decision_engine_euclid_response=?euclid_response,"decision_engine_euclid");logger::debug!(decision_engine_euclid_selected_connector=?euclid_response.evaluated_output,"decision_engine_euclid");Ok(euclid_response)}@@ -1071,14 +1063,14 @@ impl DeDiffReason {impl DeComparisonResult {/// Why this comparison counts toward the kill switch, if it does (empty DE result => `Unresponsive`).fn diff_reason(self) -> Option<DeDiffReason> {- if !self.is_equal {- Some(DeDiffReason::ResultMismatch)- } else if self.is_equal_length {+ if self.is_equal {None} else if self.is_de_result_empty {Some(DeDiffReason::Unresponsive)- } else {+ } else if !self.is_equal_length {Some(DeDiffReason::LengthMismatch)+ } else {+ Some(DeDiffReason::ResultMismatch)}}}@@ -1090,22 +1082,21 @@ pub fn compare_and_log_result<T: RoutingEq<T> + Serialize>(is_volume: bool,) -> DeComparisonResult {let is_de_result_empty = de_result.is_empty();- let is_equal = if is_de_result_empty && result.is_empty() {- true- } else {- de_result+ let is_equal_in_length = de_result.len() == result.len();+ // Equal means identical: same length AND same elements in order — an empty or+ // prefix-only DE result is not equal (zip alone would be vacuously true).+ let is_equal = is_equal_in_length+ && de_result.iter().zip(result.iter())- .all(|(a, b)| T::is_equal(a, b))- };-- let is_equal_in_length = de_result.len() == result.len();+ .all(|(a, b)| T::is_equal(a, b));router_env::logger::debug!(routing_flow=?flow,is_equal=?is_equal,is_equal_length=?is_equal_in_length,is_volume=?is_volume,+ is_de_result_empty=?is_de_result_empty,de_response=?to_json_string(&de_result),hs_response=?to_json_string(&result),"decision_engine_euclid"