[codex] trace tools build latency (#28782)

Add more tracing spans around tool building.
This commit is contained in:
Owen Lin
2026-06-17 14:53:54 -07:00
committed by GitHub
Unverified
parent 243243ab8f
commit 38211a3ff8
8 changed files with 48 additions and 0 deletions
+9
View File
@@ -942,6 +942,14 @@ impl PluginsManager {
Ok(featured_plugin_ids)
}
#[instrument(
level = "trace",
skip_all,
fields(
plugins_enabled = config.plugins_enabled,
remote_plugin_enabled = config.remote_plugin_enabled
)
)]
pub async fn recommended_plugins_mode_for_config(
&self,
config: &PluginsConfigInput,
@@ -1014,6 +1022,7 @@ impl PluginsManager {
/// Returns endpoint recommendations eligible for installation in the current client.
/// `None` selects the legacy discovery workflow.
#[instrument(level = "trace", skip_all)]
pub async fn recommended_plugin_candidates_for_config(
&self,
input: RecommendedPluginCandidatesInput<'_>,
+2
View File
@@ -27,6 +27,7 @@ use std::fs;
use std::path::Path;
use std::path::PathBuf;
use std::time::Duration;
use tracing::instrument;
use url::Url;
mod catalog_cache;
@@ -805,6 +806,7 @@ pub async fn fetch_and_cache_global_remote_plugin_catalog(
Ok(())
}
#[instrument(level = "trace", skip_all)]
pub async fn fetch_recommended_plugins(
config: &RemotePluginServiceConfig,
auth: Option<&CodexAuth>,
+1
View File
@@ -94,6 +94,7 @@ pub(crate) async fn list_accessible_and_enabled_connectors_from_manager(
.collect()
}
#[instrument(level = "trace", skip_all)]
pub(crate) async fn list_tool_suggest_discoverable_tools_with_auth(
config: &Config,
plugins_manager: &PluginsManager,
@@ -20,6 +20,7 @@ use codex_tools::ToolSpec;
use codex_tools::coalesce_loadable_tool_specs;
use std::sync::Arc;
use std::sync::Mutex;
use tracing::instrument;
pub struct ToolSearchHandler {
search_infos: Vec<ToolSearchInfo>,
@@ -33,6 +34,7 @@ pub(crate) struct ToolSearchHandlerCache {
}
impl ToolSearchHandlerCache {
#[instrument(level = "trace", skip_all, fields(search_info_count = search_infos.len()))]
pub(crate) fn get_or_build(&self, search_infos: Vec<ToolSearchInfo>) -> Arc<ToolSearchHandler> {
{
let cached = self.cached();
@@ -64,6 +66,11 @@ impl ToolSearchHandlerCache {
}
impl ToolSearchHandler {
#[instrument(
level = "trace",
skip_all,
fields(search_info_count = search_infos.len())
)]
pub(crate) fn new(search_infos: Vec<ToolSearchInfo>) -> Self {
let search_source_infos = search_infos
.iter()
+2
View File
@@ -34,6 +34,7 @@ use codex_tools::ToolSearchInfo;
use codex_tools::ToolSpec;
use futures::future::BoxFuture;
use serde_json::Value;
use tracing::instrument;
pub(crate) type ToolTelemetryTags = Vec<(&'static str, String)>;
@@ -327,6 +328,7 @@ impl ToolRegistry {
Self { tools }
}
#[instrument(level = "trace", skip_all)]
pub(crate) fn from_tools(tools: impl IntoIterator<Item = Arc<dyn CoreToolRuntime>>) -> Self {
let mut tools_by_name = HashMap::new();
for tool in tools {
+1
View File
@@ -240,6 +240,7 @@ impl ToolRouter {
}
}
#[instrument(level = "trace", skip_all)]
pub(crate) fn extension_tool_executors(
session: &Session,
) -> Vec<Arc<dyn ToolExecutor<ExtensionToolCall>>> {
+24
View File
@@ -256,6 +256,7 @@ fn spec_for_model_request(
}
}
#[instrument(level = "trace", skip_all)]
fn hosted_model_tool_specs(context: &CoreToolPlanContext<'_>) -> Vec<ToolSpec> {
let turn_context = context.turn_context;
// Responses Lite accepts schemas for client-executed tools, not hosted Responses tools.
@@ -500,6 +501,7 @@ fn build_code_mode_executors(
]
}
#[instrument(level = "trace", skip_all, fields(tool_spec_count = specs.len()))]
fn merge_into_namespaces(specs: Vec<ToolSpec>) -> Vec<ToolSpec> {
let mut merged_specs = Vec::with_capacity(specs.len());
let mut namespace_indices = BTreeMap::<String, usize>::new();
@@ -592,6 +594,7 @@ fn standalone_web_search_enabled(turn_context: &TurnContext) -> bool {
.enabled(Feature::StandaloneWebSearch))
}
#[instrument(level = "trace", skip_all)]
fn add_shell_tools(context: &CoreToolPlanContext<'_>, planned_tools: &mut PlannedTools) {
let turn_context = context.turn_context;
let features = turn_context.config.features.get();
@@ -643,6 +646,7 @@ fn unified_exec_should_include_shell_parameter(turn_context: &TurnContext) -> bo
.any(|environment| environment.environment.is_remote())
}
#[instrument(level = "trace", skip_all)]
fn add_mcp_resource_tools(context: &CoreToolPlanContext<'_>, planned_tools: &mut PlannedTools) {
if context.mcp_tools.is_some() {
planned_tools.add(ListMcpResourcesHandler);
@@ -651,6 +655,7 @@ fn add_mcp_resource_tools(context: &CoreToolPlanContext<'_>, planned_tools: &mut
}
}
#[instrument(level = "trace", skip_all)]
fn add_core_utility_tools(context: &CoreToolPlanContext<'_>, planned_tools: &mut PlannedTools) {
let turn_context = context.turn_context;
let features = turn_context.config.features.get();
@@ -722,6 +727,7 @@ fn add_core_utility_tools(context: &CoreToolPlanContext<'_>, planned_tools: &mut
}
}
#[instrument(level = "trace", skip_all)]
fn add_collaboration_tools(context: &CoreToolPlanContext<'_>, planned_tools: &mut PlannedTools) {
let turn_context = context.turn_context;
if collab_tools_enabled(turn_context) {
@@ -810,6 +816,14 @@ fn add_collaboration_tools(context: &CoreToolPlanContext<'_>, planned_tools: &mu
}
}
#[instrument(
level = "trace",
skip_all,
fields(
direct_mcp_tool_count = context.mcp_tools.map_or(0, <[ToolInfo]>::len),
deferred_mcp_tool_count = context.deferred_mcp_tools.map_or(0, <[ToolInfo]>::len)
)
)]
fn add_mcp_runtime_tools(context: &CoreToolPlanContext<'_>, planned_tools: &mut PlannedTools) {
if let Some(mcp_tools) = context.mcp_tools {
for tool in mcp_tools {
@@ -836,6 +850,11 @@ fn add_mcp_runtime_tools(context: &CoreToolPlanContext<'_>, planned_tools: &mut
}
}
#[instrument(
level = "trace",
skip_all,
fields(dynamic_tool_count = context.dynamic_tools.len())
)]
fn add_dynamic_tools(context: &CoreToolPlanContext<'_>, planned_tools: &mut PlannedTools) {
for spec in context.dynamic_tools {
match spec {
@@ -868,6 +887,11 @@ fn add_dynamic_tools(context: &CoreToolPlanContext<'_>, planned_tools: &mut Plan
}
}
#[instrument(
level = "trace",
skip_all,
fields(extension_tool_executor_count = context.extension_tool_executors.len())
)]
fn add_extension_tools(context: &CoreToolPlanContext<'_>, planned_tools: &mut PlannedTools) {
// Extension ToolContributor implementations are resolved into executors
// before planning. Core only adapts those executors into its runtime set.
+2
View File
@@ -17,6 +17,7 @@ use std::sync::atomic::AtomicU64;
use std::sync::atomic::Ordering;
use tokio::sync::Semaphore;
use tokio::sync::watch;
use tracing::instrument;
use codex_agent_identity::ChatGptEnvironment;
use codex_agent_identity::decode_agent_identity_jwt;
@@ -1719,6 +1720,7 @@ impl AuthManager {
/// Current cached auth (clone). May be `None` if not logged in or load failed.
/// For managed ChatGPT auth that needs a proactive refresh, first performs
/// a guarded reload and then refreshes only if the on-disk auth is unchanged.
#[instrument(level = "trace", skip_all)]
pub async fn auth(&self) -> Option<CodexAuth> {
if let Some(auth) = self.resolve_external_api_key_auth().await {
return Some(auth);