feat(events): Add request body to api events logger (#2660)

This commit is contained in:
Sampras Lopes
2023-10-21 17:21:21 +05:30
committed by GitHub
parent 31431e4135
commit 830eee94e1
4 changed files with 20 additions and 6 deletions

View File

@ -9,13 +9,14 @@ pub trait EventHandler: Sync + Send + dyn_clone::DynClone {
dyn_clone::clone_trait_object!(EventHandler); dyn_clone::clone_trait_object!(EventHandler);
#[derive(Debug)]
pub struct RawEvent { pub struct RawEvent {
event_type: EventType, pub event_type: EventType,
key: String, pub key: String,
payload: serde_json::Value, pub payload: serde_json::Value,
} }
#[derive(Debug, Serialize)] #[derive(Debug, Serialize, Clone, Copy)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum EventType { pub enum EventType {
PaymentIntent, PaymentIntent,

View File

@ -11,6 +11,8 @@ pub struct ApiEvent {
request_id: String, request_id: String,
latency: u128, latency: u128,
status_code: i64, status_code: i64,
request: String,
response: String,
} }
impl ApiEvent { impl ApiEvent {
@ -19,6 +21,8 @@ impl ApiEvent {
request_id: &RequestId, request_id: &RequestId,
latency: u128, latency: u128,
status_code: i64, status_code: i64,
request: String,
response: String,
) -> Self { ) -> Self {
Self { Self {
api_flow: api_flow.to_string(), api_flow: api_flow.to_string(),
@ -26,6 +30,8 @@ impl ApiEvent {
request_id: request_id.as_hyphenated().to_string(), request_id: request_id.as_hyphenated().to_string(),
latency, latency,
status_code, status_code,
request,
response,
} }
} }
} }

View File

@ -793,6 +793,7 @@ where
tracing::Span::current().record("merchant_id", &merchant_id); tracing::Span::current().record("merchant_id", &merchant_id);
let req_message = format!("{:?}", payload);
let output = { let output = {
lock_action lock_action
.clone() .clone()
@ -816,7 +817,14 @@ where
Ok(res) => metrics::request::track_response_status_code(res), Ok(res) => metrics::request::track_response_status_code(res),
Err(err) => err.current_context().status_code().as_u16().into(), 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() { match api_event.clone().try_into() {
Ok(event) => { Ok(event) => {
state.event_handler().log_event(event); state.event_handler().log_event(event);

View File

@ -360,7 +360,6 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
multiple_capture_count: payment_attempt.multiple_capture_count, multiple_capture_count: payment_attempt.multiple_capture_count,
connector_response_reference_id: None, connector_response_reference_id: None,
amount_capturable: payment_attempt.amount_capturable, amount_capturable: payment_attempt.amount_capturable,
updated_by: storage_scheme.to_string(), updated_by: storage_scheme.to_string(),
}; };