Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Prevent recursive Tokio tracing in telemetry and SQLite logs (#51775)

zbarsky-openai9dd798805fdf
diff --git a/codex-rs/core/src/session/mod.rs b/codex-rs/core/src/session/mod.rs
index 32aa2edd1a..3a1c0ae4f6 100644
--- a/codex-rs/core/src/session/mod.rs
+++ b/codex-rs/core/src/session/mod.rs
@@ -969,14 +969,14 @@ impl Session {
.as_ref()
.and_then(|startup| startup.session_teardown(thread_id));
let session_for_loop = Arc::clone(&session);
- let session_loop_handle = tokio::spawn(storage_originator.scope(async move {
+ let session_loop_handle = tokio::spawn(Box::pin(storage_originator.scope(async move {
submission_loop(session_for_loop, configured_config, rx_sub)
.instrument(info_span!("session_loop", thread_id = %thread_id))
.await;
if let Some(tree_teardown) = tree_teardown {
tree_teardown.complete();
}
- }));
+ })));
let io = SessionIo {
tx_sub,
rx_event,
diff --git a/codex-rs/core/src/session/tests.rs b/codex-rs/core/src/session/tests.rs
index 496114a113..24df4cdcd2 100644
--- a/codex-rs/core/src/session/tests.rs
+++ b/codex-rs/core/src/session/tests.rs
@@ -10065,8 +10065,8 @@ async fn capability_roots_require_turn_environment_selection() {
);
}
-#[tokio::test]
#[tracing_test::traced_test]
+#[tokio::test]
async fn conflicting_ready_environment_root_ids_keep_first_location() {
let (session, turn_context) = make_session_and_context().await;
let selected_root =
diff --git a/codex-rs/ext/skills/tests/skills_extension.rs b/codex-rs/ext/skills/tests/skills_extension.rs
index 53def3ddea..e03d694b18 100644
--- a/codex-rs/ext/skills/tests/skills_extension.rs
+++ b/codex-rs/ext/skills/tests/skills_extension.rs
@@ -1509,10 +1509,15 @@ async fn overlapping_executor_catalogs_render_their_own_roots() -> TestResult {
// the refresh callsite as globally disabled before this subscriber reaches it.
let _interest_cache_guard =
tracing::Dispatch::new(tracing::subscriber::NoSubscriber::default());
- let subscriber = tracing_subscriber::registry().with(PauseAfterRefresh {
- entered: Mutex::new(Some(entered)),
- resume: Mutex::new(resume),
- });
+ let subscriber = tracing_subscriber::registry().with(
+ PauseAfterRefresh {
+ entered: Mutex::new(Some(entered)),
+ resume: Mutex::new(resume),
+ }
+ .with_filter(tracing_subscriber::filter::filter_fn(|metadata| {
+ metadata.name() == "skills.executor.refresh_executor_catalog"
+ })),
+ );
let a = tokio::spawn(render(root_a).with_subscriber(subscriber));
tokio::time::timeout(std::time::Duration::from_secs(/*secs*/ 10), paused).await??;
let b = render(root_b).await;
diff --git a/codex-rs/otel/src/provider.rs b/codex-rs/otel/src/provider.rs
index 0b2aeb58cd..24b118a8a9 100644
--- a/codex-rs/otel/src/provider.rs
+++ b/codex-rs/otel/src/provider.rs
@@ -341,9 +341,9 @@ impl OtelProvider {
pub fn trace_export_filter(meta: &tracing::Metadata<'_>) -> bool {
let target = meta.target();
if meta.is_span() {
- // h2 creates explicit-root spans that escape the SDK's telemetry suppression.
- // Exporting them would make OTLP transport generate more OTLP exports.
- target != "h2" && !target.starts_with("h2::")
+ // The exporter uses h2 and Tokio. Their root spans escape the
+ // SDK's suppression and would generate further OTLP exports.
+ !matches!(target.split("::").next(), Some("h2" | "tokio" | "runtime"))
} else {
is_trace_safe_target(target)
}
diff --git a/codex-rs/rmcp-client/src/enterprise_oauth_login_tests.rs b/codex-rs/rmcp-client/src/enterprise_oauth_login_tests.rs
index 7434dfe3c4..78b383e307 100644
--- a/codex-rs/rmcp-client/src/enterprise_oauth_login_tests.rs
+++ b/codex-rs/rmcp-client/src/enterprise_oauth_login_tests.rs
@@ -132,8 +132,8 @@ async fn callback(authorization_url: &str, issuer: &str, provider_error: bool) -
Ok(())
}
-#[tokio::test]
#[traced_test]
+#[tokio::test]
async fn enterprise_callback_errors_and_sdk_logs_exclude_credentials() -> Result<()> {
if isolated_process(
"enterprise_oauth_login::tests::enterprise_callback_errors_and_sdk_logs_exclude_credentials",
@@ -227,8 +227,8 @@ fn enterprise_callback_requires_loopback() -> Result<()> {
Ok(())
}
-#[tokio::test]
#[traced_test]
+#[tokio::test]
async fn enterprise_public_api_storage_and_privacy() -> Result<()> {
if isolated_process("enterprise_oauth_login::tests::enterprise_public_api_storage_and_privacy")
.await?
diff --git a/codex-rs/rmcp-client/src/oauth/ema_identity_tests.rs b/codex-rs/rmcp-client/src/oauth/ema_identity_tests.rs
index b146cc2733..59b52a1695 100644
--- a/codex-rs/rmcp-client/src/oauth/ema_identity_tests.rs
+++ b/codex-rs/rmcp-client/src/oauth/ema_identity_tests.rs
@@ -278,8 +278,8 @@ async fn keyring_failure_does_not_reuse_the_pinned_refresh_token() -> Result<()>
Ok(())
}
-#[tokio::test]
#[traced_test]
+#[tokio::test]
async fn enterprise_credential_errors_and_keyring_traces_hide_account_key() -> Result<()> {
let home = TempCodexHome::new();
let sentinel = "private-workspace-sentinel";
diff --git a/codex-rs/rmcp-client/src/user_verification_cancellation_tests.rs b/codex-rs/rmcp-client/src/user_verification_cancellation_tests.rs
index 2fc8a2f146..986457f947 100644
--- a/codex-rs/rmcp-client/src/user_verification_cancellation_tests.rs
+++ b/codex-rs/rmcp-client/src/user_verification_cancellation_tests.rs
@@ -59,8 +59,8 @@ impl InProcessTransportFactory for ElicitationTestTransport {
}
}
-#[tokio::test]
#[traced_test]
+#[tokio::test]
async fn recovered_connections_accept_elicitations_with_previously_cancelled_ids()
-> anyhow::Result<()> {
for params in [
diff --git a/codex-rs/state/src/log_db.rs b/codex-rs/state/src/log_db.rs
index 6b4cc42c43..ef03ad8573 100644
--- a/codex-rs/state/src/log_db.rs
+++ b/codex-rs/state/src/log_db.rs
@@ -74,6 +74,8 @@ pub fn default_filter() -> Targets {
.with_target("codex_otel.log_only", LevelFilter::OFF)
.with_target("codex_otel.trace_safe", LevelFilter::OFF)
.with_target("rmcp", LevelFilter::INFO)
+ .with_target("tokio::", LevelFilter::INFO)
+ .with_target("runtime::", LevelFilter::INFO)
.with_target("tokio_graceful::guard", LevelFilter::DEBUG)
.with_target("tokio_graceful::trigger", LevelFilter::DEBUG)
.with_target("codex_api::responses_websocket_timing", LevelFilter::OFF)
@@ -286,6 +288,14 @@ where
return;
}
+ // Channel sends and timer polls from this sink must not enqueue more
+ // SQLite writes when Tokio runtime tracing is enabled.
+ if *metadata.level() == tracing::Level::TRACE
+ && matches!(target.split("::").next(), Some("tokio" | "runtime"))
+ {
+ return;
+ }
+
// `tracing-log` checks filters with the original log target before
// dispatching an event whose tracing target is `log`, so the outer
// target filter cannot reliably reject these bridged events.
@@ -738,13 +748,9 @@ mod tests {
.with_writer(writer.clone())
.with_ansi(false)
.with_target(false)
- .with_filter(Targets::new().with_default(tracing::Level::TRACE)),
+ .with_filter(default_filter()),
)
- .with(
- layer
- .clone()
- .with_filter(Targets::new().with_default(tracing::Level::TRACE)),
- );
+ .with(layer.clone().with_filter(default_filter()));
let guard = subscriber.set_default();
tracing::trace!("threadless-before");