[codex] add latency tracing spans (#27710)

## Why

We have some large gaps in our thread start, resume, and pre-sampling
traces that make it hard to tell where latency is coming from.

## What Changed

- Added coarse spans around thread start/resume, turn context
construction, rollout reconstruction, skill/plugin loading, and tool
preparation.
- Added a breakdown of discoverable-tool preparation across connector
loading, plugin discovery, and local plugin details.

## Testing

- `cargo check -p codex-app-server -p codex-core -p codex-core-skills -p
codex-core-plugins`
- Built the app-server locally and exercised thread start, first turn,
follow-up turn, server restart, thread resume, and a resumed turn.
This commit is contained in:
rphilizaire-openai
2026-06-12 17:11:32 -07:00
committed by GitHub
parent 1460b509f4
commit bacfc5e4c0
11 changed files with 38 additions and 0 deletions
+2
View File
@@ -18,6 +18,7 @@ use codex_tools::DiscoverableTool;
use rmcp::model::ToolAnnotations;
use serde::Deserialize;
use tokio_util::sync::CancellationToken;
use tracing::instrument;
use tracing::warn;
use crate::config::Config;
@@ -460,6 +461,7 @@ fn tool_suggest_connector_ids(
connector_ids
}
#[instrument(level = "trace", skip_all)]
async fn cached_directory_connectors_for_tool_suggest_with_auth(
config: &Config,
auth: Option<&CodexAuth>,
@@ -5,7 +5,9 @@ use codex_core_plugins::ToolSuggestPluginDiscoveryInput;
use codex_login::CodexAuth;
use codex_tools::DiscoverablePluginInfo;
use std::collections::HashSet;
use tracing::instrument;
#[instrument(level = "trace", skip_all)]
pub(crate) async fn list_tool_suggest_discoverable_plugins(
config: &Config,
plugins_manager: &PluginsManager,
+8
View File
@@ -1308,6 +1308,14 @@ impl Session {
}
}
#[instrument(
level = "trace",
skip_all,
fields(
thread_id = %self.thread_id(),
rollout_item_count = rollout_items.len()
)
)]
async fn apply_rollout_reconstruction(
&self,
turn_context: &TurnContext,
@@ -20,6 +20,7 @@ use codex_sandboxing::policy_transforms::effective_network_sandbox_policy;
use codex_utils_path_uri::PathUri;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
use tracing::instrument;
#[derive(Clone, Debug)]
pub(crate) struct TurnSkillsContext {
@@ -724,6 +725,7 @@ impl Session {
.await
}
#[instrument(name = "turn_context.build", level = "trace", skip_all)]
async fn new_turn_context_from_configuration(
&self,
sub_id: String,
+2
View File
@@ -78,6 +78,7 @@ use std::sync::atomic::Ordering;
use std::time::Duration;
use tokio::sync::RwLock;
use tokio::sync::broadcast;
use tracing::instrument;
use tracing::warn;
const THREAD_CREATED_CHANNEL_CAPACITY: usize = 1024;
@@ -702,6 +703,7 @@ impl ThreadManager {
.await
}
#[instrument(level = "trace", skip_all)]
pub async fn resume_thread_with_history(
&self,
config: Config,