mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
feat(apievent): added hs latency to api event (#2734)
Co-authored-by: Sampras lopes <lsampras@pm.me>
This commit is contained in:
committed by
GitHub
parent
8e538dbd5c
commit
c124511052
@ -38,6 +38,7 @@ pub struct ApiEvent {
|
|||||||
response: Option<serde_json::Value>,
|
response: Option<serde_json::Value>,
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
event_type: ApiEventsType,
|
event_type: ApiEventsType,
|
||||||
|
hs_latency: Option<u128>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApiEvent {
|
impl ApiEvent {
|
||||||
@ -49,6 +50,7 @@ impl ApiEvent {
|
|||||||
status_code: i64,
|
status_code: i64,
|
||||||
request: serde_json::Value,
|
request: serde_json::Value,
|
||||||
response: Option<serde_json::Value>,
|
response: Option<serde_json::Value>,
|
||||||
|
hs_latency: Option<u128>,
|
||||||
auth_type: AuthenticationType,
|
auth_type: AuthenticationType,
|
||||||
event_type: ApiEventsType,
|
event_type: ApiEventsType,
|
||||||
http_req: &HttpRequest,
|
http_req: &HttpRequest,
|
||||||
@ -72,6 +74,7 @@ impl ApiEvent {
|
|||||||
.and_then(|user_agent_value| user_agent_value.to_str().ok().map(ToOwned::to_owned)),
|
.and_then(|user_agent_value| user_agent_value.to_str().ok().map(ToOwned::to_owned)),
|
||||||
url_path: http_req.path().to_string(),
|
url_path: http_req.path().to_string(),
|
||||||
event_type,
|
event_type,
|
||||||
|
hs_latency,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -830,6 +830,7 @@ where
|
|||||||
.as_millis();
|
.as_millis();
|
||||||
|
|
||||||
let mut serialized_response = None;
|
let mut serialized_response = None;
|
||||||
|
let mut overhead_latency = None;
|
||||||
let status_code = match output.as_ref() {
|
let status_code = match output.as_ref() {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
if let ApplicationResponse::Json(data) = res {
|
if let ApplicationResponse::Json(data) = res {
|
||||||
@ -839,6 +840,19 @@ where
|
|||||||
.attach_printable("Failed to serialize json response")
|
.attach_printable("Failed to serialize json response")
|
||||||
.change_context(errors::ApiErrorResponse::InternalServerError.switch())?,
|
.change_context(errors::ApiErrorResponse::InternalServerError.switch())?,
|
||||||
);
|
);
|
||||||
|
} else if let ApplicationResponse::JsonWithHeaders((data, headers)) = res {
|
||||||
|
serialized_response.replace(
|
||||||
|
masking::masked_serialize(&data)
|
||||||
|
.into_report()
|
||||||
|
.attach_printable("Failed to serialize json response")
|
||||||
|
.change_context(errors::ApiErrorResponse::InternalServerError.switch())?,
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Some((_, value)) = headers.iter().find(|(key, _)| key == X_HS_LATENCY) {
|
||||||
|
if let Ok(external_latency) = value.parse::<u128>() {
|
||||||
|
overhead_latency.replace(external_latency);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
event_type = res.get_api_event_type().or(event_type);
|
event_type = res.get_api_event_type().or(event_type);
|
||||||
|
|
||||||
@ -854,6 +868,7 @@ where
|
|||||||
status_code,
|
status_code,
|
||||||
serialized_request,
|
serialized_request,
|
||||||
serialized_response,
|
serialized_response,
|
||||||
|
overhead_latency,
|
||||||
auth_type,
|
auth_type,
|
||||||
event_type.unwrap_or(ApiEventsType::Miscellaneous),
|
event_type.unwrap_or(ApiEventsType::Miscellaneous),
|
||||||
request,
|
request,
|
||||||
|
|||||||
Reference in New Issue
Block a user