1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
// Cadence - An extensible Statsd client for Rust!
//
// To the extent possible under law, the author(s) have dedicated all copyright and
// related and neighboring rights to this file to the public domain worldwide.
// This software is distributed without any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication along with this
// software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
// This example shows how you might use Cadence to send multiple values with each request
// either with a method the returns the result of sending them, or with a
// method the delegates any errors to a predefined error handler.
use cadence::prelude::*;
use cadence::{MetricError, NopMetricSink, StatsdClient};
fn main() {
fn my_error_handler(err: MetricError) {
eprintln!("Error sending metrics: {}", err);
}
let client = StatsdClient::builder("my.prefix", NopMetricSink)
.with_error_handler(my_error_handler)
.build();
// In this case we are sending a distribution metric with two tag key-value
// pairs. If sending the metric fails, our error handler set above will
// be invoked to do something with the metric error.
client
.distribution_with_tags("latency.milliseconds", vec![10, 20, 30, 40, 50])
.with_tag("app", "search")
.with_tag("region", "us-west-2")
.send();
// In this case we are sending the same distribution metrics with two tags.
// The results of sending the metric (or failing to send it) are returned
// to the caller to do something with.
let res = client
.distribution_with_tags("latency.milliseconds", vec![10, 20, 30, 40, 50])
.with_tag("app", "search")
.with_tag("region", "us-west-2")
.try_send();
println!("Result of metric send: {:?}", res);
}