Trait cadence::prelude::MetricClient
source · Expand description
Trait that encompasses all other traits for sending metrics.
If you wish to use StatsdClient
with a generic type or place a
StatsdClient
instance behind a pointer (such as a Box
) this will allow
you to reference all the implemented methods for recording metrics, while
using a single trait. An example of this is shown below.
use cadence::{MetricClient, StatsdClient, NopMetricSink};
let client: Box<MetricClient> = Box::new(StatsdClient::from_sink(
"prefix", NopMetricSink));
client.count("some.counter", 1).unwrap();
client.time("some.timer", 42).unwrap();
client.gauge("some.gauge", 8).unwrap();
client.meter("some.meter", 13).unwrap();
client.histogram("some.histogram", 4).unwrap();
client.set("some.set", 5).unwrap();