pub trait Telemetry {
const METRICS_ENABLED: bool = true;
const EVENTS_STATICALLY_ENABLED: bool = true;
// Required methods
fn incr_counter(&mut self, key: TelemetryKey, delta: u64);
fn set_gauge(&mut self, key: TelemetryKey, value: u64);
fn record_latency_ns(&mut self, key: TelemetryKey, value_ns: u64);
// Provided methods
fn push_metrics(&mut self) { ... }
fn events_enabled(&self) -> bool { ... }
fn push_event(&mut self, _event: TelemetryEvent) { ... }
fn flush(&mut self) { ... }
}Expand description
Core interface for collecting runtime metrics and structured telemetry events.
This trait is intentionally minimal and I/O-agnostic so that it can be
implemented in both no_std and std environments. Implementations are free to
ignore any subset of calls.
Provided Associated Constants§
Sourceconst METRICS_ENABLED: bool = true
const METRICS_ENABLED: bool = true
Compile-time flag indicating whether this telemetry implementation wants metrics (counters, gauges, latencies) at all.
Runtimes can use this to completely compile out metric collection
when METRICS_ENABLED is false for a given Telemetry type.
Sourceconst EVENTS_STATICALLY_ENABLED: bool = true
const EVENTS_STATICALLY_ENABLED: bool = true
Compile-time flag indicating whether this telemetry implementation ever produces structured events.
When this is false, runtimes can skip both the construction of
TelemetryEvent values and any calls to events_enabled(),
allowing event handling code to compile out entirely.
Required Methods§
Sourcefn incr_counter(&mut self, key: TelemetryKey, delta: u64)
fn incr_counter(&mut self, key: TelemetryKey, delta: u64)
Increment a counter metric identified by the given key.
Counters are monotonically increasing and are typically used for counts such as processed messages, dropped messages, or deadline misses.
Sourcefn set_gauge(&mut self, key: TelemetryKey, value: u64)
fn set_gauge(&mut self, key: TelemetryKey, value: u64)
Set a gauge metric identified by the given key.
Gauges represent the latest value of a quantity such as queue depth or current occupancy.
Sourcefn record_latency_ns(&mut self, key: TelemetryKey, value_ns: u64)
fn record_latency_ns(&mut self, key: TelemetryKey, value_ns: u64)
Record a latency sample in nanoseconds for the given key.
Implementations are free to aggregate these values as histograms, rolling averages, or to ignore them.
Provided Methods§
Sourcefn push_metrics(&mut self)
fn push_metrics(&mut self)
Optional: push a snapshot of aggregated metrics to the sink.
Runtimes can call this periodically without knowing how metrics are stored. Implementations that have no aggregated metrics can keep the default no-op.
Sourcefn events_enabled(&self) -> bool
fn events_enabled(&self) -> bool
Return true if this telemetry collector wants structured events.
Runtimes and nodes can use this to avoid constructing TelemetryEvent
values when events are disabled, keeping the hot path as cheap as possible.
Sourcefn push_event(&mut self, _event: TelemetryEvent)
fn push_event(&mut self, _event: TelemetryEvent)
Emit a structured telemetry event.
The default implementation is a no operation so that simple collectors can ignore structured events entirely.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.