Add client-side exec-server RPC attempt metrics (#42883)

## What changed

- Record `exec_server_client_requests_total` for every client RPC call attempt,
  labeled by protocol method.
- Count attempts before local admission so rejected, timed-out, cancelled, and
  transport-failed calls are included, while notifications and responses are not.
- Export the counter to configured OpenTelemetry collectors while excluding it
  from the built-in Statsig metrics set.

## Testing

- Cover every RPC call entry point, successful responses, local and transport
  failures, timeouts, cancellation, notifications, and disabled metrics.
- Verify that the OTLP HTTP exporter retains the counter.

GitOrigin-RevId: d266e840d5871aa2c34bed8ce44f3345e2b4650f
This commit is contained in:
bkotsopoulos authored and copyberry committed 2026-09-04 23:06:00 +00:00
1 parent a97cf1b72e
commit 574a36ff99
8 files changed
+310

No files matched your search

@@ -1,3 +1,4 @@
use codex_otel::EXEC_SERVER_CLIENT_REQUEST_COUNT_METRIC;
use codex_otel::MetricsClient;
use codex_otel::MetricsConfig;
use codex_otel::OtelExporter;
@@ -187,6 +188,12 @@ fn otlp_http_exporter_sends_metrics_to_collector() -> Result<()> {
metrics.counter("codex.turns", /*inc*/ 1, &[("source", "test")])?;
metrics.counter("codex.api_request", /*inc*/ 1, &[("status", "200")])?;
metrics.counter_with_description(
EXEC_SERVER_CLIENT_REQUEST_COUNT_METRIC,
"Client-side exec-server RPC attempts.",
/*inc*/ 1,
&[("method", "fs/readFile")],
)?;
metrics.record_duration(
"codex.api_request.duration_ms",
Duration::from_millis(100),
@@ -259,6 +266,10 @@ fn otlp_http_exporter_sends_metrics_to_collector() -> Result<()> {
"expected API-request counter not found; body prefix: {}",
&body.chars().take(2000).collect::<String>()
);
assert!(
body.contains(EXEC_SERVER_CLIENT_REQUEST_COUNT_METRIC),
"custom OTLP must retain the exec-server client counter excluded from built-in Statsig"
);
assert!(
body.contains("\"codex.api_request.duration_ms\""),
"expected API-request duration not found; body prefix: {}",