From a46f4daa6435f2455c34932ccb6ea60eaf5980e8 Mon Sep 17 00:00:00 2001 From: harsh_sharma_juspay Date: Thu, 18 Jan 2024 23:07:05 +0530 Subject: [PATCH 1/3] chore(analytics): adding status code to connector events --- crates/router/src/events/connector_api_logs.rs | 3 +++ crates/router/src/services/api.rs | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/router/src/events/connector_api_logs.rs b/crates/router/src/events/connector_api_logs.rs index 871a7af0d772..45c05a3077fd 100644 --- a/crates/router/src/events/connector_api_logs.rs +++ b/crates/router/src/events/connector_api_logs.rs @@ -18,6 +18,7 @@ pub struct ConnectorEvent { created_at: i128, request_id: String, latency: u128, + status_code: u16, } impl ConnectorEvent { @@ -33,6 +34,7 @@ impl ConnectorEvent { merchant_id: String, request_id: Option<&RequestId>, latency: u128, + status_code: u16, ) -> Self { Self { connector_name, @@ -52,6 +54,7 @@ impl ConnectorEvent { .map(|i| i.as_hyphenated().to_string()) .unwrap_or("NO_REQUEST_ID".to_string()), latency, + status_code, } } } diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index ad463fcf2b92..19d13dbe1613 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -372,7 +372,12 @@ where let response = call_connector_api(state, request).await; let external_latency = current_time.elapsed().as_millis(); logger::debug!(connector_response=?response); - + let status_code = response + .as_ref() + .map(|i| { + i.clone().map_or_else(|value| value.status_code, |value| value.status_code) + }) + .unwrap_or_default(); let connector_event = ConnectorEvent::new( req.connector.clone(), std::any::type_name::(), @@ -394,6 +399,7 @@ where req.merchant_id.clone(), state.request_id.as_ref(), external_latency, + status_code, ); match connector_event.try_into() { From 699b2563df678e1c5f5028f80b487f9ab6a5fa02 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 18 Jan 2024 17:38:31 +0000 Subject: [PATCH 2/3] chore: run formatter --- crates/router/src/services/api.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index 19d13dbe1613..2e8f8d968cad 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -375,7 +375,8 @@ where let status_code = response .as_ref() .map(|i| { - i.clone().map_or_else(|value| value.status_code, |value| value.status_code) + i.clone() + .map_or_else(|value| value.status_code, |value| value.status_code) }) .unwrap_or_default(); let connector_event = ConnectorEvent::new( From f4ee4ed6a1046ca3f7cb74025e37d26d66c2a734 Mon Sep 17 00:00:00 2001 From: Sampras lopes Date: Mon, 22 Jan 2024 14:32:35 +0530 Subject: [PATCH 3/3] chore(lints): fix redundant clone --- crates/router/src/services/api.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index 2e8f8d968cad..6e1ef0b3719d 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -375,7 +375,7 @@ where let status_code = response .as_ref() .map(|i| { - i.clone() + i.as_ref() .map_or_else(|value| value.status_code, |value| value.status_code) }) .unwrap_or_default();