mirror of
https://github.com/openai/codex.git
synced 2026-11-12 14:41:42 +00:00
feat: add metric to track the number of turns with memory usage (#18662)
Add a metric `codex.turn.memory` to know if a turn used memories or not. This is not part of the other turn metrics as a label to limit cardinality
This commit is contained in:
1 parent
1c24347772
commit
2c59806fe0
8 files changed
+138
-26
No files matched your search
@@ -35,6 +35,7 @@ use codex_login::AuthManager;
|
||||
use codex_models_manager::manager::ModelsManager;
|
||||
use codex_otel::SessionTelemetry;
|
||||
use codex_otel::TURN_E2E_DURATION_METRIC;
|
||||
use codex_otel::TURN_MEMORY_METRIC;
|
||||
use codex_otel::TURN_NETWORK_PROXY_METRIC;
|
||||
use codex_otel::TURN_TOKEN_USAGE_METRIC;
|
||||
use codex_otel::TURN_TOOL_CALL_METRIC;
|
||||
@@ -96,6 +97,29 @@ fn emit_turn_network_proxy_metric(
|
||||
);
|
||||
}
|
||||
|
||||
fn emit_turn_memory_metric(
|
||||
session_telemetry: &SessionTelemetry,
|
||||
feature_enabled: bool,
|
||||
config_enabled: bool,
|
||||
has_citations: bool,
|
||||
) {
|
||||
let read_allowed = feature_enabled && config_enabled;
|
||||
session_telemetry.counter(
|
||||
TURN_MEMORY_METRIC,
|
||||
/*inc*/ 1,
|
||||
&[
|
||||
("read_allowed", bool_tag(read_allowed)),
|
||||
("feature_enabled", bool_tag(feature_enabled)),
|
||||
("config_use_memories", bool_tag(config_enabled)),
|
||||
("has_citations", bool_tag(has_citations)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
fn bool_tag(value: bool) -> &'static str {
|
||||
if value { "true" } else { "false" }
|
||||
}
|
||||
|
||||
/// Thin wrapper that exposes the parts of [`Session`] task runners need.
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct SessionTaskContext {
|
||||
@@ -409,6 +433,7 @@ impl Session {
|
||||
let mut pending_input = Vec::<ResponseInputItem>::new();
|
||||
let mut should_clear_active_turn = false;
|
||||
let mut token_usage_at_turn_start = None;
|
||||
let mut turn_had_memory_citation = false;
|
||||
let mut turn_tool_calls = 0_u64;
|
||||
let turn_state = {
|
||||
let mut active = self.active_turn.lock().await;
|
||||
@@ -428,6 +453,7 @@ impl Session {
|
||||
if let Some(turn_state) = turn_state {
|
||||
let mut ts = turn_state.lock().await;
|
||||
pending_input = ts.take_pending_input();
|
||||
turn_had_memory_citation = ts.has_memory_citation;
|
||||
turn_tool_calls = ts.tool_calls;
|
||||
token_usage_at_turn_start = Some(ts.token_usage_at_turn_start.clone());
|
||||
}
|
||||
@@ -531,6 +557,12 @@ impl Session {
|
||||
&[("token_type", "reasoning_output"), tmp_mem],
|
||||
);
|
||||
}
|
||||
emit_turn_memory_metric(
|
||||
&self.services.session_telemetry,
|
||||
turn_context.features.enabled(Feature::MemoryTool),
|
||||
turn_context.config.memories.use_memories,
|
||||
turn_had_memory_citation,
|
||||
);
|
||||
let (completed_at, duration_ms) = turn_context
|
||||
.turn_timing_state
|
||||
.completed_at_and_duration_ms()
|
||||
|
||||
Reference in new issue
Block a user