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

feat(router): add relevant metrics and logs for manual retries flow (#1985)

Sai Harsha Vardhan1b346fcf5649
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 89f2217e10..8a4804b581 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -2496,6 +2496,14 @@ pub fn get_attempt_type(
request.retry_action,
Some(api_models::enums::RetryAction::ManualRetry)
) {
+ metrics::MANUAL_RETRY_REQUEST_COUNT.add(
+ &metrics::CONTEXT,
+ 1,
+ &[metrics::request::add_attributes(
+ "merchant_id",
+ payment_attempt.merchant_id.clone(),
+ )],
+ );
match payment_attempt.status {
enums::AttemptStatus::Started
| enums::AttemptStatus::AuthenticationPending
@@ -2514,6 +2522,14 @@ pub fn get_attempt_type(
| enums::AttemptStatus::AutoRefunded
| enums::AttemptStatus::PaymentMethodAwaited
| enums::AttemptStatus::DeviceDataCollectionPending => {
+ metrics::MANUAL_RETRY_VALIDATION_FAILED.add(
+ &metrics::CONTEXT,
+ 1,
+ &[metrics::request::add_attributes(
+ "merchant_id",
+ payment_attempt.merchant_id.clone(),
+ )],
+ );
Err(errors::ApiErrorResponse::InternalServerError)
.into_report()
.attach_printable("Payment Attempt unexpected state")
@@ -2521,15 +2537,35 @@ pub fn get_attempt_type(
storage_enums::AttemptStatus::VoidFailed
| storage_enums::AttemptStatus::RouterDeclined
- | storage_enums::AttemptStatus::CaptureFailed => Err(report!(errors::ApiErrorResponse::PreconditionFailed {
- message:
- format!("You cannot {action} this payment because it has status {}, and the previous attempt has the status {}", payment_intent.status, payment_attempt.status)
- }
- )),
+ | storage_enums::AttemptStatus::CaptureFailed => {
+ metrics::MANUAL_RETRY_VALIDATION_FAILED.add(
+ &metrics::CONTEXT,
+ 1,
+ &[metrics::request::add_attributes(
+ "merchant_id",
+ payment_attempt.merchant_id.clone(),
+ )],
+ );
+ Err(report!(errors::ApiErrorResponse::PreconditionFailed {
+ message:
+ format!("You cannot {action} this payment because it has status {}, and the previous attempt has the status {}", payment_intent.status, payment_attempt.status)
+ }
+ ))
+ }
storage_enums::AttemptStatus::AuthenticationFailed
| storage_enums::AttemptStatus::AuthorizationFailed
- | storage_enums::AttemptStatus::Failure => Ok(AttemptType::New),
+ | storage_enums::AttemptStatus::Failure => {
+ metrics::MANUAL_RETRY_COUNT.add(
+ &metrics::CONTEXT,
+ 1,
+ &[metrics::request::add_attributes(
+ "merchant_id",
+ payment_attempt.merchant_id.clone(),
+ )],
+ );
+ Ok(AttemptType::New)
+ }
}
} else {
Err(report!(errors::ApiErrorResponse::PreconditionFailed {
@@ -2678,6 +2714,12 @@ impl AttemptType {
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
+ logger::info!(
+ "manual_retry payment for {} with attempt_id {}",
+ updated_payment_intent.payment_id,
+ new_payment_attempt.attempt_id
+ );
+
Ok((updated_payment_intent, new_payment_attempt))
}
}
diff --git a/crates/router/src/routes/metrics.rs b/crates/router/src/routes/metrics.rs
index ec85a926b7..bbdfdd99cf 100644
--- a/crates/router/src/routes/metrics.rs
+++ b/crates/router/src/routes/metrics.rs
@@ -28,7 +28,10 @@ counter_metric!(SUCCESSFUL_CANCEL, GLOBAL_METER);
counter_metric!(MANDATE_COUNT, GLOBAL_METER);
counter_metric!(SUBSEQUENT_MANDATE_PAYMENT, GLOBAL_METER);
-counter_metric!(RETRY_COUNT, GLOBAL_METER);
+// Manual retry metrics
+counter_metric!(MANUAL_RETRY_REQUEST_COUNT, GLOBAL_METER);
+counter_metric!(MANUAL_RETRY_COUNT, GLOBAL_METER);
+counter_metric!(MANUAL_RETRY_VALIDATION_FAILED, GLOBAL_METER);
counter_metric!(STORED_TO_LOCKER, GLOBAL_METER);
counter_metric!(GET_FROM_LOCKER, GLOBAL_METER);