mirror of
https://github.com/openai/codex.git
synced 2026-11-05 20:10:33 +00:00
Separate HTTP execution from request logging (#34476)
## What changed - Add an execution path that injects trace headers and sends a request without logging its result. - Extract response and error logging into reusable helpers while preserving the existing behavior of `HttpClient::execute`. GitOrigin-RevId: 3feebe3da041dd08f5033dd319233d8afe9054ec
This commit is contained in:
@@ -69,40 +69,55 @@ impl HttpClient {
|
||||
|
||||
pub(crate) async fn execute(
|
||||
&self,
|
||||
mut request: reqwest::Request,
|
||||
request: reqwest::Request,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
request.headers_mut().extend(trace_headers());
|
||||
let method = request.method().clone();
|
||||
let url = request.url().to_string();
|
||||
|
||||
match self.inner.execute(request).await {
|
||||
match self.execute_without_request_logging(request).await {
|
||||
Ok(response) => {
|
||||
if self.request_logging == RequestLogging::Enabled {
|
||||
tracing::debug!(
|
||||
method = %method,
|
||||
url = %url,
|
||||
status = %response.status(),
|
||||
headers = ?response.headers(),
|
||||
version = ?response.version(),
|
||||
"Request completed"
|
||||
);
|
||||
}
|
||||
self.log_response(&method, &url, &response);
|
||||
Ok(response)
|
||||
}
|
||||
Err(error) => {
|
||||
if self.request_logging == RequestLogging::Enabled {
|
||||
tracing::debug!(
|
||||
method = %method,
|
||||
url = %url,
|
||||
status = error.status().map(|status| status.as_u16()),
|
||||
error = %error,
|
||||
"Request failed"
|
||||
);
|
||||
}
|
||||
self.log_error(&method, &url, &error);
|
||||
Err(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn execute_without_request_logging(
|
||||
&self,
|
||||
mut request: reqwest::Request,
|
||||
) -> Result<reqwest::Response, reqwest::Error> {
|
||||
request.headers_mut().extend(trace_headers());
|
||||
self.inner.execute(request).await
|
||||
}
|
||||
|
||||
pub(crate) fn log_response(&self, method: &Method, url: &str, response: &reqwest::Response) {
|
||||
if self.request_logging == RequestLogging::Enabled {
|
||||
tracing::debug!(
|
||||
method = %method,
|
||||
url = %url,
|
||||
status = %response.status(),
|
||||
headers = ?response.headers(),
|
||||
version = ?response.version(),
|
||||
"Request completed"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn log_error(&self, method: &Method, url: &str, error: &reqwest::Error) {
|
||||
if self.request_logging == RequestLogging::Enabled {
|
||||
tracing::debug!(
|
||||
method = %method,
|
||||
url = %url,
|
||||
status = error.status().map(|status| status.as_u16()),
|
||||
error = %error,
|
||||
"Request failed"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
|
||||
Reference in New Issue
Block a user