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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//! # Telemetry
//!
//! Observability for the CodeTether agent. Tracks token usage, tool executions,
//! per-provider latency/throughput, file changes, swarm progress, cost
//! estimates, and persistent audit-style records.
//!
//! ## Architecture
//!
//! Every telemetry concern lives in its own submodule so that individual files
//! stay small (≤ 50 lines of code, per the project's [coding standards]) and
//! each file holds a **single responsibility**. This module re-exports the
//! public surface so callers continue to write `use crate::telemetry::Foo;`
//! without knowing the internal layout.
//!
//! | Submodule | Responsibility |
//! |---|---|
//! | [`tokens`] | Token totals, snapshots, and the global [`AtomicTokenCounter`] |
//! | [`tools`] | Tool-execution records, the [`AtomicToolCounter`], and [`FileChange`] |
//! | [`provider`] | Per-provider request records, snapshots, and aggregated stats |
//! | [`context`] | Context-window usage ratios ([`ContextLimit`]) |
//! | [`cost`] | USD cost estimation ([`CostEstimate`]) |
//! | [`a2a`] | A2A message records |
//! | [`swarm`] | Swarm (multi-agent) telemetry collector |
//! | [`metrics`] | Per-instance rolling metrics ([`Telemetry`]) |
//! | [`persistent`] | On-disk / long-lived stats façade |
//! | [`globals`] | Process-wide `Lazy` singletons |
//!
//! ## Coding Standards for This Module
//!
//! New code must follow these rules (enforced in review):
//!
//! 1. **Single Responsibility.** One struct or one tight function group per file.
//! 2. **50-line limit.** Hard cap per file (excluding comments/blanks). Split
//! before you reach 45.
//! 3. **Rustdoc everywhere.** Every public item gets `///` docs with a
//! `# Examples` section. Prefer runnable (` ```rust `) examples;
//! fall back to `no_run` only when a runtime is required; avoid `ignore`.
//! 4. **No `any`-style typing.** Every public field and return type is
//! explicitly typed.
//! 5. **Tracing over println.** Use structured fields, e.g.
//! `tracing::info!(tool = %name, "...")`.
//! 6. **Never hand-roll atomics when an existing counter fits.** Reuse
//! [`AtomicTokenCounter`] / [`AtomicToolCounter`] rather than adding new
//! `AtomicU64` fields elsewhere.
//!
//! [coding standards]: ../../AGENTS.md
//!
//! ## Quick Start
//!
//! ```rust
//! use codetether_agent::telemetry::{TokenTotals, CostEstimate, TokenCounts};
//!
//! let totals = TokenTotals::new(1_000, 500);
//! assert_eq!(totals.total(), 1_500);
//!
//! let cost = CostEstimate::from_tokens(
//! &TokenCounts::new(1_000_000, 500_000),
//! 3.00, // $ per 1M input tokens
//! 15.00, // $ per 1M output tokens
//! );
//! assert_eq!(cost.currency, "USD");
//! ```
pub use A2AMessageRecord;
pub use ContextLimit;
pub use CostEstimate;
pub use ;
pub use ;
pub use ;
pub use ;
pub use SwarmTelemetryCollector;
pub use ;
pub use ;