mirror of
https://github.com/openai/codex.git
synced 2026-11-13 14:46:14 +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:
1 parent
1836ae0612
commit
9e5625d9cf
1 file changed
+37
-22
@@ -69,40 +69,55 @@ impl HttpClient {
|
|||||||
|
|
||||||
pub(crate) async fn execute(
|
pub(crate) async fn execute(
|
||||||
&self,
|
&self,
|
||||||
mut request: reqwest::Request,
|
request: reqwest::Request,
|
||||||
) -> Result<reqwest::Response, reqwest::Error> {
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
request.headers_mut().extend(trace_headers());
|
|
||||||
let method = request.method().clone();
|
let method = request.method().clone();
|
||||||
let url = request.url().to_string();
|
let url = request.url().to_string();
|
||||||
|
|
||||||
match self.inner.execute(request).await {
|
match self.execute_without_request_logging(request).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
if self.request_logging == RequestLogging::Enabled {
|
self.log_response(&method, &url, &response);
|
||||||
tracing::debug!(
|
|
||||||
method = %method,
|
|
||||||
url = %url,
|
|
||||||
status = %response.status(),
|
|
||||||
headers = ?response.headers(),
|
|
||||||
version = ?response.version(),
|
|
||||||
"Request completed"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Ok(response)
|
Ok(response)
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
if self.request_logging == RequestLogging::Enabled {
|
self.log_error(&method, &url, &error);
|
||||||
tracing::debug!(
|
|
||||||
method = %method,
|
|
||||||
url = %url,
|
|
||||||
status = error.status().map(|status| status.as_u16()),
|
|
||||||
error = %error,
|
|
||||||
"Request failed"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Err(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)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
|||||||
Reference in new issue
Block a user