fix(analytics): added response to the connector outgoing event (#3129)

Co-authored-by: harsh-sharma-juspay <125131007+harsh-sharma-juspay@users.noreply.github.com>
Co-authored-by: Sampras lopes <lsampras@pm.me>
This commit is contained in:
Sagar naik
2024-01-05 18:58:55 +05:30
committed by GitHub
parent 00008c16c1
commit d152c3a1ca
8 changed files with 145 additions and 149 deletions

View File

@ -116,7 +116,6 @@ impl_misc_api_event_type!(
AttachEvidenceRequest,
DisputeId,
PaymentLinkFormData,
PaymentsRedirectResponseData,
ConfigUpdate
);
@ -131,3 +130,15 @@ impl_misc_api_event_type!(
DummyConnectorRefundResponse,
DummyConnectorRefundRequest
);
impl ApiEventMetric for PaymentsRedirectResponseData {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::PaymentRedirectionResponse {
connector: self.connector.clone(),
payment_id: match &self.resource_id {
api_models::payments::PaymentIdType::PaymentIntentId(id) => Some(id.clone()),
_ => None,
},
})
}
}

View File

@ -377,7 +377,17 @@ where
req.connector.clone(),
std::any::type_name::<T>(),
masked_request_body,
None,
response
.as_ref()
.map(|response| {
response
.as_ref()
.map_or_else(|value| value, |value| value)
.response
.escape_ascii()
.to_string()
})
.ok(),
request_url,
request_method,
req.payment_id.clone(),

View File

@ -8,12 +8,9 @@ use rdkafka::{
};
use crate::events::EventType;
mod api_event;
pub mod outgoing_request;
mod payment_attempt;
mod payment_intent;
mod refund;
pub use api_event::{ApiCallEventType, ApiEvents, ApiEventsType};
use data_models::payments::{payment_attempt::PaymentAttempt, PaymentIntent};
use diesel_models::refund::Refund;
use serde::Serialize;
@ -300,11 +297,6 @@ impl KafkaProducer {
})
}
pub async fn log_api_event(&self, event: &ApiEvents) -> MQResult<()> {
self.log_kafka_event(&self.api_logs_topic, event)
.attach_printable_lazy(|| format!("Failed to add api log event {event:?}"))
}
pub fn get_topic(&self, event: EventType) -> &str {
match event {
EventType::ApiLogs => &self.api_logs_topic,

View File

@ -1,108 +0,0 @@
use api_models::enums as api_enums;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(tag = "flow_type")]
pub enum ApiEventsType {
Payment {
payment_id: String,
},
Refund {
payment_id: String,
refund_id: String,
},
Default,
PaymentMethod {
payment_method_id: String,
payment_method: Option<api_enums::PaymentMethod>,
payment_method_type: Option<api_enums::PaymentMethodType>,
},
Customer {
customer_id: String,
},
User {
//specified merchant_id will overridden on global defined
merchant_id: String,
user_id: String,
},
Webhooks {
connector: String,
payment_id: Option<String>,
},
OutgoingEvent,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct ApiEvents {
pub api_name: String,
pub request_id: Option<String>,
//It is require to solve ambiquity in case of event_type is User
#[serde(skip_serializing_if = "Option::is_none")]
pub merchant_id: Option<String>,
pub request: String,
pub response: String,
pub status_code: u16,
#[serde(with = "time::serde::timestamp")]
pub created_at: OffsetDateTime,
pub latency: u128,
//conflicting fields underlying enums will be used
#[serde(flatten)]
pub event_type: ApiEventsType,
pub user_agent: Option<String>,
pub ip_addr: Option<String>,
pub url_path: Option<String>,
pub api_event_type: Option<ApiCallEventType>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub enum ApiCallEventType {
IncomingApiEvent,
OutgoingApiEvent,
}
impl super::KafkaMessage for ApiEvents {
fn key(&self) -> String {
match &self.event_type {
ApiEventsType::Payment { payment_id } => format!(
"{}_{}",
self.merchant_id
.as_ref()
.unwrap_or(&"default_merchant_id".to_string()),
payment_id
),
ApiEventsType::Refund {
payment_id,
refund_id,
} => format!("{payment_id}_{refund_id}"),
ApiEventsType::Default => "key".to_string(),
ApiEventsType::PaymentMethod {
payment_method_id,
payment_method,
payment_method_type,
} => format!(
"{:?}_{:?}_{:?}",
payment_method_id.clone(),
payment_method.clone(),
payment_method_type.clone(),
),
ApiEventsType::Customer { customer_id } => customer_id.to_string(),
ApiEventsType::User {
merchant_id,
user_id,
} => format!("{}_{}", merchant_id, user_id),
ApiEventsType::Webhooks {
connector,
payment_id,
} => format!(
"webhook_{}_{connector}",
payment_id.clone().unwrap_or_default()
),
ApiEventsType::OutgoingEvent => "outgoing_event".to_string(),
}
}
fn creation_timestamp(&self) -> Option<i64> {
Some(self.created_at.unix_timestamp())
}
}

View File

@ -1,19 +0,0 @@
use reqwest::Url;
pub struct OutgoingRequest {
pub url: Url,
pub latency: u128,
}
// impl super::KafkaMessage for OutgoingRequest {
// fn key(&self) -> String {
// format!(
// "{}_{}",
// )
// }
// fn creation_timestamp(&self) -> Option<i64> {
// Some(self.created_at.unix_timestamp())
// }
// }