Skip to content

Commit a4be4d7

Browse files
authored
Log more types of request IDs (#5645)
Different services return different sets of IDs, log all of them to simplify debugging.
1 parent 00c1de0 commit a4be4d7

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

codex-rs/core/src/auth.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ impl PartialEq for CodexAuth {
4444

4545
impl CodexAuth {
4646
pub async fn refresh_token(&self) -> Result<String, std::io::Error> {
47+
tracing::info!("Refreshing token");
48+
4749
let token_data = self
4850
.get_current_token_data()
4951
.ok_or(std::io::Error::other("Token data is not available."))?;
@@ -917,7 +919,10 @@ impl AuthManager {
917919
self.reload();
918920
Ok(Some(token))
919921
}
920-
Err(e) => Err(e),
922+
Err(e) => {
923+
tracing::error!("Failed to refresh token: {}", e);
924+
Err(e)
925+
}
921926
}
922927
}
923928

codex-rs/core/src/client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ impl ModelClient {
301301
"POST to {}: {:?}",
302302
self.provider.get_full_url(&auth),
303303
serde_json::to_string(payload_json)
304+
.unwrap_or("<unable to serialize payload>".to_string())
304305
);
305306

306307
let mut req_builder = self

codex-rs/core/src/default_client.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use reqwest::Response;
66
use reqwest::header::HeaderName;
77
use reqwest::header::HeaderValue;
88
use serde::Serialize;
9+
use std::collections::HashMap;
910
use std::fmt::Display;
1011
use std::sync::LazyLock;
1112
use std::sync::Mutex;
@@ -115,20 +116,13 @@ impl CodexRequestBuilder {
115116
pub async fn send(self) -> Result<Response, reqwest::Error> {
116117
match self.builder.send().await {
117118
Ok(response) => {
118-
let request_id = response
119-
.headers()
120-
.get("cf-ray")
121-
.map(|v| v.to_str().unwrap_or_default().to_string())
122-
.unwrap_or_default();
123-
124-
let version = format!("{:?}", response.version());
125-
119+
let request_ids = Self::extract_request_ids(&response);
126120
tracing::debug!(
127121
method = %self.method,
128122
url = %self.url,
129123
status = %response.status(),
130-
request_id = %request_id,
131-
version = %version,
124+
request_ids = ?request_ids,
125+
version = ?response.version(),
132126
"Request completed"
133127
);
134128

@@ -147,6 +141,18 @@ impl CodexRequestBuilder {
147141
}
148142
}
149143
}
144+
145+
fn extract_request_ids(response: &Response) -> HashMap<String, String> {
146+
["cf-ray", "x-request-id", "x-oai-request-id"]
147+
.iter()
148+
.filter_map(|&name| {
149+
let header_name = HeaderName::from_static(name);
150+
let value = response.headers().get(header_name)?;
151+
let value = value.to_str().ok()?.to_owned();
152+
Some((name.to_owned(), value))
153+
})
154+
.collect()
155+
}
150156
}
151157
#[derive(Debug, Clone)]
152158
pub struct Originator {

codex-rs/feedback/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use anyhow::anyhow;
1212
use codex_protocol::ConversationId;
1313
use tracing_subscriber::fmt::writer::MakeWriter;
1414

15-
const DEFAULT_MAX_BYTES: usize = 2 * 1024 * 1024; // 2 MiB
15+
const DEFAULT_MAX_BYTES: usize = 4 * 1024 * 1024; // 4 MiB
1616
const SENTRY_DSN: &str =
1717
"https://[email protected]/4510195390611458";
1818
const UPLOAD_TIMEOUT_SECS: u64 = 10;

0 commit comments

Comments
 (0)