mirror of
https://github.com/openai/codex.git
synced 2026-11-28 23:34:06 +00:00
feat: show runtime metrics in console (#10278)
Summary of changes:
- Adds a new feature flag: runtime_metrics
- Declared in core/src/features.rs
- Added to core/config.schema.json
- Wired into OTEL init in core/src/otel_init.rs
- Enables on-demand runtime metric snapshots in OTEL
- Adds runtime_metrics: bool to otel/src/config.rs
- Enables experimental custom reader features in otel/Cargo.toml
- Adds snapshot/reset/summary APIs in:
- otel/src/lib.rs
- otel/src/metrics/client.rs
- otel/src/metrics/config.rs
- otel/src/metrics/error.rs
- Defines metric names and a runtime summary builder
- New files:
- otel/src/metrics/names.rs
- otel/src/metrics/runtime_metrics.rs
- Summarizes totals for:
- Tool calls
- API requests
- SSE/streaming events
- Instruments metrics collection in OTEL manager
- otel/src/traces/otel_manager.rs now records:
- API call counts + durations
- SSE event counts + durations (success/failure)
- Tool call metrics now use shared constants
- Surfaces runtime metrics in the TUI
- Resets runtime metrics at turn start in tui/src/chatwidget.rs
- Displays metrics in the final separator line in
tui/src/history_cell.rs
- Adds tests
- New OTEL tests:
- otel/tests/suite/snapshot.rs
- otel/tests/suite/runtime_summary.rs
- New TUI test:
- final_message_separator_includes_runtime_metrics in
tui/src/history_cell.rs
Scope:
- 19 files changed
- ~652 insertions, 38 deletions
<img width="922" height="169" alt="Screenshot 2026-01-30 at 4 11 34 PM"
src="https://github.com/user-attachments/assets/1efd754d-a16d-4564-83a5-f4442fd2f998"
/>
This commit is contained in:
1 parent
a8c9e386e7
commit
8660ad6c64
19 files changed
+659
-38
No files matched your search
@@ -1,3 +1,9 @@
|
||||
use crate::metrics::names::API_CALL_COUNT_METRIC;
|
||||
use crate::metrics::names::API_CALL_DURATION_METRIC;
|
||||
use crate::metrics::names::SSE_EVENT_COUNT_METRIC;
|
||||
use crate::metrics::names::SSE_EVENT_DURATION_METRIC;
|
||||
use crate::metrics::names::TOOL_CALL_COUNT_METRIC;
|
||||
use crate::metrics::names::TOOL_CALL_DURATION_METRIC;
|
||||
use crate::otel_provider::traceparent_context_from_env;
|
||||
use chrono::SecondsFormat;
|
||||
use chrono::Utc;
|
||||
@@ -29,6 +35,8 @@ pub use crate::OtelEventMetadata;
|
||||
pub use crate::OtelManager;
|
||||
pub use crate::ToolDecisionSource;
|
||||
|
||||
const SSE_UNKNOWN_KIND: &str = "unknown";
|
||||
|
||||
impl OtelManager {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
@@ -148,6 +156,21 @@ impl OtelManager {
|
||||
error: Option<&str>,
|
||||
duration: Duration,
|
||||
) {
|
||||
let success = status.is_some_and(|code| (200..=299).contains(&code)) && error.is_none();
|
||||
let success_str = if success { "true" } else { "false" };
|
||||
let status_str = status
|
||||
.map(|code| code.to_string())
|
||||
.unwrap_or_else(|| "none".to_string());
|
||||
self.counter(
|
||||
API_CALL_COUNT_METRIC,
|
||||
1,
|
||||
&[("status", status_str.as_str()), ("success", success_str)],
|
||||
);
|
||||
self.record_duration(
|
||||
API_CALL_DURATION_METRIC,
|
||||
duration,
|
||||
&[("status", status_str.as_str()), ("success", success_str)],
|
||||
);
|
||||
tracing::event!(
|
||||
tracing::Level::INFO,
|
||||
event.name = "codex.api_request",
|
||||
@@ -215,6 +238,16 @@ impl OtelManager {
|
||||
}
|
||||
|
||||
fn sse_event(&self, kind: &str, duration: Duration) {
|
||||
self.counter(
|
||||
SSE_EVENT_COUNT_METRIC,
|
||||
1,
|
||||
&[("kind", kind), ("success", "true")],
|
||||
);
|
||||
self.record_duration(
|
||||
SSE_EVENT_DURATION_METRIC,
|
||||
duration,
|
||||
&[("kind", kind), ("success", "true")],
|
||||
);
|
||||
tracing::event!(
|
||||
tracing::Level::INFO,
|
||||
event.name = "codex.sse_event",
|
||||
@@ -236,6 +269,17 @@ impl OtelManager {
|
||||
where
|
||||
T: Display,
|
||||
{
|
||||
let kind_str = kind.map_or(SSE_UNKNOWN_KIND, String::as_str);
|
||||
self.counter(
|
||||
SSE_EVENT_COUNT_METRIC,
|
||||
1,
|
||||
&[("kind", kind_str), ("success", "false")],
|
||||
);
|
||||
self.record_duration(
|
||||
SSE_EVENT_DURATION_METRIC,
|
||||
duration,
|
||||
&[("kind", kind_str), ("success", "false")],
|
||||
);
|
||||
match kind {
|
||||
Some(kind) => tracing::event!(
|
||||
tracing::Level::INFO,
|
||||
@@ -443,12 +487,12 @@ impl OtelManager {
|
||||
) {
|
||||
let success_str = if success { "true" } else { "false" };
|
||||
self.counter(
|
||||
"codex.tool.call",
|
||||
TOOL_CALL_COUNT_METRIC,
|
||||
1,
|
||||
&[("tool", tool_name), ("success", success_str)],
|
||||
);
|
||||
self.record_duration(
|
||||
"codex.tool.call.duration_ms",
|
||||
TOOL_CALL_DURATION_METRIC,
|
||||
duration,
|
||||
&[("tool", tool_name), ("success", success_str)],
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user