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);
#[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,

View File

@ -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,
}
}
}

View File

@ -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);

View File

@ -360,7 +360,6 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
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(),
};