Macro cadence_macros::statsd_time[][src]

macro_rules! statsd_time {
    ($key:expr, $val:expr) => { ... };
    ($key:expr, $val:expr, $($tag_key:expr => $tag_val:expr),*) => { ... };
}

Emit a timer using the default global client, optionally with tags

The timer will use the prefix from the default global client combined with the provided key.

Any errors encountered sending metrics will be handled by the error handler registered with the default global client. This error handler is a no-op unless explicitly set. Callers should set the error handler for the default client if you wish to handle these errors (by logging them or something similar).

Panics

This macro will panic if the default global client has not been set when it is invoked (via cadence_macros::set_global_default).

Examples

use cadence::{StatsdClient, NopMetricSink};
use cadence_macros::statsd_time;

let client = StatsdClient::builder("my.prefix", NopMetricSink)
    .with_error_handler(|e| { eprintln!("metric error: {}", e) })
    .build();

cadence_macros::set_global_default(client);

// "my.prefix.some.timer:123|ms"
statsd_time!("some.timer", 123);
// "my.prefix.some.timer:123|ms|#tag:val"
statsd_time!("some.timer", 123, "tag" => "val");
// "my.prefix.some.timer:123|ms|#tag:val,another:thing"
statsd_time!("some.timer", 123, "tag" => "val", "another" => "thing");

Limitations

Only key-value style tags are supported. Value style tags are not supported, e.g. builder.with_tag_value("val").