exec-server: trace RPC notifications

This commit is contained in:
Adam Perry
2026-07-09 23:59:59 +00:00
parent 139da70355
commit e8558f0466
2 changed files with 26 additions and 5 deletions
+7 -2
View File
@@ -233,8 +233,13 @@ where
.map(|(&method, route)| (method, route))
}
pub(crate) fn notification_route(&self, method: &str) -> Option<&NotificationRoute<S>> {
self.notification_routes.get(method)
pub(crate) fn notification_route(
&self,
method: &str,
) -> Option<(&'static str, &NotificationRoute<S>)> {
self.notification_routes
.get_key_value(method)
.map(|(&method, route)| (method, route))
}
}
+19 -3
View File
@@ -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;