Files
codex/codex-rs/core-plugins/src/loaded_cache_metrics.rs
willwang-openai 91c66024c7 Instrument the loaded plugin cache (#41231)
## What changed

- Count loaded-plugin cache requests by `hit`, `hit_after_wait`, or `load` outcome.
- Record time spent waiting for the load semaphore and loading plugins.
- Count cache clears and capacity evictions.
- Remove the unused force-reload path from `PluginsManager::plugins_for_config`.

GitOrigin-RevId: db7829e7bd9b1414a263d9a7100c05dfdd832777
2026-08-28 00:17:08 +00:00

50 lines
1.5 KiB
Rust

//! Request counts exclude disabled plugins, account-switch discards, and cancellations.
//! Auth retries keep the furthest request outcome reached; each completed wait/load is timed.
//! Skill-snapshot lookups are not requests. Clear events include already-empty caches.
//! Tags never contain configuration data.
use std::time::Duration;
pub(crate) const LOAD_DURATION: &str = "codex.plugins.loaded_cache.load.duration_ms";
pub(crate) const WAIT_DURATION: &str = "codex.plugins.loaded_cache.wait.duration_ms";
pub(crate) enum RequestOutcome {
Hit,
HitAfterWait,
Load,
}
impl RequestOutcome {
pub(crate) fn record(self) {
let Some(metrics) = codex_otel::global() else {
return;
};
let outcome = match self {
Self::Hit => "hit",
Self::HitAfterWait => "hit_after_wait",
Self::Load => "load",
};
let _ = metrics.counter(
"codex.plugins.loaded_cache.request",
/*inc*/ 1,
&[("outcome", outcome)],
);
}
}
pub(crate) fn record_duration(name: &'static str, duration: Duration) {
if let Some(metrics) = codex_otel::global() {
let _ = metrics.record_duration(name, duration, &[]);
}
}
pub(crate) fn record_event(event: &'static str) {
if let Some(metrics) = codex_otel::global() {
let _ = metrics.counter(
"codex.plugins.loaded_cache.event",
/*inc*/ 1,
&[("event", event)],
);
}
}