macro_rules! imetric {
(target: $target:expr, $name:expr, $unit:expr, $($rest:tt)+) => { ... };
($name:expr, $unit:expr, $($rest:tt)+) => { ... };
}Expand description
Records a integer metric. Use [imetric_dyn!] when the name or unit is built at run time.
§Examples
use micromegas_tracing::imetric;
imetric!("Frame Time", "ticks", 1000);Properties go between the unit and the value, as key = value pairs. A key is an
identifier or a string literal. Literal values are interned once per callsite, unless a ..set
is spread without a static value, in which case the literals are copied into the block
(the spread set’s own values are not); any other value is attached to the measure and copied
into the current block. A
bare value must implement PropertyValue (strings
do); use %value (Display) or ?value (Debug) for the rest, at the cost of one String
allocation.
use micromegas_tracing::prelude::*;
let correlation_id = String::from("c0ffee");
let rows = 3;
imetric!("rows_fetched", "count", correlation_id = correlation_id, region = "eu", rows = %rows, 3);
imetric!("rows_fetched", "count", "http.method" = "GET", 3);A precomputed &'static PropertySet is spread with ..set. It must come last in the
property list, and key = value pairs override its entries:
use micromegas_tracing::prelude::*;
use micromegas_tracing::property_set::{Property, PropertySet};
let set = PropertySet::find_or_create(vec![Property::new("region", "eu")]);
imetric!("rows_fetched", "count", ..set, 3);
imetric!("rows_fetched", "count", correlation_id = "c0ffee", ..set, 3);target: "name" replaces the module path as the target of the metric:
use micromegas_tracing::prelude::*;
imetric!(target: "my_crate::cache", "hits", "count", kind = "disk", 1);key = static expr takes a &'static str chosen at runtime, from a small closed set (a
label or an enum variant name, for example). Each distinct tuple of static values is interned
once per callsite and then looked up, a few nanoseconds more than a ..set spread and far
cheaper than a dynamic value. Every distinct value is kept forever, so the cardinality
contract of PropertySet applies: never use it for ids. It mixes freely with literals,
dynamic values and a trailing ..set. Among literals and static values the last one wins
(case-insensitive), a dynamic value beats both, and any pair overrides a ..set entry. With
..set and a static value in the same call, literals and static values are interned over the
set, so dynamic values beat them whatever the order.
use micromegas_tracing::prelude::*;
let label: &'static str = "alpha";
imetric!("rows_fetched", "count", prefix = static label, tier = "ram", 3);
fmetric!("fetch_ms", "ms", prefix = static label, 1.5);The value must be 'static; a borrowed string is a compile error:
use micromegas_tracing::prelude::*;
let s = String::from("alpha");
imetric!("rows_fetched", "count", prefix = static s.as_str(), 3);static doesn’t combine with % or ?:
use micromegas_tracing::prelude::*;
imetric!("rows_fetched", "count", prefix = static %"x", 3);target, name and unit are reserved keys, because analytics treats them as column
overrides. They can still be set through a ..set spread:
use micromegas_tracing::prelude::*;
imetric!("rows_fetched", "count", unit = "rows", 3);A literal value goes through concat!, so 1_000 is recorded as “1000” and 0x10 as “16”,
while a float keeps its spelling (0.50 stays “0.50”); %value uses Display instead.
A bare integer needs %:
use micromegas_tracing::prelude::*;
let n = 3_u32;
imetric!("rows_fetched", "count", rows = n, 3);A bare negated expression has no PropertyValue impl either:
use micromegas_tracing::prelude::*;
let n = 3_i32;
imetric!("rows_fetched", "count", delta = -n, 3);..set can’t be followed by other entries, and appears at most once:
use micromegas_tracing::prelude::*;
use micromegas_tracing::property_set::PropertySet;
let set = PropertySet::empty();
imetric!("rows_fetched", "count", ..set, kind = "a", 3);use micromegas_tracing::prelude::*;
use micromegas_tracing::property_set::PropertySet;
let set = PropertySet::empty();
imetric!("rows_fetched", "count", ..set, ..set, 3);