Skip to main content

Telemetry

Trait Telemetry 

Source
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§

Source

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.

Source

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§

Source

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.

Source

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.

Source

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§

Source

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.

Source

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.

Source

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.

Source

fn flush(&mut self)

Flush any buffered telemetry data to the underlying sink.

The default implementation is a no operation. Implementations that buffer data or write to external sinks can use this to force a drain.

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.

Implementations on Foreign Types§

Source§

impl Telemetry for ()

Source§

const METRICS_ENABLED: bool = false

Source§

const EVENTS_STATICALLY_ENABLED: bool = false

Source§

fn incr_counter(&mut self, _key: TelemetryKey, _delta: u64)

Source§

fn set_gauge(&mut self, _key: TelemetryKey, _value: u64)

Source§

fn record_latency_ns(&mut self, _key: TelemetryKey, _value_ns: u64)

Implementors§