Skip to main content

Module metrics

Module metrics 

Source
Available on crate feature metrics only.
Expand description

APIs for creating and capturing metrics.

With Sentry’s Application Metrics, you can record counters, gauges, and distributions from application code. This module is available when the metrics feature is enabled. Captured metrics are sent through the current Hub and are associated with the current trace and active span when available. The SDK also attaches default metric attributes.

Counters are unitless. Gauges and distributions support units via unit.

For more information, see the Rust SDK metrics guide.

§Examples

Capture counters, gauges, and distributions:

use sentry::metrics;
use sentry::protocol::Unit;

metrics::counter("http.requests", 1).capture();
metrics::gauge("queue.depth", 42).capture();
metrics::distribution("http.response_time", 187.5)
    .unit(Unit::Millisecond)
    .capture();

Add attributes that can be used to filter and group metrics in Sentry:

use sentry::metrics;

metrics::counter("http.requests", 1)
    .attribute("http.route", "/health")
    .attribute("http.response.status_code", 200)
    .capture();

Structs§

CounterMetric
A counter metric, created with counter.
DistributionMetric
A distribution metric, created with distribution.
GaugeMetric
A gauge metric, created with gauge.

Traits§

IntoProtocolMetric
Marker trait for types which can be converted to a protocol metric, allowing Hub::capture_metric to capture and send them to Sentry.

Functions§

counter
Creates a counter metric, with the given name and value.
distribution
Creates a distribution metric, with the given name and value.
gauge
Creates a gauge metric, with the given name and value.