diff --git a/crates/llm_gateway/src/filter_context.rs b/crates/llm_gateway/src/filter_context.rs index 56af01b5..0edba456 100644 --- a/crates/llm_gateway/src/filter_context.rs +++ b/crates/llm_gateway/src/filter_context.rs @@ -79,6 +79,11 @@ impl RootContext for FilterContext { } fn create_http_context(&self, context_id: u32) -> Option> { + trace!( + "||| create_http_context called with context_id: {:?} |||", + context_id + ); + Some(Box::new(StreamContext::new( context_id, Rc::clone(&self.metrics), diff --git a/crates/llm_gateway/src/stream_context.rs b/crates/llm_gateway/src/stream_context.rs index 12595409..528358a3 100644 --- a/crates/llm_gateway/src/stream_context.rs +++ b/crates/llm_gateway/src/stream_context.rs @@ -176,7 +176,6 @@ impl HttpContext for StreamContext { // Envoy's HTTP model is event driven. The WASM ABI has given implementors events to hook onto // the lifecycle of the http request and response. fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { - let request_path = self.get_http_request_header(":path").unwrap_or_default(); self.select_llm_provider(); // if endpoint is not set then use provider name as routing header so envoy can resolve the cluster name @@ -308,6 +307,12 @@ impl HttpContext for StreamContext { } fn on_http_response_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + trace!( + "on_http_response_headers [S={}] end_stream={}", + self.context_id, + _end_of_stream + ); + self.set_property( vec!["metadata", "filter_metadata", "llm_filter", "user_prompt"], Some("hello world from filter".as_bytes()), @@ -317,6 +322,13 @@ impl HttpContext for StreamContext { } fn on_http_response_body(&mut self, body_size: usize, end_of_stream: bool) -> Action { + trace!( + "on_http_response_body [S={}] bytes={} end_stream={}", + self.context_id, + body_size, + end_of_stream + ); + if !self.is_chat_completions_request { debug!("non-chatcompletion request"); return Action::Continue; diff --git a/crates/prompt_gateway/src/filter_context.rs b/crates/prompt_gateway/src/filter_context.rs index b323e675..f782dea2 100644 --- a/crates/prompt_gateway/src/filter_context.rs +++ b/crates/prompt_gateway/src/filter_context.rs @@ -3,6 +3,7 @@ use crate::stream_context::StreamContext; use common::configuration::{Configuration, Overrides, PromptGuards, PromptTarget, Tracing}; use common::http::Client; use common::stats::Gauge; +use log::trace; use proxy_wasm::traits::*; use proxy_wasm::types::*; use std::cell::RefCell; @@ -83,6 +84,11 @@ impl RootContext for FilterContext { } fn create_http_context(&self, context_id: u32) -> Option> { + trace!( + "||| create_http_context called with context_id: {:?} |||", + context_id + ); + Some(Box::new(StreamContext::new( context_id, Rc::clone(&self.metrics), diff --git a/crates/prompt_gateway/src/http_context.rs b/crates/prompt_gateway/src/http_context.rs index 9b8fc0ce..e7d920f1 100644 --- a/crates/prompt_gateway/src/http_context.rs +++ b/crates/prompt_gateway/src/http_context.rs @@ -10,6 +10,7 @@ use common::{ }, errors::ServerError, http::{CallArgs, Client}, + pii::obfuscate_auth_header, }; use http::StatusCode; use log::{debug, trace, warn}; @@ -39,6 +40,12 @@ impl HttpContext for StreamContext { self.is_chat_completions_request = request_path == CHAT_COMPLETIONS_PATH; + trace!( + "on_http_request_headers S[{}] req_headers={:?}", + self.context_id, + obfuscate_auth_header(&mut self.get_http_request_headers()) + ); + self.request_id = self.get_http_request_header(REQUEST_ID_HEADER); self.traceparent = self.get_http_request_header(TRACE_PARENT_HEADER); Action::Continue @@ -78,10 +85,7 @@ impl HttpContext for StreamContext { } }; - trace!( - "request body: {}", - String::from_utf8_lossy(&body_bytes) - ); + trace!("request body: {}", String::from_utf8_lossy(&body_bytes)); // Deserialize body into spec. // Currently OpenAI API. diff --git a/crates/prompt_gateway/src/stream_context.rs b/crates/prompt_gateway/src/stream_context.rs index 178e6fcc..110db924 100644 --- a/crates/prompt_gateway/src/stream_context.rs +++ b/crates/prompt_gateway/src/stream_context.rs @@ -344,11 +344,11 @@ impl StreamContext { Duration::from_secs(5), ); - debug!("dispatching api call to developer endpoint: {}, path: {}", endpoint.name, path); - trace!( - "request body: {}", - tool_params_json_str + debug!( + "dispatching api call to developer endpoint: {}, path: {}", + endpoint.name, path ); + trace!("request body: {}", tool_params_json_str); callout_context.upstream_cluster = Some(endpoint.name.to_owned()); callout_context.upstream_cluster_path = Some(path.to_owned()); @@ -363,8 +363,8 @@ impl StreamContext { let http_status = self .get_http_call_response_header(":status") .unwrap_or(StatusCode::OK.as_str().to_string()); - debug!("api call response received: status code: {}", http_status); - if http_status != StatusCode::OK.as_str() { + debug!("api call response received: status code: {}", http_status); + if http_status != StatusCode::OK.as_str() { warn!( "api server responded with non 2xx status code: {}", http_status