scuffle_metrics_derive

Attribute Macro metrics

Source
#[metrics]
Expand description

A macro used to create metric handlers.

You can change the crate by specifying #[metrics(crate = "...")].

Attributes:

  • crate: The scuffle_metrics crate path. Valid on modules & functions.
  • builder: The builder to use for the metric. Valid on functions.
  • unit: The unit of the metric. Valid on functions.
  • rename: The name of the metric. Valid on modules, functions & function arguments.

When using the module, you do not need to attribute each function with the #[metrics] attribute. All non function definitions are ignored.

§Module Example

#[metrics]
mod example {
    use scuffle_metrics::{CounterU64, MetricEnum};

    #[derive(MetricEnum)]
    pub enum Kind {
        Http,
        Grpc,
    }

    #[metrics(unit = "requests")]
    pub fn request(kind: Kind) -> CounterU64;
}

example::request(Kind::Http).incr();

§Function Example

#[metrics(unit = "requests")]
pub fn request(kind: Kind) -> CounterU64;

request(Kind::Http).incr();