From 830eee94e1d35dcd14ef9989eb7b6003c1244a18 Mon Sep 17 00:00:00 2001 From: Sampras Lopes Date: Sat, 21 Oct 2023 17:21:21 +0530 Subject: [PATCH] feat(events): Add request body to api events logger (#2660) --- crates/router/src/events.rs | 9 +++++---- crates/router/src/events/api_logs.rs | 6 ++++++ crates/router/src/services/api.rs | 10 +++++++++- crates/storage_impl/src/payments/payment_attempt.rs | 1 - 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/crates/router/src/events.rs b/crates/router/src/events.rs index 88d7ff6684..39a8543a68 100644 --- a/crates/router/src/events.rs +++ b/crates/router/src/events.rs @@ -9,13 +9,14 @@ pub trait EventHandler: Sync + Send + dyn_clone::DynClone { dyn_clone::clone_trait_object!(EventHandler); +#[derive(Debug)] pub struct RawEvent { - event_type: EventType, - key: String, - payload: serde_json::Value, + pub event_type: EventType, + pub key: String, + pub payload: serde_json::Value, } -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, Clone, Copy)] #[serde(rename_all = "snake_case")] pub enum EventType { PaymentIntent, diff --git a/crates/router/src/events/api_logs.rs b/crates/router/src/events/api_logs.rs index 784d80b278..ee6676b9e4 100644 --- a/crates/router/src/events/api_logs.rs +++ b/crates/router/src/events/api_logs.rs @@ -11,6 +11,8 @@ pub struct ApiEvent { request_id: String, latency: u128, status_code: i64, + request: String, + response: String, } impl ApiEvent { @@ -19,6 +21,8 @@ impl ApiEvent { request_id: &RequestId, latency: u128, status_code: i64, + request: String, + response: String, ) -> Self { Self { api_flow: api_flow.to_string(), @@ -26,6 +30,8 @@ impl ApiEvent { request_id: request_id.as_hyphenated().to_string(), latency, status_code, + request, + response, } } } diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index b2cb29bbd2..b21eff3e7a 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -793,6 +793,7 @@ where tracing::Span::current().record("merchant_id", &merchant_id); + let req_message = format!("{:?}", payload); let output = { lock_action .clone() @@ -816,7 +817,14 @@ where Ok(res) => metrics::request::track_response_status_code(res), Err(err) => err.current_context().status_code().as_u16().into(), }; - let api_event = ApiEvent::new(flow, &request_id, request_duration, status_code); + let api_event = ApiEvent::new( + flow, + &request_id, + request_duration, + status_code, + req_message, + format!("{:?}", output), + ); match api_event.clone().try_into() { Ok(event) => { state.event_handler().log_event(event); diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index 386c673b36..751796bd1d 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -360,7 +360,6 @@ impl PaymentAttemptInterface for KVRouterStore { multiple_capture_count: payment_attempt.multiple_capture_count, connector_response_reference_id: None, amount_capturable: payment_attempt.amount_capturable, - updated_by: storage_scheme.to_string(), };