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(analytics): surface connector-event dimensions + ucs_api_events read API (#12899)
gopikrishna000c2b8d14d1613
diff --git a/crates/analytics/src/clickhouse.rs b/crates/analytics/src/clickhouse.rsindex 2f6bfc7b0f..74dee8edf9 100644--- a/crates/analytics/src/clickhouse.rs+++ b/crates/analytics/src/clickhouse.rs@@ -153,6 +153,8 @@ impl AnalyticsDataSource for ClickhouseClient {| AnalyticsCollection::ApiPayoutEvents| AnalyticsCollection::ConnectorEvents| AnalyticsCollection::ConnectorPayoutEvents+ | AnalyticsCollection::PrismConnectorEvents+ | AnalyticsCollection::PrismConnectorPayoutEvents| AnalyticsCollection::RoutingEvents| AnalyticsCollection::ApiEventsAnalytics| AnalyticsCollection::OutgoingWebhookEvent@@ -484,6 +486,10 @@ impl ToSql<ClickhouseClient> for AnalyticsCollection {Self::PaymentIntentSessionized => Ok("sessionizer_payment_intents".to_string()),Self::ConnectorEvents => Ok("connector_events_audit".to_string()),Self::ConnectorPayoutEvents => Ok("connector_events_payout_audit".to_string()),+ Self::PrismConnectorEvents => Ok("prism_connector_events_audit".to_string()),+ Self::PrismConnectorPayoutEvents => {+ Ok("prism_connector_events_payout_audit".to_string())+ }Self::OutgoingWebhookEvent => Ok("outgoing_webhook_events_audit".to_string()),Self::OutgoingWebhookPayoutEvent => {Ok("outgoing_webhook_events_payout_audit".to_string())diff --git a/crates/analytics/src/connector_events.rs b/crates/analytics/src/connector_events.rsindex c7c31306a2..f704f4c7c5 100644--- a/crates/analytics/src/connector_events.rs+++ b/crates/analytics/src/connector_events.rs@@ -3,3 +3,14 @@ pub mod events;pub trait ConnectorEventAnalytics: events::ConnectorEventLogAnalytics {}pub use self::core::connector_events_core;++/// Which set of physical connector-event tables a query targets.+#[derive(Debug, Clone, Copy)]+pub enum ConnectorEventSource {+ /// Native Hyperswitch connector events+ /// (`connector_events_audit` / `connector_events_payout_audit`).+ Hyperswitch,+ /// UCS/Prism-emitted connector events+ /// (`prism_connector_events_audit` / `prism_connector_events_payout_audit`).+ Prism,+}diff --git a/crates/analytics/src/connector_events/core.rs b/crates/analytics/src/connector_events/core.rsindex ae1405ed47..59e549d415 100644--- a/crates/analytics/src/connector_events/core.rs+++ b/crates/analytics/src/connector_events/core.rs@@ -2,13 +2,17 @@ use api_models::analytics::connector_events::ConnectorEventsRequest;use common_utils::errors::ReportSwitchExt;use error_stack::ResultExt;-use super::events::{get_connector_events, ConnectorEventsResult};+use super::{+ events::{get_connector_events, ConnectorEventsResult},+ ConnectorEventSource,+};use crate::{errors::AnalyticsResult, types::FiltersError, AnalyticsProvider};pub async fn connector_events_core(pool: &AnalyticsProvider,req: ConnectorEventsRequest,merchant_id: &common_utils::id_type::MerchantId,+ source: ConnectorEventSource,) -> AnalyticsResult<Vec<ConnectorEventsResult>> {let data = match pool {AnalyticsProvider::Sqlx(_) => Err(FiltersError::NotImplemented(@@ -18,7 +22,7 @@ pub async fn connector_events_core(AnalyticsProvider::Clickhouse(ckh_pool)| AnalyticsProvider::CombinedSqlx(_, ckh_pool)| AnalyticsProvider::CombinedCkh(_, ckh_pool) => {- get_connector_events(merchant_id, req, ckh_pool).await+ get_connector_events(merchant_id, req, ckh_pool, source).await}}.switch()?;diff --git a/crates/analytics/src/connector_events/events.rs b/crates/analytics/src/connector_events/events.rsindex 2b87a2cd8d..b4b413bccd 100644--- a/crates/analytics/src/connector_events/events.rs+++ b/crates/analytics/src/connector_events/events.rs@@ -3,6 +3,7 @@ use common_utils::errors::ReportSwitchExt;use error_stack::ResultExt;use time::PrimitiveDateTime;+use super::ConnectorEventSource;use crate::{query::{Aggregate, GroupByClause, QueryBuilder, ToSql, Window},types::{AnalyticsCollection, AnalyticsDataSource, FiltersError, FiltersResult, LoadRow},@@ -13,6 +14,7 @@ pub async fn get_connector_events<T>(merchant_id: &common_utils::id_type::MerchantId,query_param: ConnectorEventsRequest,pool: &T,+ source: ConnectorEventSource,) -> FiltersResult<Vec<ConnectorEventsResult>>whereT: AnalyticsDataSource + ConnectorEventLogAnalytics,@@ -22,9 +24,19 @@ whereAggregate<&'static str>: ToSql<T>,Window<&'static str>: ToSql<T>,{- let mut query_builder: QueryBuilder<T> = match query_param.payment_id {- Some(_) => QueryBuilder::new(AnalyticsCollection::ConnectorEvents),- None => QueryBuilder::new(AnalyticsCollection::ConnectorPayoutEvents),+ let mut query_builder: QueryBuilder<T> = match (source, query_param.payment_id.as_ref()) {+ (ConnectorEventSource::Prism, Some(_)) => {+ QueryBuilder::new(AnalyticsCollection::PrismConnectorEvents)+ }+ (ConnectorEventSource::Prism, None) => {+ QueryBuilder::new(AnalyticsCollection::PrismConnectorPayoutEvents)+ }+ (ConnectorEventSource::Hyperswitch, Some(_)) => {+ QueryBuilder::new(AnalyticsCollection::ConnectorEvents)+ }+ (ConnectorEventSource::Hyperswitch, None) => {+ QueryBuilder::new(AnalyticsCollection::ConnectorPayoutEvents)+ }};query_builder.add_select_column("*").switch()?;diff --git a/crates/analytics/src/lib.rs b/crates/analytics/src/lib.rsindex 5524519ef9..2f914c07da 100644--- a/crates/analytics/src/lib.rs+++ b/crates/analytics/src/lib.rs@@ -1175,6 +1175,7 @@ pub enum AnalyticsFlow {GetApiEventMetrics,GetApiEventFilters,GetConnectorEvents,+ GetPrismConnectorEvents,GetOutgoingWebhookEvents,GetGlobalSearchResults,GetSearchResults,diff --git a/crates/analytics/src/sqlx.rs b/crates/analytics/src/sqlx.rsindex b44988a833..61d236b88b 100644--- a/crates/analytics/src/sqlx.rs+++ b/crates/analytics/src/sqlx.rs@@ -1467,6 +1467,12 @@ impl ToSql<SqlxClient> for AnalyticsCollection {.attach_printable("ConnectorEvents table is not implemented for Sqlx"))?,Self::ConnectorPayoutEvents => Err(error_stack::report!(ParsingError::UnknownError).attach_printable("ConnectorPayoutEvents table is not implemented for Sqlx"))?,+ Self::PrismConnectorEvents => Err(error_stack::report!(ParsingError::UnknownError)+ .attach_printable("PrismConnectorEvents table is not implemented for Sqlx"))?,+ Self::PrismConnectorPayoutEvents => Err(error_stack::report!(+ ParsingError::UnknownError+ )+ .attach_printable("PrismConnectorPayoutEvents table is not implemented for Sqlx"))?,Self::ApiEventsAnalytics => Err(error_stack::report!(ParsingError::UnknownError).attach_printable("ApiEvents table is not implemented for Sqlx"))?,Self::ActivePaymentsAnalytics => Err(error_stack::report!(ParsingError::UnknownError)diff --git a/crates/analytics/src/types.rs b/crates/analytics/src/types.rsindex 7f0db8dd2a..0d2b868857 100644--- a/crates/analytics/src/types.rs+++ b/crates/analytics/src/types.rs@@ -39,6 +39,8 @@ pub enum AnalyticsCollection {PaymentIntentSessionized,ConnectorEvents,ConnectorPayoutEvents,+ PrismConnectorEvents,+ PrismConnectorPayoutEvents,OutgoingWebhookEvent,OutgoingWebhookPayoutEvent,Authentications,diff --git a/crates/router/src/analytics.rs b/crates/router/src/analytics.rsindex 6c0a5a8d27..03565c8eae 100644--- a/crates/router/src/analytics.rs+++ b/crates/router/src/analytics.rs@@ -8,10 +8,16 @@ pub mod routes {use actix_web::{web, Responder, Scope};use analytics::{- api_event::api_events_core, connector_events::connector_events_core, enums::AuthInfo,- errors::AnalyticsError, lambda_utils::invoke_lambda, opensearch::OpenSearchError,- outgoing_webhook_event::outgoing_webhook_events_core, routing_events::routing_events_core,- sdk_events::sdk_events_core, AnalyticsFlow,+ api_event::api_events_core,+ connector_events::{connector_events_core, ConnectorEventSource},+ enums::AuthInfo,+ errors::AnalyticsError,+ lambda_utils::invoke_lambda,+ opensearch::OpenSearchError,+ outgoing_webhook_event::outgoing_webhook_events_core,+ routing_events::routing_events_core,+ sdk_events::sdk_events_core,+ AnalyticsFlow,};use api_models::analytics::{api_event::QueryType,@@ -174,6 +180,10 @@ pub mod routes {web::resource("connector_event_logs").route(web::get().to(get_profile_connector_events)),)+ .service(+ web::resource("prism_connector_event_logs")+ .route(web::get().to(get_profile_prism_connector_events)),+ ).service(web::resource("routing_event_logs").route(web::get().to(get_profile_routing_events)),@@ -432,6 +442,10 @@ pub mod routes {web::resource("connector_event_logs").route(web::get().to(get_profile_connector_events)),)+ .service(+ web::resource("prism_connector_event_logs")+ .route(web::get().to(get_profile_prism_connector_events)),+ ).service(web::resource("routing_event_logs").route(web::get().to(get_profile_routing_events)),@@ -3659,18 +3673,19 @@ pub mod routes {.await}- pub async fn get_profile_connector_events(+ async fn connector_event_logs(state: web::Data<AppState>,req: actix_web::HttpRequest,json_payload: web::Query<api_models::analytics::connector_events::ConnectorEventsRequest>,+ flow: AnalyticsFlow,+ source: ConnectorEventSource,) -> impl Responder {- let flow = AnalyticsFlow::GetConnectorEvents;Box::pin(api::server_wrap(flow,state,&req,json_payload.into_inner(),- |state, auth: AuthenticationData, req, _| async move {+ move |state, auth: AuthenticationData, req, _| async move {#[cfg(feature = "v1")]let profile_id = auth.profile.map(|profile| profile.get_id().clone());#[cfg(feature = "v2")]@@ -3688,6 +3703,7 @@ pub mod routes {&state.pool,req,auth.platform.get_processor().get_account().get_id(),+ source,).await.map(ApplicationResponse::Json)@@ -3702,6 +3718,36 @@ pub mod routes {.await}+ pub async fn get_profile_connector_events(+ state: web::Data<AppState>,+ req: actix_web::HttpRequest,+ json_payload: web::Query<api_models::analytics::connector_events::ConnectorEventsRequest>,+ ) -> impl Responder {+ connector_event_logs(+ state,+ req,+ json_payload,+ AnalyticsFlow::GetConnectorEvents,+ ConnectorEventSource::Hyperswitch,+ )+ .await+ }++ pub async fn get_profile_prism_connector_events(+ state: web::Data<AppState>,+ req: actix_web::HttpRequest,+ json_payload: web::Query<api_models::analytics::connector_events::ConnectorEventsRequest>,+ ) -> impl Responder {+ connector_event_logs(+ state,+ req,+ json_payload,+ AnalyticsFlow::GetPrismConnectorEvents,+ ConnectorEventSource::Prism,+ )+ .await+ }+pub async fn get_profile_routing_events(state: web::Data<AppState>,req: actix_web::HttpRequest,