feat(metrics): add flow-specific metrics (#1259)

This commit is contained in:
Sangamesh Kulkarni
2023-05-25 14:37:05 +05:30
committed by GitHub
parent 71a17c682e
commit 5e90a369db
5 changed files with 81 additions and 3 deletions

View File

@ -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")?;

View File

@ -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 {

View File

@ -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(),

View File

@ -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),

View File

@ -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);