Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions codex-rs/exec-server/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
22 changes: 19 additions & 3 deletions codex-rs/exec-server/src/server/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: can we instrument the whole notification dispatch here, rather than only the route future?

_ = 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;
Expand Down
Loading