pub struct Reporter { /* private fields */ }Expand description
Records telemetry events, ships the ones worth their bytes, and counts them all.
A reporter keeps a level threshold and forwards only events at or above it, while
counting every event it sees - dropped or not - so the aggregate picture survives
even when the link is too costly to ship detail. Call
adapt_to as the link cost changes to raise or lower the
bar, and ship a snapshot of the counters periodically
instead of the full stream.
§Examples
use pamoja_telemetry::{Event, Level, LinkCost, Reporter};
let mut reporter = Reporter::new(Level::Trace);
// On a metered link, routine debug events are dropped but a warning still ships.
reporter.adapt_to(LinkCost::Metered);
assert!(reporter.record(Event::debug("loop.tick")).is_none());
assert!(reporter.record(Event::warn("battery.low")).is_some());
// Both events were still counted.
assert_eq!(reporter.total(), 2);
assert_eq!(reporter.dropped(), 1);Implementations§
Source§impl Reporter
impl Reporter
Sourcepub fn set_threshold(&mut self, threshold: Level)
pub fn set_threshold(&mut self, threshold: Level)
Sourcepub fn adapt_to(&mut self, cost: LinkCost)
pub fn adapt_to(&mut self, cost: LinkCost)
Raises or lowers the threshold to match the current link cost.
§Arguments
cost- how costly the link currently is.
Sourcepub fn record(&mut self, event: Event) -> Option<Event>
pub fn record(&mut self, event: Event) -> Option<Event>
Records an event, returning it to ship if it clears the threshold.
The event is counted whether or not it is shipped, so the aggregate counts stay complete even while detail is held back.
§Arguments
event- the event to record.
§Returns
Some(event) if it should be shipped, or None if it was dropped by the
threshold.