buswatch_sdk/lib.rs
1//! # buswatch-sdk
2//!
3//! Instrumentation SDK for emitting message bus metrics to buswatch.
4//!
5//! This crate provides a simple API for instrumenting any message bus system
6//! to emit metrics that can be consumed by buswatch or other monitoring tools.
7//!
8//! ## Quick Start
9//!
10//! ```rust,no_run
11//! use buswatch_sdk::{Instrumentor, Output};
12//! use std::time::Duration;
13//!
14//! #[tokio::main]
15//! async fn main() {
16//! // Create an instrumentor that emits snapshots every second
17//! let instrumentor = Instrumentor::builder()
18//! .output(Output::file("metrics.json"))
19//! .interval(Duration::from_secs(1))
20//! .build();
21//!
22//! // Register a module and get a handle for recording metrics
23//! let handle = instrumentor.register("my-service");
24//!
25//! // Record metrics as your service processes messages
26//! handle.record_read("orders.new", 1);
27//! handle.record_write("orders.processed", 1);
28//!
29//! // Start background emission (non-blocking)
30//! instrumentor.start();
31//!
32//! // ... your application runs ...
33//! }
34//! ```
35//!
36//! ## Features
37//!
38//! - **Simple API**: Just `record_read()` and `record_write()`
39//! - **Multiple outputs**: File, TCP, or custom channel
40//! - **Background emission**: Automatic periodic snapshots
41//! - **Thread-safe**: Use from any thread or async task
42//! - **Low overhead**: Lock-free counters where possible
43
44mod handle;
45mod instrumentor;
46mod output;
47mod state;
48
49#[cfg(feature = "otel")]
50pub mod otel;
51
52pub use handle::ModuleHandle;
53pub use instrumentor::{Instrumentor, InstrumentorBuilder};
54pub use output::Output;
55
56#[cfg(feature = "otel")]
57pub use otel::{OtelConfig, OtelExporter};
58
59// Re-export types for convenience
60pub use buswatch_types::{Microseconds, ModuleMetrics, ReadMetrics, Snapshot, WriteMetrics};