From 0ba514837d1ed6bee7a9c5729ad1942ef0b3573c Mon Sep 17 00:00:00 2001 From: bkotsopoulos Date: Wed, 18 Nov 2026 17:35:36 +0000 Subject: [PATCH] Measure plugin recommendation latency during initial context setup (#62326) Record how long initial context assembly waits for prompt-only plugin recommendations in `codex.initial_context.plugin_recommendations_wait_ms`. Use named info-level spans for loading recommendations, reading the tooling change marker, and fetching the recommendation catalog. GitOrigin-RevId: 67b26f79252f8cba6e770f43df252ec1d73a569f --- codex-rs/core-plugins/src/remote.rs | 12 ++++++++++-- codex-rs/core/src/session/mod.rs | 9 ++++++++- codex-rs/core/src/session/turn.rs | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/codex-rs/core-plugins/src/remote.rs b/codex-rs/core-plugins/src/remote.rs index 4359ed945d..78b64c3634 100644 --- a/codex-rs/core-plugins/src/remote.rs +++ b/codex-rs/core-plugins/src/remote.rs @@ -1160,7 +1160,11 @@ pub fn invalidate_cached_remote_plugin_catalog_scopes( } } -#[instrument(level = "trace", skip_all)] +#[instrument( + name = "plugins.recommendations.read_tooling_marker", + level = "info", + skip_all +)] pub(crate) async fn fetch_tooling_changed_at( config: &RemotePluginServiceConfig, auth: Option<&CodexAuth>, @@ -1181,7 +1185,11 @@ pub(crate) async fn fetch_tooling_changed_at( }) } -#[instrument(level = "trace", skip_all)] +#[instrument( + name = "plugins.recommendations.fetch_catalog", + level = "info", + skip_all +)] pub async fn fetch_recommended_plugins( config: &RemotePluginServiceConfig, auth: Option<&CodexAuth>, diff --git a/codex-rs/core/src/session/mod.rs b/codex-rs/core/src/session/mod.rs index b6318819f2..482505b42f 100644 --- a/codex-rs/core/src/session/mod.rs +++ b/codex-rs/core/src/session/mod.rs @@ -5284,7 +5284,14 @@ impl Session { .features .plugin_recommendations_enabled() { - match PreparedToolRecommendations::load(self, turn_context).await { + let started_at = std::time::Instant::now(); + let recommendations = PreparedToolRecommendations::load(self, turn_context).await; + turn_context.session_telemetry.record_duration( + "codex.initial_context.plugin_recommendations_wait_ms", + started_at.elapsed(), + &[], + ); + match recommendations { PreparedToolRecommendations::Endpoint(tools) => Some(tools), PreparedToolRecommendations::Legacy(_) => None, } diff --git a/codex-rs/core/src/session/turn.rs b/codex-rs/core/src/session/turn.rs index 32fc11c5c8..5e2a229286 100644 --- a/codex-rs/core/src/session/turn.rs +++ b/codex-rs/core/src/session/turn.rs @@ -2228,7 +2228,7 @@ pub(super) enum PreparedToolRecommendations { } impl PreparedToolRecommendations { - #[instrument(level = "trace", skip_all)] + #[instrument(name = "plugins.recommendations.load", level = "info", skip_all)] pub(super) async fn load(sess: &Session, turn_context: &TurnContext) -> Self { let auth = sess.services.auth_manager.auth().await; let endpoint_candidates = sess