Skip to content

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

fix: Added context to UCS shadow mode logs HS<>UCS (#10575)

Amitsingh Tanwarfc0078ae5900
diff --git a/crates/hyperswitch_interfaces/src/api/gateway.rs b/crates/hyperswitch_interfaces/src/api/gateway.rs
index 51d392d814..78ac3f546b 100644
--- a/crates/hyperswitch_interfaces/src/api/gateway.rs
+++ b/crates/hyperswitch_interfaces/src/api/gateway.rs
@@ -12,7 +12,7 @@ use common_enums::{CallConnectorAction, ExecutionMode, ExecutionPath};
use common_utils::{errors::CustomResult, request::Request};
use error_stack::ResultExt;
use hyperswitch_domain_models::router_data::RouterData;
-use router_env::logger;
+use router_env::{logger, tracing::Instrument};
use crate::{
api_client::{self, ApiClientWrapper},
@@ -210,44 +210,49 @@ where
let direct_router_data_clone = direct_router_data.clone();
let return_raw_connector_response_clone = return_raw_connector_response;
let context_clone = context.clone();
- tokio::spawn(async move {
- let gateway: Box<dyn PaymentGateway<State, ConnectorData, F, Req, Resp, Context>> =
- F::get_gateway(execution_path);
- let ucs_shadow_result = gateway
- .execute(
- &state_clone,
- connector_integration,
- &router_data_clone,
- call_connector_action,
- None,
- return_raw_connector_response_clone,
- context_clone,
- )
- .await
- .attach_printable("Gateway execution failed");
- // Send comparison data asynchronously
- match ucs_shadow_result {
- Ok(ucs_router_data) => {
- // Send comparison data asynchronously
- if let Some(comparison_service_config) =
- state_clone.get_comparison_service_config()
- {
- let request_id = state_clone.get_request_id_str();
- let _ = helpers::serialize_router_data_and_send_to_comparison_service(
- &state_clone,
- direct_router_data_clone,
- ucs_router_data,
- comparison_service_config,
- request_id,
- )
- .await;
- };
- }
- Err(e) => {
- logger::error!("UCS shadow execution failed: {:?}", e);
+ tokio::spawn(
+ async move {
+ let gateway: Box<
+ dyn PaymentGateway<State, ConnectorData, F, Req, Resp, Context>,
+ > = F::get_gateway(execution_path);
+ let ucs_shadow_result = gateway
+ .execute(
+ &state_clone,
+ connector_integration,
+ &router_data_clone,
+ call_connector_action,
+ None,
+ return_raw_connector_response_clone,
+ context_clone,
+ )
+ .await
+ .attach_printable("Gateway execution failed");
+ // Send comparison data asynchronously
+ match ucs_shadow_result {
+ Ok(ucs_router_data) => {
+ // Send comparison data asynchronously
+ if let Some(comparison_service_config) =
+ state_clone.get_comparison_service_config()
+ {
+ let request_id = state_clone.get_request_id_str();
+ let _ =
+ helpers::serialize_router_data_and_send_to_comparison_service(
+ &state_clone,
+ direct_router_data_clone,
+ ucs_router_data,
+ comparison_service_config,
+ request_id,
+ )
+ .await;
+ };
+ }
+ Err(e) => {
+ logger::error!(error=?e, "UCS shadow execution failed");
+ }
}
}
- });
+ .instrument(router_env::tracing::Span::current()),
+ );
Ok(direct_router_data)
}
}
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 680d3e0377..690be022c6 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -62,7 +62,7 @@ use openssl::{
use rand::Rng;
#[cfg(feature = "v2")]
use redis_interface::errors::RedisError;
-use router_env::{instrument, logger, tracing};
+use router_env::{instrument, logger, tracing, tracing::Instrument};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
@@ -8673,34 +8673,37 @@ where
Err(_) => None,
};
- tokio::spawn(async move {
- execute_shadow_unified_connector_service_call(
- unified_connector_service_state,
- unified_connector_service_router_data,
- direct_router_data,
- unified_connector_service_header_payload,
- lineage_ids,
- unified_connector_service_merchant_connector_account,
- &connector,
- unified_connector_service_platform,
- unified_connector_service_merchant_order_reference_id,
- call_connector_action,
- shadow_ucs_call_connector_action,
- unified_connector_service_creds_identifier,
- unified_connector_service_customer,
- unified_connector_service_payment_attempt_data,
- unified_connector_service_connector_label,
- unified_connector_service_connector_payment_id,
- )
- .await
- .map_err(|e| {
- router_env::logger::debug!(
- "Shadow UCS call in Direct with shadow UCS processing failed: {:?}",
- e
+ tokio::spawn(
+ async move {
+ execute_shadow_unified_connector_service_call(
+ unified_connector_service_state,
+ unified_connector_service_router_data,
+ direct_router_data,
+ unified_connector_service_header_payload,
+ lineage_ids,
+ unified_connector_service_merchant_connector_account,
+ &connector,
+ unified_connector_service_platform,
+ unified_connector_service_merchant_order_reference_id,
+ call_connector_action,
+ shadow_ucs_call_connector_action,
+ unified_connector_service_creds_identifier,
+ unified_connector_service_customer,
+ unified_connector_service_payment_attempt_data,
+ unified_connector_service_connector_label,
+ unified_connector_service_connector_payment_id,
)
- })
- .ok()
- });
+ .await
+ .map_err(|e| {
+ router_env::logger::debug!(
+ "Shadow UCS call in Direct with shadow UCS processing failed: {:?}",
+ e
+ )
+ })
+ .ok()
+ }
+ .instrument(tracing::Span::current()),
+ );
result
}
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs
index 1923be79ff..469a006ead 100644
--- a/crates/router/src/core/refunds.rs
+++ b/crates/router/src/core/refunds.rs
@@ -14,7 +14,7 @@ use hyperswitch_domain_models::{
router_data::ErrorResponse, router_request_types::SplitRefundsRequest,
};
use hyperswitch_interfaces::integrity::{CheckIntegrity, FlowIntegrity, GetIntegrityObject};
-use router_env::{instrument, tracing};
+use router_env::{instrument, tracing, tracing::Instrument};
use scheduler::{
consumer::types::process_data, errors as sch_errors, utils as process_tracker_utils,
};
@@ -575,20 +575,21 @@ async fn execute_refund_execute_via_direct_with_ucs_shadow(
// Clone direct result for comparison (if successful)
let direct_router_data_for_comparison = direct_result.as_ref().ok().cloned();
- tokio::spawn(async move {
- let ucs_result =
- unified_connector_service::call_unified_connector_service_for_refund_execute(
- &ucs_state,
- &ucs_platform,
- ucs_router_data,
- ExecutionMode::Shadow,
- merchant_connector_account,
- )
- .await;
+ tokio::spawn(
+ async move {
+ let ucs_result =
+ unified_connector_service::call_unified_connector_service_for_refund_execute(
+ &ucs_state,
+ &ucs_platform,
+ ucs_router_data,
+ ExecutionMode::Shadow,
+ merchant_connector_account,
+ )
+ .await;
- match (ucs_result, direct_router_data_for_comparison) {
- (Ok(ucs_router_data), Some(direct_router_data)) => {
- unified_connector_service::serialize_router_data_and_send_to_comparison_service(
+ match (ucs_result, direct_router_data_for_comparison) {
+ (Ok(ucs_router_data), Some(direct_router_data)) => {
+ unified_connector_service::serialize_router_data_and_send_to_comparison_service(
&ucs_state,
direct_router_data,
ucs_router_data,
@@ -601,20 +602,22 @@ async fn execute_refund_execute_via_direct_with_ucs_shadow(
);
})
.ok();
- }
- (Err(e), _) => {
- router_env::logger::debug!(
- "Skipping refund execute comparison - UCS shadow execute failed: {:?}",
- e
- );
- }
- (_, None) => {
- router_env::logger::debug!(
- "Skipping refund execute comparison - direct execute failed"
- );
+ }
+ (Err(e), _) => {
+ router_env::logger::debug!(
+ "Skipping refund execute comparison - UCS shadow execute failed: {:?}",
+ e
+ );
+ }
+ (_, None) => {
+ router_env::logger::debug!(
+ "Skipping refund execute comparison - direct execute failed"
+ );
+ }
}
}
- });
+ .instrument(tracing::Span::current()),
+ );
// Return PRIMARY result (Direct connector response)
direct_result
@@ -1091,19 +1094,21 @@ async fn execute_refund_sync_via_direct_with_ucs_shadow(
let merchant_connector_account = merchant_connector_account.clone();
let direct_router_data_for_comparison = direct_result.as_ref().ok().cloned();
- tokio::spawn(async move {
- let ucs_result = unified_connector_service::call_unified_connector_service_for_refund_sync(
- &state,
- &platform,
- router_data,
- ExecutionMode::Shadow,
- merchant_connector_account,
- )
- .await;
+ tokio::spawn(
+ async move {
+ let ucs_result =
+ unified_connector_service::call_unified_connector_service_for_refund_sync(
+ &state,
+ &platform,
+ router_data,
+ ExecutionMode::Shadow,
+ merchant_connector_account,
+ )
+ .await;
- match (ucs_result, direct_router_data_for_comparison) {
- (Ok(ucs_router_data), Some(direct_router_data)) => {
- unified_connector_service::serialize_router_data_and_send_to_comparison_service(
+ match (ucs_result, direct_router_data_for_comparison) {
+ (Ok(ucs_router_data), Some(direct_router_data)) => {
+ unified_connector_service::serialize_router_data_and_send_to_comparison_service(
&state,
direct_router_data,
ucs_router_data,
@@ -1113,17 +1118,21 @@ async fn execute_refund_sync_via_direct_with_ucs_shadow(
router_env::logger::debug!("Shadow UCS sync comparison failed: {:?}", e);
})
.ok();
- }
- (Err(_), _) => {
- router_env::logger::debug!(
- "Skipping refund sync comparison - UCS shadow sync failed"
- );
- }
- (_, None) => {
- router_env::logger::debug!("Skipping refund sync comparison - direct sync failed");
+ }
+ (Err(_), _) => {
+ router_env::logger::debug!(
+ "Skipping refund sync comparison - UCS shadow sync failed"
+ );
+ }
+ (_, None) => {
+ router_env::logger::debug!(
+ "Skipping refund sync comparison - direct sync failed"
+ );
+ }
}
}
- });
+ .instrument(tracing::Span::current()),
+ );
direct_result
}