refactor(events): Tenant config in API, Connector and Outgoing Web-hook events (#6777)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
ShivanshMathurJuspay
2024-12-10 16:48:50 +05:30
committed by GitHub
parent 3df4233356
commit c620779bbd
7 changed files with 14 additions and 0 deletions

View File

@ -9,6 +9,7 @@ use time::OffsetDateTime;
/// struct ConnectorEvent
#[derive(Debug, Serialize)]
pub struct ConnectorEvent {
tenant_id: common_utils::id_type::TenantId,
connector_name: String,
flow: String,
request: String,
@ -31,6 +32,7 @@ impl ConnectorEvent {
/// fn new ConnectorEvent
#[allow(clippy::too_many_arguments)]
pub fn new(
tenant_id: common_utils::id_type::TenantId,
connector_name: String,
flow: &str,
request: serde_json::Value,
@ -45,6 +47,7 @@ impl ConnectorEvent {
status_code: u16,
) -> Self {
Self {
tenant_id,
connector_name,
flow: flow
.rsplit_once("::")

View File

@ -99,6 +99,7 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(
.attach_printable("Could not convert webhook effect to string")?;
let api_event = ApiEvent::new(
state.tenant.tenant_id.clone(),
Some(merchant_account.get_id().clone()),
flow,
&request_id,

View File

@ -91,6 +91,7 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(
.attach_printable("Could not convert webhook effect to string")?;
let api_event = ApiEvent::new(
state.tenant.tenant_id.clone(),
Some(merchant_account.get_id().clone()),
flow,
&request_id,

View File

@ -499,6 +499,7 @@ async fn raise_webhooks_analytics_event(
});
let webhook_event = OutgoingWebhookEvent::new(
state.tenant.tenant_id.clone(),
merchant_id,
event_id,
event.event_type,

View File

@ -24,6 +24,7 @@ use crate::{
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub struct ApiEvent {
tenant_id: common_utils::id_type::TenantId,
merchant_id: Option<common_utils::id_type::MerchantId>,
api_flow: String,
created_at_timestamp: i128,
@ -47,6 +48,7 @@ pub struct ApiEvent {
impl ApiEvent {
#[allow(clippy::too_many_arguments)]
pub fn new(
tenant_id: common_utils::id_type::TenantId,
merchant_id: Option<common_utils::id_type::MerchantId>,
api_flow: &impl FlowMetric,
request_id: &RequestId,
@ -62,6 +64,7 @@ impl ApiEvent {
http_method: &http::Method,
) -> Self {
Self {
tenant_id,
merchant_id,
api_flow: api_flow.to_string(),
created_at_timestamp: OffsetDateTime::now_utc().unix_timestamp_nanos() / 1_000_000,

View File

@ -10,6 +10,7 @@ use crate::services::kafka::KafkaMessage;
#[derive(Clone, Debug, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub struct OutgoingWebhookEvent {
tenant_id: common_utils::id_type::TenantId,
merchant_id: common_utils::id_type::MerchantId,
event_id: String,
event_type: OutgoingWebhookEventType,
@ -147,6 +148,7 @@ impl OutgoingWebhookEventMetric for OutgoingWebhookContent {
impl OutgoingWebhookEvent {
#[allow(clippy::too_many_arguments)]
pub fn new(
tenant_id: common_utils::id_type::TenantId,
merchant_id: common_utils::id_type::MerchantId,
event_id: String,
event_type: OutgoingWebhookEventType,
@ -157,6 +159,7 @@ impl OutgoingWebhookEvent {
delivery_attempt: Option<WebhookDeliveryAttempt>,
) -> Self {
Self {
tenant_id,
merchant_id,
event_id,
event_type,

View File

@ -228,6 +228,7 @@ where
})
.unwrap_or_default();
let mut connector_event = ConnectorEvent::new(
state.tenant.tenant_id.clone(),
req.connector.clone(),
std::any::type_name::<T>(),
masked_request_body,
@ -851,6 +852,7 @@ where
};
let api_event = ApiEvent::new(
tenant_id,
Some(merchant_id.clone()),
flow,
&request_id,