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§

clickhouse
otlp
span
Standalone distributed tracing for fast-telemetry.

Structs§

ClickHouseMetricBatch
OTel-standard ClickHouse rows built directly from fast-telemetry primitives.
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.
LabeledSampledTimer
Label-indexed sampled timer with O(1) lookup.
MaxGauge
A thread-sharded maximum tracker exported as a gauge.
MaxGaugeF64
A thread-sharded maximum tracker for floating-point values.
MetricLabel
One borrowed metric label pair.
MetricLabels
Borrowed labels for one metric observation.
MetricLabelsIter
Iterator over borrowed metric labels.
MetricMeta
Immutable metadata for one metric observation.
MinGauge
A thread-sharded minimum tracker exported as a gauge.
MinGaugeF64
A thread-sharded minimum tracker for floating-point values.
SampledTimer
Counts every timed operation and samples elapsed latency into a histogram.
SampledTimerGuard
RAII guard returned by SampledTimer::start and LabeledSampledTimer::start.

Enums§

MetricKind
Coarse semantic kind for a metric observation.
Temporality
Aggregation temporality used during export.

Traits§

ClickHouseExport
Direct ClickHouse export trait for metric primitives.
DistributionSnapshot
Borrowed snapshot view for exponential-bucket distributions.
DogStatsDExport
Trait for exporting a metric in DogStatsD format.
HistogramSnapshot
Borrowed snapshot view for fixed-bucket histograms.
LabelEnum
Trait for label enums used with LabeledCounter, LabeledGauge, etc.
MetricVisitor
Visitor for structured cumulative metric observations.
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.