Skip to content

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

feat(events): add request details to api events (#2769)

Sampras Lopes164d1c66fbcb
diff --git a/crates/router/src/events/api_logs.rs b/crates/router/src/events/api_logs.rs
index 35eaf1edae..5a66ba3e0b 100644
--- a/crates/router/src/events/api_logs.rs
+++ b/crates/router/src/events/api_logs.rs
@@ -1,3 +1,4 @@
+use actix_web::HttpRequest;
use router_env::{tracing_actix_web::RequestId, types::FlowMetric};
use serde::Serialize;
use time::OffsetDateTime;
@@ -15,10 +16,14 @@ pub struct ApiEvent {
#[serde(flatten)]
auth_type: AuthenticationType,
request: serde_json::Value,
+ user_agent: Option<String>,
+ ip_addr: Option<String>,
+ url_path: String,
response: Option<serde_json::Value>,
}
impl ApiEvent {
+ #[allow(clippy::too_many_arguments)]
pub fn new(
api_flow: &impl FlowMetric,
request_id: &RequestId,
@@ -27,6 +32,7 @@ impl ApiEvent {
request: serde_json::Value,
response: Option<serde_json::Value>,
auth_type: AuthenticationType,
+ http_req: &HttpRequest,
) -> Self {
Self {
api_flow: api_flow.to_string(),
@@ -37,6 +43,15 @@ impl ApiEvent {
request,
response,
auth_type,
+ ip_addr: http_req
+ .connection_info()
+ .realip_remote_addr()
+ .map(ToOwned::to_owned),
+ user_agent: http_req
+ .headers()
+ .get("user-agent")
+ .and_then(|user_agent_value| user_agent_value.to_str().ok().map(ToOwned::to_owned)),
+ url_path: http_req.path().to_string(),
}
}
}
diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs
index c942f09f96..3626449069 100644
--- a/crates/router/src/services/api.rs
+++ b/crates/router/src/services/api.rs
@@ -852,6 +852,7 @@ where
serialized_request,
serialized_response,
auth_type,
+ request,
);
match api_event.clone().try_into() {
Ok(event) => {