mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	feat(events): Add request body to api events logger (#2660)
This commit is contained in:
		| @ -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, | ||||
|  | ||||
| @ -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, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -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); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Sampras Lopes
					Sampras Lopes