Skip to main content

sample

Macro sample 

Source
sample!() { /* proc-macro */ }
Expand description

Emit a metric sample.

§Examples

Emit a metric sample from a value:

let my_metric = 42;

emit::sample!(value: my_metric);

In the above example, the name is inferred to be "my_metric" using the name of the identifier in the value control parameter.

The name can also be specified manually, and is required if value is not an identifier:

emit::sample!(name: "my_metric", value: 42);

Properties can be attached to metric samples:

let my_metric = 42;

let metric = emit::sample!(value: my_metric, props: emit::props! { my_property: "some value" });

§Syntax

(control_param),*

where

  • control_param: A Rust field-value with a pre-determined identifier (see below).

§Control parameters

This macro accepts the following optional control parameters:

nametypedescription
rtimpl emit::runtime::RuntimeThe runtime to emit the metric sample through if sampler is unspecified.
samplerimpl emit::sampler::SamplerThe Sampler to pass the metric sample to.
mdlimpl Into<emit::Path>The module the metric sample belongs to. If unspecified the current module path is used.
extentimpl emit::ToExtentThe extent to use on the metric sample. If unspecified the extent is left empty.
propsimpl emit::PropsA set of properties to add to the metric sample.
value (required)impl emit::ToValueThe value of the metric sample. If the value is an identifier then name will be inferred to be that identifier.
name (required if value is not an identifier)impl emit::ToStrThe name of the metric being sampled. If unspecified, and value is an identifier, then the stringified identifier is used as the name.
aggimpl emit::ToStrThe aggregation of the metric sample. If unspecified, the default for the macro is used.
descriptionimpl emit::ToStrA description of the underlying data source. If unspecified the description is left empty.
unitimpl emit::ToStrThe measurement unit of the sample value. If unspecified the unit is left empty.