mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 17:47:54 +08:00
feat(events): add request details to api events (#2769)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
use actix_web::HttpRequest;
|
||||
use router_env::{tracing_actix_web::RequestId, types::FlowMetric};
|
||||
use serde::Serialize;
|
||||
use time::OffsetDateTime;
|
||||
@ -15,10 +16,14 @@ pub struct ApiEvent {
|
||||
#[serde(flatten)]
|
||||
auth_type: AuthenticationType,
|
||||
request: serde_json::Value,
|
||||
user_agent: Option<String>,
|
||||
ip_addr: Option<String>,
|
||||
url_path: String,
|
||||
response: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
impl ApiEvent {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
api_flow: &impl FlowMetric,
|
||||
request_id: &RequestId,
|
||||
@ -27,6 +32,7 @@ impl ApiEvent {
|
||||
request: serde_json::Value,
|
||||
response: Option<serde_json::Value>,
|
||||
auth_type: AuthenticationType,
|
||||
http_req: &HttpRequest,
|
||||
) -> Self {
|
||||
Self {
|
||||
api_flow: api_flow.to_string(),
|
||||
@ -37,6 +43,15 @@ impl ApiEvent {
|
||||
request,
|
||||
response,
|
||||
auth_type,
|
||||
ip_addr: http_req
|
||||
.connection_info()
|
||||
.realip_remote_addr()
|
||||
.map(ToOwned::to_owned),
|
||||
user_agent: http_req
|
||||
.headers()
|
||||
.get("user-agent")
|
||||
.and_then(|user_agent_value| user_agent_value.to_str().ok().map(ToOwned::to_owned)),
|
||||
url_path: http_req.path().to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -852,6 +852,7 @@ where
|
||||
serialized_request,
|
||||
serialized_response,
|
||||
auth_type,
|
||||
request,
|
||||
);
|
||||
match api_event.clone().try_into() {
|
||||
Ok(event) => {
|
||||
|
||||
Reference in New Issue
Block a user