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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(events): adding infra level components to api-events (#8214)
Shivansh Mathurec908d38acb6
diff --git a/config/config.example.toml b/config/config.example.tomlindex 12a905e1f5..9943aa27e3 100644--- a/config/config.example.toml+++ b/config/config.example.toml@@ -1077,3 +1077,7 @@ retry_algorithm_type = "cascading" # type of retry algorithm[clone_connector_allowlist]merchant_ids = "merchant_ids" # Comma-separated list of allowed merchant IDsconnector_names = "connector_names" # Comma-separated list of allowed connector names++[infra_values]+cluster = "CLUSTER" # value of CLUSTER from deployment+version = "HOSTNAME" # value of HOSTNAME from deployment which tells its version\ No newline at end of filediff --git a/config/development.toml b/config/development.tomlindex d090c0aaaa..83b575d774 100644--- a/config/development.toml+++ b/config/development.toml@@ -1160,3 +1160,7 @@ retry_algorithm_type = "cascading"[clone_connector_allowlist]merchant_ids = "merchant_123, merchant_234" # Comma-separated list of allowed merchant IDsconnector_names = "stripe, adyen" # Comma-separated list of allowed connector names++[infra_values]+cluster = "CLUSTER"+version = "HOSTNAME"\ No newline at end of filediff --git a/config/docker_compose.toml b/config/docker_compose.tomlindex c6d40c59e8..a0f2515a52 100644--- a/config/docker_compose.toml+++ b/config/docker_compose.toml@@ -1069,3 +1069,7 @@ retry_algorithm_type = "cascading" # type of retry algorithm[clone_connector_allowlist]merchant_ids = "merchant_123, merchant_234" # Comma-separated list of allowed merchant IDsconnector_names = "stripe, adyen" # Comma-separated list of allowed connector names++[infra_values]+cluster = "CLUSTER" # value of CLUSTER from deployment+version = "HOSTNAME" # value of HOSTNAME from deployment which tells its version\ No newline at end of filediff --git a/crates/router/src/configs/secrets_transformers.rs b/crates/router/src/configs/secrets_transformers.rsindex e3f1b6abce..bc664cca95 100644--- a/crates/router/src/configs/secrets_transformers.rs+++ b/crates/router/src/configs/secrets_transformers.rs@@ -540,5 +540,6 @@ pub(crate) async fn fetch_raw_secrets(revenue_recovery: conf.revenue_recovery,debit_routing_config: conf.debit_routing_config,clone_connector_allowlist: conf.clone_connector_allowlist,+ infra_values: conf.infra_values,}}diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rsindex 8e1fb35ddc..8bd826dc33 100644--- a/crates/router/src/configs/settings.rs+++ b/crates/router/src/configs/settings.rs@@ -158,6 +158,8 @@ pub struct Settings<S: SecretState> {#[cfg(feature = "v2")]pub revenue_recovery: revenue_recovery::RevenueRecoverySettings,pub clone_connector_allowlist: Option<CloneConnectorAllowlistConfig>,+ #[serde(default)]+ pub infra_values: Option<HashMap<String, String>>,}#[derive(Debug, Deserialize, Clone, Default)]diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rsindex 2152c56341..a7a0c76e2f 100644--- a/crates/router/src/core/webhooks/incoming.rs+++ b/crates/router/src/core/webhooks/incoming.rs@@ -103,7 +103,7 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(let response_value = serde_json::to_value(&webhooks_response_tracker).change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Could not convert webhook effect to string")?;-+ let infra = state.infra_components.clone();let api_event = ApiEvent::new(state.tenant.tenant_id.clone(),Some(merchant_context.get_merchant_account().get_id().clone()),@@ -119,6 +119,7 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(api_event,req,req.method(),+ infra,);state.event_handler().log_event(&api_event);Ok(application_response)diff --git a/crates/router/src/core/webhooks/incoming_v2.rs b/crates/router/src/core/webhooks/incoming_v2.rsindex d1207b7cb9..a7b4302436 100644--- a/crates/router/src/core/webhooks/incoming_v2.rs+++ b/crates/router/src/core/webhooks/incoming_v2.rs@@ -97,6 +97,8 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Could not convert webhook effect to string")?;+ let infra = state.infra_components.clone();+let api_event = ApiEvent::new(state.tenant.tenant_id.clone(),Some(merchant_context.get_merchant_account().get_id().clone()),@@ -112,6 +114,7 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(api_event,req,req.method(),+ infra,);state.event_handler().log_event(&api_event);Ok(application_response)diff --git a/crates/router/src/events/api_logs.rs b/crates/router/src/events/api_logs.rsindex 419164810c..9435a0e318 100644--- a/crates/router/src/events/api_logs.rs+++ b/crates/router/src/events/api_logs.rs@@ -43,6 +43,8 @@ pub struct ApiEvent {event_type: ApiEventsType,hs_latency: Option<u128>,http_method: String,+ #[serde(flatten)]+ infra_components: Option<serde_json::Value>,}impl ApiEvent {@@ -62,6 +64,7 @@ impl ApiEvent {event_type: ApiEventsType,http_req: &HttpRequest,http_method: &http::Method,+ infra_components: Option<serde_json::Value>,) -> Self {Self {tenant_id,@@ -87,6 +90,7 @@ impl ApiEvent {event_type,hs_latency,http_method: http_method.to_string(),+ infra_components,}}}diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rsindex 18201380c3..a452e8283b 100644--- a/crates/router/src/routes/app.rs+++ b/crates/router/src/routes/app.rs@@ -130,6 +130,7 @@ pub struct SessionState {pub theme_storage_client: Arc<dyn FileStorageInterface>,pub locale: String,pub crm_client: Arc<dyn CrmInterface>,+ pub infra_components: Option<serde_json::Value>,}impl scheduler::SchedulerSessionState for SessionState {fn get_db(&self) -> Box<dyn SchedulerInterface> {@@ -242,6 +243,7 @@ pub struct AppState {pub grpc_client: Arc<GrpcClients>,pub theme_storage_client: Arc<dyn FileStorageInterface>,pub crm_client: Arc<dyn CrmInterface>,+ pub infra_components: Option<serde_json::Value>,}impl scheduler::SchedulerAppState for AppState {fn get_tenants(&self) -> Vec<id_type::TenantId> {@@ -406,7 +408,7 @@ impl AppState {let crm_client = conf.crm.get_crm_client().await;let grpc_client = conf.grpc_client.get_grpc_client_interface().await;-+ let infra_component_values = Self::process_env_mappings(conf.infra_values.clone());Self {flow_name: String::from("default"),stores,@@ -427,6 +429,7 @@ impl AppState {grpc_client,theme_storage_client,crm_client,+ infra_components: infra_component_values,}}).await@@ -521,8 +524,29 @@ impl AppState {theme_storage_client: self.theme_storage_client.clone(),locale: locale.unwrap_or(common_utils::consts::DEFAULT_LOCALE.to_string()),crm_client: self.crm_client.clone(),+ infra_components: self.infra_components.clone(),})}++ pub fn process_env_mappings(+ mappings: Option<HashMap<String, String>>,+ ) -> Option<serde_json::Value> {+ let result: HashMap<String, String> = mappings?+ .into_iter()+ .filter_map(|(key, env_var)| std::env::var(&env_var).ok().map(|value| (key, value)))+ .collect();++ if result.is_empty() {+ None+ } else {+ Some(serde_json::Value::Object(+ result+ .into_iter()+ .map(|(k, v)| (k, serde_json::Value::String(v)))+ .collect(),+ ))+ }+ }}pub struct Health;diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rsindex 2ae0c68cce..a80f2dc1d0 100644--- a/crates/router/src/services/api.rs+++ b/crates/router/src/services/api.rs@@ -602,7 +602,6 @@ where.switch(),)?};-let locale = utils::get_locale_from_header(&incoming_request_header.clone());let mut session_state =Arc::new(app_state.clone()).get_session_state(&tenant_id, Some(locale), || {@@ -701,6 +700,8 @@ where}};+ let infra = state.infra_components.clone();+let api_event = ApiEvent::new(tenant_id,Some(merchant_id.clone()),@@ -716,7 +717,9 @@ whereevent_type.unwrap_or(ApiEventsType::Miscellaneous),request,request.method(),+ infra.clone(),);+state.event_handler().log_event(&api_event);output