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

refactor(euclid): refactor logs (#11726)

Prajjwal Kumarbd71c40f8ba7
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index 4d46f51475..b52d5770d8 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -38924,6 +38924,12 @@
"description": "Identifier of the user/system triggering routing evaluation.\n\nExample:\n```json\n\"created_by\": \"some_id\"\n```",
"example": "profile_123"
},
+ "payment_id": {
+ "type": "string",
+ "description": "Payment ID for debugging and tracing routing decisions.\n\nExample:\n```json\n\"payment_id\": \"pay_abc123\"\n```",
+ "example": "pay_abc123",
+ "nullable": true
+ },
"parameters": {
"type": "object",
"description": "Dynamic parameters used during routing evaluation.\n\nEach key represents a routing attribute.\n\nExample fields:\n\n- `payment_method`\n- `payment_method_type`\n- `amount`\n- `currency`\n- `authentication_type`\n- `card_bin`\n- `capture_method`\n- `business_country`\n- `billing_country`\n- `business_label`\n- `setup_future_usage`\n- `card_network`\n- `payment_type`\n- `mandate_type`\n- `mandate_acceptance_type`\n- `metadata`\n\nExample:\n```json\n{\n\"payment_method\": { \"type\": \"enum_variant\", \"value\": \"card\" },\n\"amount\": { \"type\": \"number\", \"value\": 10 },\n\"currency\": { \"type\": \"str_value\", \"value\": \"INR\" },\n\"authentication_type\": { \"type\": \"enum_variant\", \"value\": \"three_ds\" },\n\"card_bin\": { \"type\": \"str_value\", \"value\": \"424242\" },\n\"business_country\": { \"type\": \"str_value\", \"value\": \"IN\" },\n\"setup_future_usage\": { \"type\": \"enum_variant\", \"value\": \"off_session\" },\n\"card_network\": { \"type\": \"enum_variant\", \"value\": \"visa\" },\n\"metadata\": {\n\"type\": \"metadata_variant\",\n\"value\": { \"key\": \"key1\", \"value\": \"value1\" }\n}\n}\n```\n\nFor the complete superset of supported routing keys,\nrefer to `routing_configs.keys` in:\nhttps://github.com/juspay/decision-engine/blob/main/config/development.toml"
diff --git a/crates/api_models/src/routing.rs b/crates/api_models/src/routing.rs
index 9454ddbb59..9266dd1a89 100644
--- a/crates/api_models/src/routing.rs
+++ b/crates/api_models/src/routing.rs
@@ -1917,6 +1917,14 @@ pub struct RoutingEvaluateRequest {
/// ```
#[schema(example = "profile_123")]
pub created_by: String,
+ /// Payment ID for debugging and tracing routing decisions.
+ ///
+ /// Example:
+ /// ```json
+ /// "payment_id": "pay_abc123"
+ /// ```
+ #[schema(example = "pay_abc123")]
+ pub payment_id: Option<String>,
/// Dynamic parameters used during routing evaluation.
///
/// Each key represents a routing attribute.
diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rs
index b52ba58fbf..5b3d4e9538 100644
--- a/crates/router/src/core/payments/routing.rs
+++ b/crates/router/src/core/payments/routing.rs
@@ -1490,6 +1490,13 @@ impl RoutingStage for HybridRoutingStage {
let should_include_static_request = input.state.conf.open_router.static_routing_enabled
&& input.static_approach == common_enums::RoutingApproach::RuleBasedRouting;
+ let payment_id = input
+ .payment_dsl_input
+ .payment_attempt
+ .payment_id
+ .get_string_repr()
+ .to_string();
+
let static_routing_request = if should_include_static_request {
Some(utils::build_static_routing_request_for_hybrid(
input
@@ -1497,6 +1504,7 @@ impl RoutingStage for HybridRoutingStage {
.get_id()
.get_string_repr()
.to_string(),
+ payment_id.clone(),
input.backend_input.clone(),
input.fallback_config.to_vec(),
)?)
@@ -1510,13 +1518,6 @@ impl RoutingStage for HybridRoutingStage {
);
RoutingConnectorOutcomeWithApproach::empty()
} else {
- let payment_id = input
- .payment_dsl_input
- .payment_attempt
- .payment_id
- .get_string_repr()
- .to_string();
-
let hybrid_outcome = utils::decision_engine_hybrid_routing(
input.state,
input.business_profile,
diff --git a/crates/router/src/core/payments/routing/utils.rs b/crates/router/src/core/payments/routing/utils.rs
index d5a630d3f4..faf3da2603 100644
--- a/crates/router/src/core/payments/routing/utils.rs
+++ b/crates/router/src/core/payments/routing/utils.rs
@@ -344,11 +344,13 @@ fn convert_fallback_to_de_choices(
pub fn build_static_routing_request_for_hybrid(
created_by: String,
+ payment_id: String,
input: BackendInput,
fallback_output: Vec<RoutableConnectorChoice>,
) -> RoutingResult<RoutingEvaluateRequest> {
convert_backend_input_to_routing_eval(
created_by,
+ Some(payment_id),
input,
convert_fallback_to_de_choices(fallback_output),
)
@@ -472,7 +474,7 @@ pub async fn decision_engine_hybrid_routing(
payment_id,
business_profile.get_id().to_owned(),
business_profile.merchant_id.to_owned(),
- "DecisionEngine: Hybrid Routing".to_string(),
+ "DecisionEngine: Routing".to_string(),
Some(hybrid_request.clone()),
true,
false,
@@ -516,6 +518,7 @@ pub async fn perform_decision_euclid_routing(
state: &SessionState,
input: BackendInput,
created_by: String,
+ payment_id: String,
events_wrapper: RoutingEventsWrapper<RoutingEvaluateRequest>,
fallback_output: Vec<RoutableConnectorChoice>,
) -> RoutingResult<RoutingEvaluateResponse> {
@@ -524,8 +527,12 @@ pub async fn perform_decision_euclid_routing(
let mut events_wrapper = events_wrapper;
let fallback_output = convert_fallback_to_de_choices(fallback_output);
- let routing_request =
- convert_backend_input_to_routing_eval(created_by, input, fallback_output)?;
+ let routing_request = convert_backend_input_to_routing_eval(
+ created_by,
+ Some(payment_id),
+ input,
+ fallback_output,
+ )?;
events_wrapper.set_request_body(routing_request.clone());
let event_response = EuclidApiClient::send_decision_engine_request(
@@ -610,7 +617,7 @@ pub async fn decision_engine_routing(
let routing_events_wrapper = RoutingEventsWrapper::new(
state.tenant.tenant_id.clone(),
state.request_id.clone(),
- payment_id,
+ payment_id.clone(),
business_profile.get_id().to_owned(),
business_profile.merchant_id.to_owned(),
"DecisionEngine: Euclid Static Routing".to_string(),
@@ -623,6 +630,7 @@ pub async fn decision_engine_routing(
state,
backend_input.clone(),
business_profile.get_id().get_string_repr().to_string(),
+ payment_id,
routing_events_wrapper,
merchant_fallback_config,
)
@@ -1002,6 +1010,7 @@ pub struct ListRountingAlgorithmsRequest {
// Maps Hyperswitch `BackendInput` to a `RoutingEvaluateRequest` compatible with Decision Engine
pub fn convert_backend_input_to_routing_eval(
created_by: String,
+ payment_id: Option<String>,
input: BackendInput,
fallback_output: Vec<DeRoutableConnectorChoice>,
) -> RoutingResult<RoutingEvaluateRequest> {
@@ -1136,6 +1145,7 @@ pub fn convert_backend_input_to_routing_eval(
Ok(RoutingEvaluateRequest {
created_by,
+ payment_id,
parameters: params,
fallback_output,
})