Trace per-step preparation for each tool contributor (#65067)

Add an info-level `tool_contributor.prepare_for_step` span so traces
show how long each contributor spends preparing before tools are built.
Label the span with the contributor's `trace_name()`, which defaults to
its concrete Rust type name, and skip recording the preparation inputs.

GitOrigin-RevId: cc644deb2d7c1a00e8eea68698516ad1c2e102da
This commit is contained in:
Tom
2026-12-01 19:34:56 +00:00
committed by copyberry
parent 4c75131c9c
commit 848d7ffbe3
2 changed files with 29 additions and 5 deletions
+24 -5
View File
@@ -1472,6 +1472,23 @@ async fn thread_title_from_thread_store(
(!title.is_empty() && thread.preview.trim() != title).then(|| title.to_string())
}
#[instrument(
name = "tool_contributor.prepare_for_step",
level = "info",
skip_all,
fields(contributor = contributor.trace_name())
)]
async fn prepare_tool_contributor_for_step(
contributor: &dyn codex_extension_api::ToolContributor,
input: codex_extension_api::StepPreparationInput<'_>,
cancellation_token: &CancellationToken,
) -> Result<(), codex_async_utils::CancelErr> {
contributor
.prepare_for_step(input)
.or_cancel(cancellation_token)
.await
}
impl Session {
pub(crate) async fn app_server_client_metadata(&self) -> AppServerClientMetadata {
let state = self.state.lock().await;
@@ -4908,8 +4925,9 @@ impl Session {
})
.collect::<Vec<_>>();
for contributor in self.services.extensions.tool_contributors() {
contributor
.prepare_for_step(codex_extension_api::StepPreparationInput {
prepare_tool_contributor_for_step(
contributor.as_ref(),
codex_extension_api::StepPreparationInput {
turn_id: &turn_context.sub_id,
ready_selected_capability_roots: &accessed_roots,
executor_capability_discovery: skill_discovery,
@@ -4919,9 +4937,10 @@ impl Session {
thread_store: &self.services.thread_extension_data,
turn_store: turn_context.extension_data.as_ref(),
step_store: &extension_data,
})
.or_cancel(cancellation_token)
.await?;
},
cancellation_token,
)
.await?;
}
drop(catalogs);
extension_data.insert(selected_plugins);
@@ -416,6 +416,11 @@ pub struct StepPreparationInput<'a> {
/// Extension contribution that exposes native tools owned by a feature.
pub trait ToolContributor: Send + Sync {
/// Identifies the concrete contributor in traces, without any per-instance data.
fn trace_name(&self) -> &'static str {
std::any::type_name::<Self>()
}
/// Prepares step state once, before tools are built and without rendering.
/// Never publish partial state; discovery failures may report warnings.
fn prepare_for_step<'a>(&'a self, _input: StepPreparationInput<'a>) -> ExtensionFuture<'a, ()> {