diff --git a/litellm-rust/crates/core/src/logging/events.rs b/litellm-rust/crates/core/src/logging/events.rs index 0830cd7077b..88cc7d8d645 100644 --- a/litellm-rust/crates/core/src/logging/events.rs +++ b/litellm-rust/crates/core/src/logging/events.rs @@ -21,8 +21,6 @@ pub enum LogEvent { } pub struct RequestEventInput { - pub call_id: String, - pub provider: String, pub model: String, pub stream: bool, pub url: String, @@ -114,12 +112,16 @@ pub struct ProviderErrorEvent { pub body: Option, } -pub(crate) fn request_event(input: RequestEventInput) -> LogEvent { +pub(crate) fn request_event( + call_id: String, + provider: String, + input: RequestEventInput, +) -> LogEvent { let snapshot = snapshot_json(input.body); LogEvent::Request(ProviderRequestEvent { source: "litellm-rust", - call_id: input.call_id, - provider: input.provider, + call_id, + provider, model: input.model, stream: input.stream, method: "POST", @@ -221,15 +223,17 @@ mod tests { #[test] fn redacts_credentials_recursively() { - let event = request_event(RequestEventInput { - call_id: "call_01".to_string(), - provider: "anthropic".to_string(), - model: "claude".to_string(), - stream: false, - url: "https://example.test?signature=secret&x=ok".to_string(), - headers: vec![("Authorization".to_string(), "Bearer secret".to_string())], - body: serde_json::json!({"nested": {"token": "secret"}, "prompt": "visible"}), - }); + let event = request_event( + "call_01".to_string(), + "anthropic".to_string(), + RequestEventInput { + model: "claude".to_string(), + stream: false, + url: "https://example.test?signature=secret&x=ok".to_string(), + headers: vec![("Authorization".to_string(), "Bearer secret".to_string())], + body: serde_json::json!({"nested": {"token": "secret"}, "prompt": "visible"}), + }, + ); let json = serde_json::to_string(&event).expect("serializes"); assert!(!json.contains("secret")); assert!(json.contains("visible")); diff --git a/litellm-rust/crates/core/src/logging/http.rs b/litellm-rust/crates/core/src/logging/http.rs index 196e40b8e2f..028be43a1a9 100644 --- a/litellm-rust/crates/core/src/logging/http.rs +++ b/litellm-rust/crates/core/src/logging/http.rs @@ -28,8 +28,6 @@ pub async fn execute_json( request .logger .request_about_to_be_sent(super::RequestEventInput { - call_id: request.logger.call_id().to_string(), - provider: request.logger.provider().to_string(), model: request.model, stream: request.stream, url: request.url.clone(), @@ -105,20 +103,9 @@ pub async fn execute_json( CoreError::InvalidResponse(format!("invalid provider response JSON: {error}")) })?; let typed = T::deserialize(&value); - let response_body = if media_type - .as_deref() - .is_some_and(|value| value.to_ascii_lowercase().contains("json")) - { - ResponseBody::Json(value) - } else { - ResponseBody::Binary { - media_type, - bytes: text.len(), - } - }; request .logger - .response_received(status.as_u16(), headers, response_body); + .response_received(status.as_u16(), headers, ResponseBody::Json(value)); let typed = typed.map_err(|error| { request.logger.failure( Some(status.as_u16()), @@ -140,8 +127,6 @@ pub async fn execute_stream( request .logger .request_about_to_be_sent(super::RequestEventInput { - call_id: request.logger.call_id().to_string(), - provider: request.logger.provider().to_string(), model: request.model, stream: true, url: request.url.clone(), diff --git a/litellm-rust/crates/core/src/logging/mod.rs b/litellm-rust/crates/core/src/logging/mod.rs index 5e4b3f3e2e0..1525b606eff 100644 --- a/litellm-rust/crates/core/src/logging/mod.rs +++ b/litellm-rust/crates/core/src/logging/mod.rs @@ -35,18 +35,12 @@ impl CallLogger { } } - pub(crate) fn call_id(&self) -> &str { - &self.context.litellm_call_id - } - - pub(crate) fn provider(&self) -> &str { - &self.context.custom_llm_provider - } - - pub fn request_about_to_be_sent(&self, mut input: events::RequestEventInput) { - input.call_id = self.context.litellm_call_id.clone(); - input.provider = self.context.custom_llm_provider.clone(); - self.emit(events::request_event(input)); + pub fn request_about_to_be_sent(&self, input: events::RequestEventInput) { + self.emit(events::request_event( + self.context.litellm_call_id.clone(), + self.context.custom_llm_provider.clone(), + input, + )); } pub fn response_received( @@ -143,8 +137,6 @@ mod tests { let context = CallLifecycleContext::new("messages", "claude", "anthropic", "req_123"); let logger = CallLogger::new(&context, Some(Arc::new(sink.clone()))); logger.request_about_to_be_sent(events::RequestEventInput { - call_id: String::new(), - provider: String::new(), model: "claude".to_string(), stream: false, url: "https://example.test/v1/messages".to_string(),