Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

feat: timer total turn metrics (#9382)

jif-oai7ebe13f69223
diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs
index c6e11b1376..e677794386 100644
--- a/codex-rs/core/src/codex.rs
+++ b/codex-rs/core/src/codex.rs
@@ -525,7 +525,6 @@ impl Session {
session_configuration.collaboration_mode.model(),
model_info.slug.as_str(),
);
-
let per_turn_config = Arc::new(per_turn_config);
let client = ModelClient::new(
per_turn_config.clone(),
diff --git a/codex-rs/core/src/state/turn.rs b/codex-rs/core/src/state/turn.rs
index ddc9efafea..3dfc5132d3 100644
--- a/codex-rs/core/src/state/turn.rs
+++ b/codex-rs/core/src/state/turn.rs
@@ -37,7 +37,6 @@ pub(crate) enum TaskKind {
Compact,
}
-#[derive(Clone)]
pub(crate) struct RunningTask {
pub(crate) done: Arc<Notify>,
pub(crate) kind: TaskKind,
@@ -45,6 +44,8 @@ pub(crate) struct RunningTask {
pub(crate) cancellation_token: CancellationToken,
pub(crate) handle: Arc<AbortOnDropHandle<()>>,
pub(crate) turn_context: Arc<TurnContext>,
+ // Timer recorded when the task drops to capture the full turn duration.
+ pub(crate) _timer: Option<codex_otel::Timer>,
}
impl ActiveTurn {
diff --git a/codex-rs/core/src/tasks/mod.rs b/codex-rs/core/src/tasks/mod.rs
index d6754c23c8..83326b1f05 100644
--- a/codex-rs/core/src/tasks/mod.rs
+++ b/codex-rs/core/src/tasks/mod.rs
@@ -144,6 +144,12 @@ impl Session {
})
};
+ let timer = turn_context
+ .client
+ .get_otel_manager()
+ .start_timer("codex.turn.e2e_duration_ms", &[])
+ .ok();
+
let running_task = RunningTask {
done,
handle: Arc::new(AbortOnDropHandle::new(handle)),
@@ -151,6 +157,7 @@ impl Session {
task,
cancellation_token,
turn_context: Arc::clone(&turn_context),
+ _timer: timer,
};
self.register_new_active_task(running_task).await;
}
diff --git a/codex-rs/otel/src/lib.rs b/codex-rs/otel/src/lib.rs
index 868a977735..fa7cc93bb7 100644
--- a/codex-rs/otel/src/lib.rs
+++ b/codex-rs/otel/src/lib.rs
@@ -9,7 +9,7 @@ use crate::metrics::MetricsClient;
use crate::metrics::MetricsConfig;
use crate::metrics::MetricsError;
use crate::metrics::Result as MetricsResult;
-use crate::metrics::timer::Timer;
+pub use crate::metrics::timer::Timer;
use crate::metrics::validation::validate_tag_key;
use crate::metrics::validation::validate_tag_value;
use crate::otel_provider::OtelProvider;
diff --git a/codex-rs/otel/src/metrics/timer.rs b/codex-rs/otel/src/metrics/timer.rs
index b1624fda16..6c85f413b3 100644
--- a/codex-rs/otel/src/metrics/timer.rs
+++ b/codex-rs/otel/src/metrics/timer.rs
@@ -2,6 +2,7 @@ use crate::metrics::MetricsClient;
use crate::metrics::error::Result;
use std::time::Instant;
+#[derive(Debug)]
pub struct Timer {
name: String,
tags: Vec<(String, String)>,