pub struct StatsdClientBuilder { /* private fields */ }
Expand description
Builder for creating and customizing StatsdClient
instances.
Instances of the builder should be created by calling the ::builder()
method on the StatsClient
struct.
§Example
use cadence::prelude::*;
use cadence::{MetricError, StatsdClient, NopMetricSink};
fn my_error_handler(err: MetricError) {
println!("Metric error! {}", err);
}
let client = StatsdClient::builder("prefix", NopMetricSink)
.with_error_handler(my_error_handler)
.with_tag("environment", "production")
.with_tag_value("rust")
.build();
client.count("something", 123);
client.count_with_tags("some.counter", 42)
.with_tag("region", "us-east-2")
.send();
Implementations§
Source§impl StatsdClientBuilder
impl StatsdClientBuilder
Sourcepub fn with_error_handler<F>(self, errors: F) -> Self
pub fn with_error_handler<F>(self, errors: F) -> Self
Set an error handler to use for metrics sent via MetricBuilder::send()
The error handler is only invoked when metrics are not able to be sent
correctly. Either due to invalid input, I/O errors encountered when trying
to send them via a MetricSink
, or some other reason.
The error handler should consume the error without panicking. The error may be logged, printed to stderr, discarded, etc. - this is up to the implementation.
Sourcepub fn with_tag<K, V>(self, key: K, value: V) -> Self
pub fn with_tag<K, V>(self, key: K, value: V) -> Self
Add a default tag with key and value to every metric published by the built StatsdClient.
Sourcepub fn with_tag_value<K>(self, value: K) -> Selfwhere
K: ToString,
pub fn with_tag_value<K>(self, value: K) -> Selfwhere
K: ToString,
Add a default tag with only a value to every metric published by the built StatsdClient.
Sourcepub fn build(self) -> StatsdClient
pub fn build(self) -> StatsdClient
Construct a new StatsdClient
instance based on current settings.