From 5ac640ac49ae5c8b781d51bbaf0467c98cda2643 Mon Sep 17 00:00:00 2001 From: mchen-oai Date: Tue, 9 Jun 2026 17:49:59 -0700 Subject: [PATCH] Add spans to build_tool_router (#27094) ## Why - Local profiling shows `append_tool_search_executor` averages ~113ms per call. Adding a span lets us track this cost as we optimize in follow-up PRs, either by reducing the work or avoiding repeated rebuilds when inputs have not changed. - While we're here, we can add spans to `build_tool_router` and other sub-calls which code analysis shows may have additional opportunities for improvement. ## What changed Add function-level trace spans around `build_tool_router`, `build_tool_specs_and_registry`, `add_tool_sources`, `append_tool_search_executor`, and `build_model_visible_specs_and_registry` ## Verification Trigger Codex rollout and observe new spans are included --- codex-rs/core/src/tools/spec_plan.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/codex-rs/core/src/tools/spec_plan.rs b/codex-rs/core/src/tools/spec_plan.rs index fed62a0ee..19f4c9f89 100644 --- a/codex-rs/core/src/tools/spec_plan.rs +++ b/codex-rs/core/src/tools/spec_plan.rs @@ -86,6 +86,7 @@ use codex_tools::shell_type_for_model_and_features; use std::collections::BTreeMap; use std::collections::HashSet; use std::sync::Arc; +use tracing::instrument; use tracing::warn; const MULTI_AGENT_V2_NAMESPACE_DESCRIPTION: &str = "Tools for spawning and managing sub-agents."; @@ -148,6 +149,7 @@ struct CoreToolPlanContext<'a> { wait_agent_timeouts: WaitAgentTimeoutOptions, } +#[instrument(level = "trace", skip_all)] pub(crate) fn build_tool_router( turn_context: &TurnContext, params: ToolRouterParams<'_>, @@ -156,6 +158,7 @@ pub(crate) fn build_tool_router( ToolRouter::from_parts(registry, model_visible_specs) } +#[instrument(level = "trace", skip_all)] fn build_tool_specs_and_registry( turn_context: &TurnContext, params: ToolRouterParams<'_>, @@ -186,6 +189,7 @@ fn build_tool_specs_and_registry( build_model_visible_specs_and_registry(turn_context, planned_tools) } +#[instrument(level = "trace", skip_all)] fn build_model_visible_specs_and_registry( turn_context: &TurnContext, planned_tools: PlannedTools, @@ -557,6 +561,7 @@ fn code_mode_namespace_descriptions( namespace_descriptions } +#[instrument(level = "trace", skip_all)] fn add_tool_sources(context: &CoreToolPlanContext<'_>, planned_tools: &mut PlannedTools) { add_shell_tools(context, planned_tools); add_mcp_resource_tools(context, planned_tools); @@ -837,6 +842,7 @@ fn add_extension_tools(context: &CoreToolPlanContext<'_>, planned_tools: &mut Pl ); } +#[instrument(level = "trace", skip_all)] fn append_tool_search_executor( context: &CoreToolPlanContext<'_>, planned_tools: &mut PlannedTools,