-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(events): add event generation for connector api calls
- Loading branch information
Showing
8 changed files
with
148 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
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: String, | ||
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, | ||
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)?, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters