From d6807abba46136eabadcbfbc51bce421144dca2c Mon Sep 17 00:00:00 2001 From: harsh-sharma-juspay <125131007+harsh-sharma-juspay@users.noreply.github.com> Date: Tue, 30 Jan 2024 12:43:56 +0530 Subject: [PATCH] chore(analytics): adding status code to connector Kafka events (#3393) Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Sampras lopes --- crates/router/src/events/connector_api_logs.rs | 3 +++ crates/router/src/services/api.rs | 9 ++++++++- 2 files changed, 11 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 bc8ab2e05e78..e0c6a0862579 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -372,7 +372,13 @@ 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.as_ref() + .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 +400,7 @@ where req.merchant_id.clone(), state.request_id.as_ref(), external_latency, + status_code, ); match connector_event.try_into() {