Instrumentor

Struct Instrumentor 

Source
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

Source

pub fn new() -> Self

Create a new instrumentor with default settings.

By default, no outputs are configured and the interval is 1 second.

Source

pub fn builder() -> InstrumentorBuilder

Create a builder for configuring the instrumentor.

Source

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”)
Source

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.

Source

pub fn start(&self) -> EmissionHandle

Start background emission of snapshots.

This spawns a tokio task that periodically collects and emits snapshots to all configured outputs.

Returns a handle that can be used to stop the emission.

Source

pub async fn emit_now(&self)

Emit a snapshot to all outputs immediately.

Trait Implementations§

Source§

impl Debug for Instrumentor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Instrumentor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.