mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-30 09:38:33 +08:00 
			
		
		
		
	feat(metrics): add flow-specific metrics (#1259)
This commit is contained in:
		 Sangamesh Kulkarni
					Sangamesh Kulkarni
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							71a17c682e
						
					
				
				
					commit
					5e90a369db
				
			| @ -34,7 +34,7 @@ use crate::{ | |||||||
|     }, |     }, | ||||||
|     db::StorageInterface, |     db::StorageInterface, | ||||||
|     logger, |     logger, | ||||||
|     routes::AppState, |     routes::{metrics, AppState}, | ||||||
|     scheduler::utils as pt_utils, |     scheduler::utils as pt_utils, | ||||||
|     services::{self, api::Authenticate}, |     services::{self, api::Authenticate}, | ||||||
|     types::{ |     types::{ | ||||||
| @ -285,6 +285,20 @@ pub trait PaymentRedirectFlow: Sync { | |||||||
|         merchant_account: storage::MerchantAccount, |         merchant_account: storage::MerchantAccount, | ||||||
|         req: PaymentsRedirectResponseData, |         req: PaymentsRedirectResponseData, | ||||||
|     ) -> RouterResponse<api::RedirectionResponse> { |     ) -> 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 connector = req.connector.clone().get_required_value("connector")?; | ||||||
|  |  | ||||||
|         let query_params = req.param.clone().get_required_value("param")?; |         let query_params = req.param.clone().get_required_value("param")?; | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ use crate::{ | |||||||
|         payments, |         payments, | ||||||
|     }, |     }, | ||||||
|     logger, |     logger, | ||||||
|     routes::AppState, |     routes::{metrics, AppState}, | ||||||
|     services, |     services, | ||||||
|     types::{self, api, storage}, |     types::{self, api, storage}, | ||||||
| }; | }; | ||||||
| @ -51,6 +51,15 @@ pub async fn create_connector_customer<F: Clone, T: Clone>( | |||||||
|     .await |     .await | ||||||
|     .map_err(|error| error.to_payment_failed_response())?; |     .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 { |     let connector_customer_id = match resp.response { | ||||||
|         Ok(response) => match response { |         Ok(response) => match response { | ||||||
|             types::PaymentsResponseData::ConnectorCustomerResponse { |             types::PaymentsResponseData::ConnectorCustomerResponse { | ||||||
|  | |||||||
| @ -143,6 +143,19 @@ impl types::PaymentsAuthorizeRouterData { | |||||||
|                     .execute_pretasks(self, state) |                     .execute_pretasks(self, state) | ||||||
|                     .await |                     .await | ||||||
|                     .map_err(|error| error.to_payment_failed_response())?; |                     .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); |                 logger::debug!(completed_pre_tasks=?true); | ||||||
|                 if self.should_proceed_with_authorize() { |                 if self.should_proceed_with_authorize() { | ||||||
|                     self.decide_authentication_type(); |                     self.decide_authentication_type(); | ||||||
| @ -257,6 +270,27 @@ pub async fn authorize_preprocessing_steps<F: Clone>( | |||||||
|         .await |         .await | ||||||
|         .map_err(|error| error.to_payment_failed_response())?; |         .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 = |         let authorize_router_data = | ||||||
|             payments::helpers::router_data_type_conversion::<_, F, _, _, _, _>( |             payments::helpers::router_data_type_conversion::<_, F, _, _, _, _>( | ||||||
|                 resp.clone(), |                 resp.clone(), | ||||||
|  | |||||||
| @ -9,7 +9,7 @@ use crate::{ | |||||||
|         mandate, payment_methods, payments, |         mandate, payment_methods, payments, | ||||||
|     }, |     }, | ||||||
|     logger, |     logger, | ||||||
|     routes::AppState, |     routes::{metrics, AppState}, | ||||||
|     services, |     services, | ||||||
|     types::{ |     types::{ | ||||||
|         self, |         self, | ||||||
| @ -231,6 +231,21 @@ pub async fn add_payment_method_token<F: Clone, T: Clone>( | |||||||
|             .await |             .await | ||||||
|             .map_err(|error| error.to_payment_failed_response())?; |             .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 { |             let pm_token = match resp.response { | ||||||
|                 Ok(response) => match response { |                 Ok(response) => match response { | ||||||
|                     types::PaymentsResponseData::TokenizationResponse { token } => Some(token), |                     types::PaymentsResponseData::TokenizationResponse { token } => Some(token), | ||||||
|  | |||||||
| @ -57,6 +57,12 @@ counter_metric!(RESPONSE_DESERIALIZATION_FAILURE, GLOBAL_METER); | |||||||
| counter_metric!(CONNECTOR_ERROR_RESPONSE_COUNT, GLOBAL_METER); | counter_metric!(CONNECTOR_ERROR_RESPONSE_COUNT, GLOBAL_METER); | ||||||
| counter_metric!(REQUEST_TIMEOUT_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 | // Connector Level Metric | ||||||
| counter_metric!(REQUEST_BUILD_FAILURE, GLOBAL_METER); | counter_metric!(REQUEST_BUILD_FAILURE, GLOBAL_METER); | ||||||
| counter_metric!(UNIMPLEMENTED_FLOW, GLOBAL_METER); | counter_metric!(UNIMPLEMENTED_FLOW, GLOBAL_METER); | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user