Skip to main content

photon_telemetry/
lib.rs

1//! Operations telemetry port for Photon.
2//!
3//! Hosts install a process-wide [`OpsLog`] via [`install_ops_log`] or
4//! [`PhotonBuilder::ops_log`](https://docs.rs/uf-photon/latest/photon/struct.PhotonBuilder.html#method.ops_log).
5//! Backend instrumentation (publish counters, DLQ rows, checkpoint failures) calls [`ops_log`].
6//!
7//! ## Entry points
8//!
9//! - [`OpsLog`] — counter / gauge / event trait
10//! - [`install_ops_log`] / [`ops_log`] / [`ops_log_from_env`] — process-wide adapter
11//! - [`ConsoleOpsLog`] / [`NoOpsLog`] — shipped adapters
12
13mod console;
14mod global;
15mod noop;
16
17#[cfg(feature = "recording")]
18mod recording;
19
20pub use console::ConsoleOpsLog;
21pub use global::{install_ops_log, ops_log, ops_log_from_env};
22pub use noop::NoOpsLog;
23
24#[cfg(feature = "recording")]
25pub use recording::{RecordedCounter, RecordedEvent, RecordedGauge, RecordingOpsLog};
26
27/// Structured ops metrics/events for publish, drain, DLQ, checkpoints.
28pub trait OpsLog: Send + Sync {
29    /// Increment a counter with optional labels.
30    fn record_counter(&self, name: &str, labels: &[(&str, &str)], value: f64);
31
32    /// Set a gauge with optional labels.
33    fn record_gauge(&self, name: &str, labels: &[(&str, &str)], value: f64);
34
35    /// Emit a structured diagnostic event.
36    fn log_event(&self, name: &str, payload: &serde_json::Value);
37}
38
39#[cfg(test)]
40mod tests {
41    use super::{ConsoleOpsLog, NoOpsLog, OpsLog};
42
43    #[test]
44    fn noop_ops_log_is_silent() {
45        let log = NoOpsLog;
46        log.record_counter("c", &[], 1.0);
47        log.record_gauge("g", &[], 2.0);
48        log.log_event("e", &serde_json::json!({}));
49    }
50
51    #[test]
52    fn console_ops_log_does_not_panic() {
53        let log = ConsoleOpsLog;
54        log.record_counter("photon_publishes", &[("topic", "t")], 1.0);
55    }
56}