Skip to main content

Crate fast_telemetry

Crate fast_telemetry 

Source
Expand description

Fast, thread-sharded counters and histograms for high-performance telemetry.

OpenTelemetry counters use atomic operations with global synchronization, which causes cache-line bouncing across cores. This crate provides thread-local sharded counters that:

  • Increment with no cross-thread contention (just a thread-local write)
  • Are cache-line padded to avoid false sharing (using crossbeam’s CachePadded)
  • Aggregate on read (sum all shards)

§Labeled Metrics

For dimensional metrics (counters/gauges/histograms broken down by label), use the Labeled* types with a LabelEnum implementation. These provide O(1) lookup via array indexing instead of HashMap lookups.

use fast_telemetry::{LabeledCounter, LabelEnum};

#[derive(Copy, Clone, Debug)]
enum HttpMethod { Get, Post, Put, Delete }

impl LabelEnum for HttpMethod { /* ... */ }

let counter: LabeledCounter<HttpMethod> = LabeledCounter::new(4);
counter.inc(HttpMethod::Get);  // O(1) array index, no hashing

Re-exports§

pub use span::CompletedSpan;
pub use span::Span;
pub use span::SpanAttribute;
pub use span::SpanCollector;
pub use span::SpanEvent;
pub use span::SpanId;
pub use span::SpanKind;
pub use span::SpanStatus;
pub use span::SpanValue;
pub use span::TraceId;
pub use span::current_span_id;
pub use span::current_trace_id;

Modules§

otlp
span
Standalone distributed tracing for fast-telemetry.

Structs§

Counter
A sharded atomic counter.
Distribution
Exponential histogram distribution for high-performance metric recording.
DynamicCounter
Counter keyed by runtime label sets.
DynamicCounterSeries
A reusable handle to a dynamic-label counter series.
DynamicDistribution
Distribution keyed by runtime label sets.
DynamicDistributionSeries
A reusable handle to a dynamic-label distribution series.
DynamicGauge
Gauge keyed by runtime label sets.
DynamicGaugeI64
Signed integer gauge keyed by runtime label sets.
DynamicGaugeI64Series
A reusable handle to a dynamic-label i64 gauge series.
DynamicGaugeSeries
A reusable handle to a dynamic-label gauge series.
DynamicHistogram
Histogram keyed by runtime label sets.
DynamicHistogramSeries
A reusable handle to a dynamic-label histogram series.
DynamicLabelSet
Canonicalized runtime label set.
Gauge
A cache-padded atomic gauge for point-in-time measurements.
GaugeF64
A cache-padded atomic gauge for floating-point point-in-time measurements.
Histogram
A fixed-bucket histogram with thread-sharded counters.
LabeledCounter
A counter indexed by an enum label, providing O(1) dimensional metrics.
LabeledGauge
A gauge indexed by an enum label, providing O(1) dimensional metrics.
LabeledHistogram
A histogram indexed by an enum label, providing O(1) dimensional metrics.

Enums§

Temporality
Aggregation temporality used during export.

Traits§

DogStatsDExport
Trait for exporting a metric in DogStatsD format.
LabelEnum
Trait for label enums used with LabeledCounter, LabeledGauge, etc.
OtlpExport
Trait for exporting a metric as OTLP protobuf Metric messages.
PrometheusExport
Trait for exporting a metric in Prometheus text exposition format.

Functions§

advance_cycle
Advance the eviction cycle by 1 and return the new value.
current_cycle
Get the current eviction cycle.

Derive Macros§

DeriveLabel
Derive macro for implementing LabelEnum on enums.
ExportMetrics
Derive macro for exporting metrics in Prometheus, DogStatsD, and OTLP formats.