ModuleHandle

Struct ModuleHandle 

Source
pub struct ModuleHandle { /* private fields */ }
Expand description

A handle for recording metrics for a specific module.

This is the primary interface for instrumenting your message bus. Obtain a handle by calling Instrumentor::register().

§Example

use buswatch_sdk::Instrumentor;

let instrumentor = Instrumentor::new();
let handle = instrumentor.register("my-service");

// Record a read from a topic
handle.record_read("orders.new", 1);

// Record a write to a topic
handle.record_write("orders.processed", 1);

// Track pending operations
let guard = handle.start_read("orders.new");
// ... do the read ...
drop(guard); // Clears pending state

Implementations§

Source§

impl ModuleHandle

Source

pub fn record_read(&self, topic: &str, count: u64)

Record that messages were read from a topic.

§Arguments
  • topic - The topic name
  • count - Number of messages read
Source

pub fn record_write(&self, topic: &str, count: u64)

Record that messages were written to a topic.

§Arguments
  • topic - The topic name
  • count - Number of messages written
Source

pub fn start_read(&self, topic: &str) -> PendingGuard

Start tracking a pending read operation.

Returns a guard that clears the pending state when dropped. This is useful for tracking how long reads are blocked.

§Example
let guard = handle.start_read("events");
// ... blocking read operation ...
drop(guard); // Clears pending state
handle.record_read("events", 1);
Source

pub fn start_write(&self, topic: &str) -> PendingGuard

Start tracking a pending write operation.

Returns a guard that clears the pending state when dropped. This is useful for tracking backpressure (slow consumers).

Source

pub fn set_read_pending(&self, topic: &str, since: Option<Instant>)

Set the pending duration for a read directly.

Use this if you’re computing pending time yourself rather than using the guard-based API.

Source

pub fn set_write_pending(&self, topic: &str, since: Option<Instant>)

Set the pending duration for a write directly.

Source

pub fn name(&self) -> &str

Get the module name.

Trait Implementations§

Source§

impl Clone for ModuleHandle

Source§

fn clone(&self) -> ModuleHandle

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ModuleHandle

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.