[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
parent 243243ab8f
commit 38211a3ff8
8 changed files with 48 additions and 0 deletions
@@ -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.