mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Add memory tool call metrics to memories extension (#24583)
## Why The memories extension now receives a metrics exporter, but the useful extension-owned signal is the memory tool call itself: which operation ran, which memory area it touched, whether the backend call succeeded, and whether the result was truncated. ## What changed - Added the `codex.memories.tool.call` counter in `ext/memories/src/metrics.rs`. - Emit that counter from `memories/add_ad_hoc_note`, `memories/list`, `memories/read`, and `memories/search` after backend execution. - Tag each call with `tool`, `operation`, `scope`, `status`, and `truncated`. - Pass the existing `MetricsClient` through the memories extension into the tool executors; tests use `None`. ## Verification - `just test -p codex-memories-extension`
This commit is contained in:
1 parent
b77be36896
commit
01a8bf0ae3
9 files changed
+154
-22
No files matched your search
@@ -0,0 +1,69 @@
|
||||
use codex_otel::MetricsClient;
|
||||
|
||||
use crate::MEMORY_TOOLS_NAMESPACE;
|
||||
|
||||
pub(crate) const MEMORIES_TOOL_CALL_METRIC: &str = "codex.memories.tool.call";
|
||||
|
||||
pub(crate) fn record_tool_call(
|
||||
metrics_client: Option<&MetricsClient>,
|
||||
operation: &str,
|
||||
scope: &str,
|
||||
success: bool,
|
||||
truncated: &str,
|
||||
) {
|
||||
let Some(metrics_client) = metrics_client else {
|
||||
return;
|
||||
};
|
||||
|
||||
let tool = format!("{MEMORY_TOOLS_NAMESPACE}{operation}");
|
||||
let _ = metrics_client.counter(
|
||||
MEMORIES_TOOL_CALL_METRIC,
|
||||
/*inc*/ 1,
|
||||
&[
|
||||
("tool", tool.as_str()),
|
||||
("operation", operation),
|
||||
("scope", scope),
|
||||
("status", status_tag(success)),
|
||||
("truncated", truncated),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn scope_from_path(path: &str) -> &'static str {
|
||||
let path = path.trim_matches('/');
|
||||
let path = path.strip_prefix("./").unwrap_or(path);
|
||||
|
||||
if path.is_empty() {
|
||||
"root"
|
||||
} else if path == "MEMORY.md" {
|
||||
"memory_md"
|
||||
} else if path == "memory_summary.md" {
|
||||
"memory_summary"
|
||||
} else if path == "raw_memories.md" {
|
||||
"raw_memories"
|
||||
} else if path == "rollout_summaries" || path.starts_with("rollout_summaries/") {
|
||||
"rollout_summaries"
|
||||
} else if path == "skills" || path.starts_with("skills/") {
|
||||
"skills"
|
||||
} else if path == "extensions/ad_hoc/notes" || path.starts_with("extensions/ad_hoc/notes/") {
|
||||
"ad_hoc_notes"
|
||||
} else {
|
||||
"other"
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn scope_from_optional_path(path: Option<&str>, default: &'static str) -> &'static str {
|
||||
path.map_or(default, scope_from_path)
|
||||
}
|
||||
|
||||
pub(crate) fn truncated_tag(truncated: Option<bool>) -> &'static str {
|
||||
match truncated {
|
||||
Some(true) => "true",
|
||||
Some(false) => "false",
|
||||
None => "unknown",
|
||||
}
|
||||
}
|
||||
|
||||
fn status_tag(success: bool) -> &'static str {
|
||||
if success { "succeeded" } else { "failed" }
|
||||
}
|
||||
Reference in new issue
Block a user