From e8558f04668161b6430a5a4899d64d1e2779c55a Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Thu, 9 Jul 2026 01:42:26 +0000 Subject: [PATCH] exec-server: trace RPC notifications --- codex-rs/exec-server/src/rpc.rs | 9 ++++++-- codex-rs/exec-server/src/server/processor.rs | 22 +++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/codex-rs/exec-server/src/rpc.rs b/codex-rs/exec-server/src/rpc.rs index bde4e48f00..671c2a2f8d 100644 --- a/codex-rs/exec-server/src/rpc.rs +++ b/codex-rs/exec-server/src/rpc.rs @@ -233,8 +233,13 @@ where .map(|(&method, route)| (method, route)) } - pub(crate) fn notification_route(&self, method: &str) -> Option<&NotificationRoute> { - self.notification_routes.get(method) + pub(crate) fn notification_route( + &self, + method: &str, + ) -> Option<(&'static str, &NotificationRoute)> { + self.notification_routes + .get_key_value(method) + .map(|(&method, route)| (method, route)) } } diff --git a/codex-rs/exec-server/src/server/processor.rs b/codex-rs/exec-server/src/server/processor.rs index 15343754c9..fb91a673d1 100644 --- a/codex-rs/exec-server/src/server/processor.rs +++ b/codex-rs/exec-server/src/server/processor.rs @@ -185,23 +185,39 @@ async fn run_connection( } } codex_exec_server_protocol::JSONRPCMessage::Notification(notification) => { - let Some(route) = router.notification_route(notification.method.as_str()) - else { + let method = notification.method.as_str(); + let notification_span = tracing::info_span!( + "codex.exec_server.notification", + otel.kind = "server", + otel.name = tracing::field::Empty, + rpc.system = "jsonrpc", + rpc.method = method, + rpc.transport = transport.metric_tag(), + method, + result = tracing::field::Empty, + ); + let Some((method, route)) = router.notification_route(method) else { + notification_span.record("otel.name", "unknown"); + notification_span.record("result", "error"); warn!( "closing exec-server connection after unexpected notification: {}", notification.method ); break; }; + notification_span.record("otel.name", method); let result = tokio::select! { - result = route(Arc::clone(&handler), notification) => result, + result = route(Arc::clone(&handler), notification).instrument(notification_span.clone()) => result, _ = disconnected_rx.changed() => { + notification_span.record("result", "disconnected"); debug!( "exec-server transport disconnected while handling notification" ); break; } }; + notification_span + .record("result", if result.is_ok() { "success" } else { "error" }); if let Err(err) = result { warn!("closing exec-server connection after protocol error: {err}"); break;