mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
exec-server: align JSON-RPC span attributes
This commit is contained in:
@@ -363,6 +363,10 @@ impl RpcClient {
|
||||
})
|
||||
}
|
||||
|
||||
fn allocate_request_id(&self) -> RequestId {
|
||||
RequestId::Integer(self.next_request_id.fetch_add(1, Ordering::SeqCst))
|
||||
}
|
||||
|
||||
#[tracing::instrument(
|
||||
name = "codex.exec_server.request",
|
||||
level = "info",
|
||||
@@ -370,6 +374,9 @@ impl RpcClient {
|
||||
fields(
|
||||
otel.kind = "client",
|
||||
otel.name = method,
|
||||
rpc.system = "jsonrpc",
|
||||
rpc.method = method,
|
||||
rpc.request_id = tracing::field::Empty,
|
||||
method,
|
||||
)
|
||||
)]
|
||||
@@ -379,7 +386,10 @@ impl RpcClient {
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let _call_slot = self.acquire_regular_call_slot()?;
|
||||
self.call_inner(method, params, RpcCallTimeout::None).await
|
||||
let request_id = self.allocate_request_id();
|
||||
tracing::Span::current().record("rpc.request_id", tracing::field::display(&request_id));
|
||||
self.call_inner(request_id, method, params, RpcCallTimeout::None)
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn call_with_timeout<P, T>(
|
||||
@@ -393,8 +403,14 @@ impl RpcClient {
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let _call_slot = self.acquire_regular_call_slot()?;
|
||||
self.call_inner(method, params, RpcCallTimeout::After(call_timeout))
|
||||
.await
|
||||
let request_id = self.allocate_request_id();
|
||||
self.call_inner(
|
||||
request_id,
|
||||
method,
|
||||
params,
|
||||
RpcCallTimeout::After(call_timeout),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tracing::instrument(
|
||||
@@ -404,6 +420,9 @@ impl RpcClient {
|
||||
fields(
|
||||
otel.kind = "client",
|
||||
otel.name = method,
|
||||
rpc.system = "jsonrpc",
|
||||
rpc.method = method,
|
||||
rpc.request_id = tracing::field::Empty,
|
||||
method,
|
||||
)
|
||||
)]
|
||||
@@ -426,11 +445,15 @@ impl RpcClient {
|
||||
}
|
||||
},
|
||||
};
|
||||
self.call_inner(method, params, RpcCallTimeout::None).await
|
||||
let request_id = self.allocate_request_id();
|
||||
tracing::Span::current().record("rpc.request_id", tracing::field::display(&request_id));
|
||||
self.call_inner(request_id, method, params, RpcCallTimeout::None)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn call_inner<P, T>(
|
||||
&self,
|
||||
request_id: RequestId,
|
||||
method: &str,
|
||||
params: &P,
|
||||
call_timeout: RpcCallTimeout,
|
||||
@@ -439,7 +462,6 @@ impl RpcClient {
|
||||
P: Serialize,
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let request_id = RequestId::Integer(self.next_request_id.fetch_add(1, Ordering::SeqCst));
|
||||
let (response_tx, response_rx) = oneshot::channel();
|
||||
{
|
||||
let mut pending = self.pending.lock().await;
|
||||
|
||||
@@ -129,7 +129,7 @@ async fn run_connection(
|
||||
codex_exec_server_protocol::JSONRPCMessage::Request(request) => {
|
||||
let request_started_at = Instant::now();
|
||||
if let Some((method, route)) = router.request_route(request.method.as_str()) {
|
||||
let request_span = request_span(method, &request);
|
||||
let request_span = request_span(method, &request, transport);
|
||||
let message = tokio::select! {
|
||||
message = route(Arc::clone(&handler), request).instrument(request_span.clone()) => message,
|
||||
_ = disconnected_rx.changed() => {
|
||||
@@ -160,7 +160,7 @@ async fn run_connection(
|
||||
drop(request_span);
|
||||
} else {
|
||||
let method = "unknown";
|
||||
let request_span = request_span(method, &request);
|
||||
let request_span = request_span(method, &request, transport);
|
||||
if outgoing_tx
|
||||
.send(RpcServerOutboundMessage::Error {
|
||||
request_id: request.id,
|
||||
@@ -244,12 +244,17 @@ async fn run_connection(
|
||||
fn request_span(
|
||||
span_name: &str,
|
||||
request: &codex_exec_server_protocol::JSONRPCRequest,
|
||||
transport: ConnectionTransport,
|
||||
) -> tracing::Span {
|
||||
let method = request.method.as_str();
|
||||
let span = tracing::info_span!(
|
||||
"codex.exec_server.request",
|
||||
otel.kind = "server",
|
||||
otel.name = span_name,
|
||||
rpc.system = "jsonrpc",
|
||||
rpc.method = method,
|
||||
rpc.transport = transport.metric_tag(),
|
||||
rpc.request_id = %request.id,
|
||||
method,
|
||||
result = tracing::field::Empty,
|
||||
);
|
||||
@@ -351,7 +356,11 @@ mod tests {
|
||||
params: None,
|
||||
trace: Some(trace),
|
||||
};
|
||||
let request_span = request_span("unknown", &request);
|
||||
let request_span = request_span(
|
||||
"unknown",
|
||||
&request,
|
||||
crate::telemetry::ConnectionTransport::Stdio,
|
||||
);
|
||||
request_span.in_scope(|| {});
|
||||
drop(request_span);
|
||||
});
|
||||
|
||||
@@ -52,7 +52,7 @@ pub(crate) enum ConnectionTransport {
|
||||
}
|
||||
|
||||
impl ConnectionTransport {
|
||||
fn metric_tag(self) -> &'static str {
|
||||
pub(crate) fn metric_tag(self) -> &'static str {
|
||||
match self {
|
||||
Self::Relay => "relay",
|
||||
Self::Stdio => "stdio",
|
||||
|
||||
Reference in New Issue
Block a user