Skip to main content

Module metrics

Module metrics 

Source
Expand description

Metrics collection and reporting.

This module provides metrics collection for monitoring session performance and behavior. It includes:

  • Core metrics (counters, gauges, histograms)
  • OpenTelemetry span integration (with metrics feature)
  • Prometheus export (with metrics feature)

§Basic Usage

use rust_expect::metrics::{Counter, Gauge, Timer, SessionMetrics};

// Use basic metrics
let counter = Counter::new();
counter.inc();

let gauge = Gauge::new();
gauge.set(42);

// Time an operation
let timer = Timer::start();
// ... do work ...
let elapsed = timer.stop();

§OpenTelemetry Integration (with metrics feature)

use rust_expect::metrics::otel::{init_tracing, shutdown_tracing};

// Initialize OpenTelemetry tracing
init_tracing("my-service", "http://localhost:4317")?;

// Your application code with tracing spans...

// Clean shutdown
shutdown_tracing();

Structs§

Counter
A counter metric.
Gauge
A gauge metric.
Histogram
A histogram for measuring distributions.
MetricsRegistry
Global metrics registry.
MetricsSnapshot
Snapshot of metrics.
SessionMetrics
Session metrics.
Timer
Timer for measuring durations.