1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! # 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`](std::sync::atomic::AtomicU64) internally (for the counters)
//! or a [`tokio::sync::Mutex`] guarded `Vec` (for provider history).
//!
//! ## Examples
//!
//! ```rust
//! 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);
//! ```
use Lazy;
use Arc;
use ProviderMetrics;
use AtomicTokenCounter;
use AtomicToolCounter;
/// Process-wide cumulative token usage across every provider request.
pub static TOKEN_USAGE: =
new;
/// Process-wide cumulative tool execution counter (success + failure).
pub static TOOL_EXECUTIONS: =
new;
/// Process-wide rolling buffer of the last N provider requests (N = 1000).
///
/// Used to derive averages, p50, and p95 latency / throughput per provider.
pub static PROVIDER_METRICS: =
new;