Skip to main content

torvyn_observability/
lib.rs

1//! # torvyn-observability
2//!
3//! Tracing, metrics, diagnostics, and runtime inspection for the Torvyn
4//! reactive streaming runtime.
5//!
6//! This crate provides the observability subsystem defined in HLI Doc 05.
7//! It implements the [`EventSink`](torvyn_types::EventSink) trait from
8//! `torvyn-types` for hot-path recording and manages three internal
9//! subsystems:
10//!
11//! - **Metrics**: Pre-allocated counters, histograms, and gauges scoped per
12//!   flow, component, and stream.
13//! - **Tracing**: Trace context propagation, sampling, and span ring buffers
14//!   for retroactive export.
15//! - **Events**: Structured diagnostic events for lifecycle, performance,
16//!   error, security, and resource state transitions.
17//!
18//! ## Architecture
19//!
20//! The [`ObservabilityCollector`] is the central orchestrator. It:
21//! - Implements `EventSink` for the reactor, resource manager, and host
22//!   lifecycle manager.
23//! - Owns the [`MetricsRegistry`] that holds pre-allocated per-flow metrics.
24//! - Manages the event channel and diagnostic event buffer.
25//! - Provides [`FlowObserver`] handles to the reactor for per-flow recording.
26//!
27//! ## Observability Levels
28//!
29//! | Level | Overhead | What's collected |
30//! |-------|----------|------------------|
31//! | Off | 0 | Nothing |
32//! | Production | < 500ns/element | Counters, histograms, sampled traces |
33//! | Diagnostic | < 2μs/element | All of Production + per-element spans, events |
34//!
35//! Level switching is atomic and does not require restarting flows.
36
37#![deny(missing_docs)]
38
39pub mod bench;
40pub mod collector;
41pub mod config;
42pub mod events;
43pub mod export;
44pub mod metrics;
45pub mod tracer;
46
47// Re-exports for public API.
48pub use bench::BenchmarkReport;
49pub use collector::{FlowObserver, ObservabilityCollector};
50pub use config::ObservabilityConfig;
51pub use events::{DiagnosticEvent, EventCategory, EventPayload};
52pub use metrics::{
53    Counter, FlowMetricsSnapshot, Gauge, Histogram, HistogramSnapshot, MetricsRegistry,
54    LATENCY_BUCKETS_NS, SIZE_BUCKETS_BYTES,
55};
56pub use tracer::{
57    CompactSpanRecord, FlowTraceContext, Sampler, SamplingDecision, SpanRingBuffer, TraceFlags,
58};