pub struct Instrumentor { /* private fields */ }Expand description
The main entry point for instrumenting a message bus.
An Instrumentor collects metrics from registered modules and periodically emits snapshots to configured outputs.
§Example
use buswatch_sdk::{Instrumentor, Output};
use std::time::Duration;
#[tokio::main]
async fn main() {
let instrumentor = Instrumentor::builder()
.output(Output::file("metrics.json"))
.interval(Duration::from_secs(1))
.build();
let handle = instrumentor.register("my-service");
// Start background emission
instrumentor.start();
// Record some metrics
handle.record_read("events", 10);
handle.record_write("results", 10);
// Keep the application running
tokio::time::sleep(Duration::from_secs(5)).await;
}Implementations§
Source§impl Instrumentor
impl Instrumentor
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new instrumentor with default settings.
By default, no outputs are configured and the interval is 1 second.
Sourcepub fn builder() -> InstrumentorBuilder
pub fn builder() -> InstrumentorBuilder
Create a builder for configuring the instrumentor.
Sourcepub fn register(&self, name: &str) -> ModuleHandle
pub fn register(&self, name: &str) -> ModuleHandle
Register a module and get a handle for recording metrics.
If a module with this name already exists, returns a handle to the existing module.
§Arguments
name- The module name (e.g., “order-processor”, “notification-sender”)
Sourcepub fn collect(&self) -> Snapshot
pub fn collect(&self) -> Snapshot
Collect a snapshot of all current metrics.
This is useful if you want to emit snapshots manually rather than using the background emission.
Trait Implementations§
Source§impl Debug for Instrumentor
impl Debug for Instrumentor
Auto Trait Implementations§
impl Freeze for Instrumentor
impl !RefUnwindSafe for Instrumentor
impl Send for Instrumentor
impl Sync for Instrumentor
impl Unpin for Instrumentor
impl !UnwindSafe for Instrumentor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more