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 stateImplementations§
Source§impl ModuleHandle
impl ModuleHandle
Sourcepub fn record_read(&self, topic: &str, count: u64)
pub fn record_read(&self, topic: &str, count: u64)
Record that messages were read from a topic.
§Arguments
topic- The topic namecount- Number of messages read
Sourcepub fn record_write(&self, topic: &str, count: u64)
pub fn record_write(&self, topic: &str, count: u64)
Record that messages were written to a topic.
§Arguments
topic- The topic namecount- Number of messages written
Sourcepub fn start_read(&self, topic: &str) -> PendingGuard
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);Sourcepub fn start_write(&self, topic: &str) -> PendingGuard
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).
Sourcepub fn set_read_pending(&self, topic: &str, since: Option<Instant>)
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.
Sourcepub fn set_write_pending(&self, topic: &str, since: Option<Instant>)
pub fn set_write_pending(&self, topic: &str, since: Option<Instant>)
Set the pending duration for a write directly.
Trait Implementations§
Source§impl Clone for ModuleHandle
impl Clone for ModuleHandle
Source§fn clone(&self) -> ModuleHandle
fn clone(&self) -> ModuleHandle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more