Skip to main content

codetether_agent/telemetry/provider/
snapshot.rs

1//! Aggregated per-provider view. Built by [`super::ProviderMetrics::all_snapshots`].
2
3use serde::{Deserialize, Serialize};
4
5/// Aggregated statistics for one provider across its retained request history.
6///
7/// All percentiles use the simple `(n * pct) as usize` index method; for the
8/// rolling 1000-entry buffer this is accurate to well within 1%.
9///
10/// # Examples
11///
12/// ```rust
13/// use codetether_agent::telemetry::ProviderSnapshot;
14///
15/// let s = ProviderSnapshot {
16///     provider: "openai".into(),
17///     request_count: 0,
18///     total_input_tokens: 0,
19///     total_output_tokens: 0,
20///     avg_tps: 0.0,
21///     avg_latency_ms: 0.0,
22///     p50_tps: 0.0,
23///     p50_latency_ms: 0.0,
24///     p95_tps: 0.0,
25///     p95_latency_ms: 0.0,
26/// };
27/// assert_eq!(s.provider, "openai");
28/// ```
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct ProviderSnapshot {
31    /// Provider name.
32    pub provider: String,
33    /// Requests included in this snapshot.
34    pub request_count: usize,
35    /// Sum of `input_tokens` across all included requests.
36    pub total_input_tokens: u64,
37    /// Sum of `output_tokens` across all included requests.
38    pub total_output_tokens: u64,
39    /// Mean output tokens-per-second.
40    pub avg_tps: f64,
41    /// Mean end-to-end latency in ms.
42    pub avg_latency_ms: f64,
43    /// Median output tokens-per-second.
44    pub p50_tps: f64,
45    /// Median end-to-end latency in ms.
46    pub p50_latency_ms: f64,
47    /// 95th-percentile tokens-per-second.
48    pub p95_tps: f64,
49    /// 95th-percentile latency in ms.
50    pub p95_latency_ms: f64,
51}