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
+23
-8
@@ -69,14 +69,32 @@ 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) => {
|
||||||
|
self.log_response(&method, &url, &response);
|
||||||
|
Ok(response)
|
||||||
|
}
|
||||||
|
Err(error) => {
|
||||||
|
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 {
|
if self.request_logging == RequestLogging::Enabled {
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
method = %method,
|
method = %method,
|
||||||
@@ -87,9 +105,9 @@ impl HttpClient {
|
|||||||
"Request completed"
|
"Request completed"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Ok(response)
|
|
||||||
}
|
}
|
||||||
Err(error) => {
|
|
||||||
|
pub(crate) fn log_error(&self, method: &Method, url: &str, error: &reqwest::Error) {
|
||||||
if self.request_logging == RequestLogging::Enabled {
|
if self.request_logging == RequestLogging::Enabled {
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
method = %method,
|
method = %method,
|
||||||
@@ -99,9 +117,6 @@ impl HttpClient {
|
|||||||
"Request failed"
|
"Request failed"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user