Expand description
§Global telemetry singletons
Process-wide counters that every part of the agent writes to. Isolated in their own file so the static definitions don’t bloat any type module.
§Why globals?
Telemetry must be cheap and lock-free at the call site — wrapping every
provider/tool call in dependency-injected collectors was measured to add
noticeable overhead in the hot path. The three singletons here use
AtomicU64 internally (for the counters)
or a tokio::sync::Mutex guarded Vec (for provider history).
§Examples
use codetether_agent::telemetry::{TOKEN_USAGE, TOOL_EXECUTIONS};
TOKEN_USAGE.record(100, 50);
TOOL_EXECUTIONS.record(true);
let (prompt, completion, total) = TOKEN_USAGE.get();
assert!(total >= prompt + completion);Statics§
- PROVIDER_
METRICS - Process-wide rolling buffer of the last N provider requests (N = 1000).
- TOKEN_
USAGE - Process-wide cumulative token usage across every provider request.
- TOOL_
EXECUTIONS - Process-wide cumulative tool execution counter (success + failure).