[codex] trace MCP startup latency (#28630)

## Summary

- add trace-level instrumentation around per-server MCP setup, client
construction, initialization, and initial tool listing
- trace Codex Apps tool and server-info cache loads
- attach `server_name` to server-scoped spans so slow startup work can
be attributed to a specific MCP server

## Why

`session_init.mcp_manager_init` can occasionally be slow, but its
existing coarse span does not identify whether time is spent loading the
Codex Apps cache, constructing a client, initializing a transport, or
listing tools. These definition-level spans provide that breakdown
without changing startup behavior.

## Validation

- `just test -p codex-mcp` (87 passed)
- `just test -p codex-rmcp-client` (86 passed, 2 skipped)
This commit is contained in:
rphilizaire-openai
2026-06-23 17:46:54 -07:00
committed by GitHub
Unverified
parent 61ff4d087e
commit 322e33512b
3 changed files with 13 additions and 1 deletions
+3
View File
@@ -58,6 +58,7 @@ use tokio::sync::Mutex;
use tokio::sync::Semaphore;
use tokio::sync::watch;
use tokio::time;
use tracing::instrument;
use tracing::warn;
use crate::elicitation_client_service::ElicitationClientService;
@@ -420,6 +421,7 @@ impl RmcpClient {
/// Perform the initialization handshake with the MCP server.
/// https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle#initialization
#[instrument(level = "trace", skip_all)]
pub async fn initialize(
&self,
params: InitializeRequestParams,
@@ -501,6 +503,7 @@ impl RmcpClient {
Ok(result)
}
#[instrument(level = "trace", skip_all)]
pub async fn list_tools_with_connector_ids(
&self,
params: Option<PaginatedRequestParams>,