mirror of
https://github.com/openai/codex.git
synced 2026-10-19 16:17:49 +00:00
Keep API request metrics out of Statsig exports (#36840)
## What changed - Treat `codex.api_request` and `codex.api_request.duration_ms` as runtime-only metrics for Statsig exporters, matching the existing tool-call metric behavior. - Keep both metrics available through other OTLP exporters. ## Testing - Extend the Statsig filtering test to cover both API request metrics. - Verify the OTLP HTTP exporter still sends the API request count and duration. GitOrigin-RevId: f0f800ade7979e4da72ae59641bf42aa8a3ebd5a
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use crate::config::OtelExporter;
|
||||
use crate::metrics::Result;
|
||||
use crate::metrics::names::API_CALL_COUNT_METRIC;
|
||||
use crate::metrics::names::API_CALL_DURATION_METRIC;
|
||||
use crate::metrics::names::TOOL_CALL_COUNT_METRIC;
|
||||
use crate::metrics::names::TOOL_CALL_DURATION_METRIC;
|
||||
use crate::metrics::validation::validate_tag_key;
|
||||
@@ -8,7 +10,12 @@ use opentelemetry_sdk::metrics::InMemoryMetricExporter;
|
||||
use std::collections::BTreeMap;
|
||||
use std::time::Duration;
|
||||
|
||||
const RUNTIME_ONLY_METRICS: &[&str] = &[TOOL_CALL_COUNT_METRIC, TOOL_CALL_DURATION_METRIC];
|
||||
const RUNTIME_ONLY_METRICS: &[&str] = &[
|
||||
API_CALL_COUNT_METRIC,
|
||||
API_CALL_DURATION_METRIC,
|
||||
TOOL_CALL_COUNT_METRIC,
|
||||
TOOL_CALL_DURATION_METRIC,
|
||||
];
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum MetricsExporter {
|
||||
|
||||
@@ -462,6 +462,8 @@ mod shutdown_tests;
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::metrics::API_CALL_COUNT_METRIC;
|
||||
use crate::metrics::API_CALL_DURATION_METRIC;
|
||||
use crate::metrics::MetricsExporter;
|
||||
use crate::metrics::TOOL_CALL_COUNT_METRIC;
|
||||
use crate::metrics::TOOL_CALL_DURATION_METRIC;
|
||||
@@ -544,6 +546,8 @@ mod tests {
|
||||
config.exporter = MetricsExporter::InMemory(exporter.clone());
|
||||
let metrics = MetricsClient::new(config)?;
|
||||
|
||||
metrics.counter(API_CALL_COUNT_METRIC, /*inc*/ 1, &[])?;
|
||||
metrics.record_duration(API_CALL_DURATION_METRIC, Duration::from_millis(100), &[])?;
|
||||
metrics.counter(TOOL_CALL_COUNT_METRIC, /*inc*/ 1, &[])?;
|
||||
metrics.record_duration(TOOL_CALL_DURATION_METRIC, Duration::from_millis(25), &[])?;
|
||||
metrics.counter("codex.turns", /*inc*/ 1, &[])?;
|
||||
|
||||
@@ -186,6 +186,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.record_duration(
|
||||
"codex.api_request.duration_ms",
|
||||
Duration::from_millis(100),
|
||||
&[("status", "200")],
|
||||
)?;
|
||||
metrics.counter("codex.tool.call", /*inc*/ 1, &[("tool", "test")])?;
|
||||
metrics.record_duration(
|
||||
"codex.tool.call.duration_ms",
|
||||
@@ -227,6 +233,16 @@ fn otlp_http_exporter_sends_metrics_to_collector() -> Result<()> {
|
||||
"expected gauge not found; body prefix: {}",
|
||||
&body.chars().take(2000).collect::<String>()
|
||||
);
|
||||
assert!(
|
||||
body.contains("\"codex.api_request\""),
|
||||
"expected API-request counter not found; body prefix: {}",
|
||||
&body.chars().take(2000).collect::<String>()
|
||||
);
|
||||
assert!(
|
||||
body.contains("\"codex.api_request.duration_ms\""),
|
||||
"expected API-request duration not found; body prefix: {}",
|
||||
&body.chars().take(2000).collect::<String>()
|
||||
);
|
||||
assert!(
|
||||
body.contains("\"codex.tool.call\""),
|
||||
"expected tool-call counter not found; body prefix: {}",
|
||||
|
||||
Reference in New Issue
Block a user