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(metrics): add flow-specific metrics (#1259)

Sangamesh Kulkarni5e90a369db32
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 8628251d00..c2faae18a8 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -34,7 +34,7 @@ use crate::{
},
db::StorageInterface,
logger,
- routes::AppState,
+ routes::{metrics, AppState},
scheduler::utils as pt_utils,
services::{self, api::Authenticate},
types::{
@@ -285,6 +285,20 @@ pub trait PaymentRedirectFlow: Sync {
merchant_account: storage::MerchantAccount,
req: PaymentsRedirectResponseData,
) -> RouterResponse<api::RedirectionResponse> {
+ metrics::REDIRECTION_TRIGGERED.add(
+ &metrics::CONTEXT,
+ 1,
+ &[
+ metrics::request::add_attributes(
+ "connector",
+ req.connector.to_owned().unwrap_or("null".to_string()),
+ ),
+ metrics::request::add_attributes(
+ "merchant_id",
+ merchant_account.merchant_id.to_owned(),
+ ),
+ ],
+ );
let connector = req.connector.clone().get_required_value("connector")?;
let query_params = req.param.clone().get_required_value("param")?;
diff --git a/crates/router/src/core/payments/customers.rs b/crates/router/src/core/payments/customers.rs
index 910fb5f985..4b8e99fcb9 100644
--- a/crates/router/src/core/payments/customers.rs
+++ b/crates/router/src/core/payments/customers.rs
@@ -7,7 +7,7 @@ use crate::{
payments,
},
logger,
- routes::AppState,
+ routes::{metrics, AppState},
services,
types::{self, api, storage},
};
@@ -51,6 +51,15 @@ pub async fn create_connector_customer<F: Clone, T: Clone>(
.await
.map_err(|error| error.to_payment_failed_response())?;
+ metrics::CONNECTOR_CUSTOMER_CREATE.add(
+ &metrics::CONTEXT,
+ 1,
+ &[metrics::request::add_attributes(
+ "connector",
+ connector.connector_name.to_string(),
+ )],
+ );
+
let connector_customer_id = match resp.response {
Ok(response) => match response {
types::PaymentsResponseData::ConnectorCustomerResponse {
diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs
index 744c1c0d14..fd9a17a017 100644
--- a/crates/router/src/core/payments/flows/authorize_flow.rs
+++ b/crates/router/src/core/payments/flows/authorize_flow.rs
@@ -143,6 +143,19 @@ impl types::PaymentsAuthorizeRouterData {
.execute_pretasks(self, state)
.await
.map_err(|error| error.to_payment_failed_response())?;
+
+ metrics::EXECUTE_PRETASK_COUNT.add(
+ &metrics::CONTEXT,
+ 1,
+ &[
+ metrics::request::add_attributes(
+ "connector",
+ connector.connector_name.to_string(),
+ ),
+ metrics::request::add_attributes("flow", format!("{:?}", api::Authorize)),
+ ],
+ );
+
logger::debug!(completed_pre_tasks=?true);
if self.should_proceed_with_authorize() {
self.decide_authentication_type();
@@ -257,6 +270,27 @@ pub async fn authorize_preprocessing_steps<F: Clone>(
.await
.map_err(|error| error.to_payment_failed_response())?;
+ metrics::PREPROCESSING_STEPS_COUNT.add(
+ &metrics::CONTEXT,
+ 1,
+ &[
+ metrics::request::add_attributes("connector", connector.connector_name.to_string()),
+ metrics::request::add_attributes(
+ "payment_method",
+ router_data.payment_method.to_string(),
+ ),
+ metrics::request::add_attributes(
+ "payment_method_type",
+ router_data
+ .request
+ .payment_method_type
+ .as_ref()
+ .map(|inner| inner.to_string())
+ .unwrap_or("null".to_string()),
+ ),
+ ],
+ );
+
let authorize_router_data =
payments::helpers::router_data_type_conversion::<_, F, _, _, _, _>(
resp.clone(),
diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rs
index 3dec82570c..8dbea2295c 100644
--- a/crates/router/src/core/payments/tokenization.rs
+++ b/crates/router/src/core/payments/tokenization.rs
@@ -9,7 +9,7 @@ use crate::{
mandate, payment_methods, payments,
},
logger,
- routes::AppState,
+ routes::{metrics, AppState},
services,
types::{
self,
@@ -231,6 +231,21 @@ pub async fn add_payment_method_token<F: Clone, T: Clone>(
.await
.map_err(|error| error.to_payment_failed_response())?;
+ metrics::CONNECTOR_PAYMENT_METHOD_TOKENIZATION.add(
+ &metrics::CONTEXT,
+ 1,
+ &[
+ metrics::request::add_attributes(
+ "connector",
+ connector.connector_name.to_string(),
+ ),
+ metrics::request::add_attributes(
+ "payment_method",
+ router_data.payment_method.to_string(),
+ ),
+ ],
+ );
+
let pm_token = match resp.response {
Ok(response) => match response {
types::PaymentsResponseData::TokenizationResponse { token } => Some(token),
diff --git a/crates/router/src/routes/metrics.rs b/crates/router/src/routes/metrics.rs
index 133a01bb5c..499e579235 100644
--- a/crates/router/src/routes/metrics.rs
+++ b/crates/router/src/routes/metrics.rs
@@ -57,6 +57,12 @@ counter_metric!(RESPONSE_DESERIALIZATION_FAILURE, GLOBAL_METER);
counter_metric!(CONNECTOR_ERROR_RESPONSE_COUNT, GLOBAL_METER);
counter_metric!(REQUEST_TIMEOUT_COUNT, GLOBAL_METER);
+counter_metric!(EXECUTE_PRETASK_COUNT, GLOBAL_METER);
+counter_metric!(CONNECTOR_PAYMENT_METHOD_TOKENIZATION, GLOBAL_METER);
+counter_metric!(PREPROCESSING_STEPS_COUNT, GLOBAL_METER);
+counter_metric!(CONNECTOR_CUSTOMER_CREATE, GLOBAL_METER);
+counter_metric!(REDIRECTION_TRIGGERED, GLOBAL_METER);
+
// Connector Level Metric
counter_metric!(REQUEST_BUILD_FAILURE, GLOBAL_METER);
counter_metric!(UNIMPLEMENTED_FLOW, GLOBAL_METER);