mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 05:17:02 +08:00
feat(events): add type info to outgoing requests & maintain structural & PII type info (#2956)
Co-authored-by: Prasunna Soppa <prasunna.soppa@juspay.in>
This commit is contained in:
69
crates/router/src/events/connector_api_logs.rs
Normal file
69
crates/router/src/events/connector_api_logs.rs
Normal file
@ -0,0 +1,69 @@
|
||||
use common_utils::request::Method;
|
||||
use router_env::tracing_actix_web::RequestId;
|
||||
use serde::Serialize;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
use super::{EventType, RawEvent};
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct ConnectorEvent {
|
||||
connector_name: String,
|
||||
flow: String,
|
||||
request: String,
|
||||
response: Option<String>,
|
||||
url: String,
|
||||
method: String,
|
||||
payment_id: String,
|
||||
merchant_id: String,
|
||||
created_at: i128,
|
||||
request_id: String,
|
||||
latency: u128,
|
||||
}
|
||||
|
||||
impl ConnectorEvent {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
connector_name: String,
|
||||
flow: &str,
|
||||
request: serde_json::Value,
|
||||
response: Option<String>,
|
||||
url: String,
|
||||
method: Method,
|
||||
payment_id: String,
|
||||
merchant_id: String,
|
||||
request_id: Option<&RequestId>,
|
||||
latency: u128,
|
||||
) -> Self {
|
||||
Self {
|
||||
connector_name,
|
||||
flow: flow
|
||||
.rsplit_once("::")
|
||||
.map(|(_, s)| s)
|
||||
.unwrap_or(flow)
|
||||
.to_string(),
|
||||
request: request.to_string(),
|
||||
response,
|
||||
url,
|
||||
method: method.to_string(),
|
||||
payment_id,
|
||||
merchant_id,
|
||||
created_at: OffsetDateTime::now_utc().unix_timestamp_nanos() / 1_000_000,
|
||||
request_id: request_id
|
||||
.map(|i| i.as_hyphenated().to_string())
|
||||
.unwrap_or("NO_REQUEST_ID".to_string()),
|
||||
latency,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<ConnectorEvent> for RawEvent {
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn try_from(value: ConnectorEvent) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
event_type: EventType::ConnectorApiLogs,
|
||||
key: value.request_id.clone(),
|
||||
payload: serde_json::to_value(value)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user