---
title: "Metrics"
description: "Metrics allow you to send, view and query counters, gauges and measurements from your Sentry-configured apps to track application health and drill down into related traces, logs, and errors."
url: https://docs.sentry.io/platforms/rust/guides/actix-web/metrics/
---

# Set Up Metrics | Sentry for Actix Web

With [Sentry's Application Metrics](https://docs.sentry.io/product/explore/metrics.md), you can send counters, gauges, and distributions from your Rust applications to Sentry. Once in Sentry, these metrics can be viewed alongside relevant errors and searched using their individual attributes.

## [Requirements](https://docs.sentry.io/platforms/rust/guides/actix-web/metrics.md#requirements)

Metrics for Rust are supported in Sentry Rust SDK version `0.48.0` or later when compiled with the `metrics` feature.

`Cargo.toml`

```toml
[dependencies]
sentry = { version = "0.48.1", features = ["metrics"] }
```

Metrics are enabled by default.

## [Usage](https://docs.sentry.io/platforms/rust/guides/actix-web/metrics.md#usage)

The SDK's [`sentry::metrics` module](https://docs.rs/sentry/latest/sentry/metrics/index.html) contains functions for capturing each of the [three metric types](https://docs.sentry.io/product/explore/metrics.md#metric-types) that Sentry supports.

Metrics are automatically associated with the trace and, if applicable, the span they are captured within.

### [Capture a Counter](https://docs.sentry.io/platforms/rust/guides/actix-web/metrics.md#capture-a-counter)

Capture [counter metrics](https://docs.sentry.io/product/explore/metrics.md#counters) using [`metrics::counter`](https://docs.rs/sentry/latest/sentry/metrics/fn.counter.html).

Counters track occurrences, such as handled HTTP requests, and are always unitless.

`main.rs`

```rust
use sentry::metrics;

metrics::counter("http.requests", 1).capture();
```

### [Capture a Gauge](https://docs.sentry.io/platforms/rust/guides/actix-web/metrics.md#capture-a-gauge)

Capture [gauge metrics](https://docs.sentry.io/product/explore/metrics.md#gauges) using [`metrics::gauge`](https://docs.rs/sentry/latest/sentry/metrics/fn.gauge.html).

Gauges track current state or level, such as queue depth or active connections, and support [units](https://docs.rs/sentry/latest/sentry/metrics/struct.GaugeMetric.html#method.unit).

`main.rs`

```rust
use sentry::metrics;

metrics::gauge("queue.depth", 42).capture();
```

### [Distribution](https://docs.sentry.io/platforms/rust/guides/actix-web/metrics.md#distribution)

Capture [distribution metrics](https://docs.sentry.io/product/explore/metrics.md#distributions) using [`metrics::distribution`](https://docs.rs/sentry/latest/sentry/metrics/fn.distribution.html).

Distributions track values that vary and need statistical analysis, such as response times or payload sizes, and they support [units](https://docs.rs/sentry/latest/sentry/metrics/struct.DistributionMetric.html#method.unit).

`main.rs`

```rust
use sentry::metrics;
use sentry::protocol::Unit;

metrics::distribution("http.response_time", 187.5)
  .unit(Unit::Millisecond)
  .capture();
```

### [Setting Attributes](https://docs.sentry.io/platforms/rust/guides/actix-web/metrics.md#setting-attributes)

Attributes let you filter and group metrics in Sentry. Add them with `.attribute(key, value)` before you call `.capture()`. You can add multiple attributes by chaining calls to `.attribute`.

When possible, use [Sentry Semantic Conventions](https://getsentry.github.io/sentry-conventions/) for attribute keys.

## [Options](https://docs.sentry.io/platforms/rust/guides/actix-web/metrics.md#options)

### [Filtering Metrics](https://docs.sentry.io/platforms/rust/guides/actix-web/metrics.md#filtering-metrics)

Use [`before_send_metric`](https://docs.rs/sentry/latest/sentry/struct.ClientOptions.html#structfield.before_send_metric) to drop or update metrics before Sentry sends them. Return `None` to drop a metric.

For example, to filter all metrics with the name `"debug.metric"`, you could use the following `before_send_metric`:

`main.rs`

```rust
let _guard = sentry::init((
    "___PUBLIC_DSN___",
    sentry::ClientOptions {
        before_send_metric: Some(std::sync::Arc::new(|metric| {
            if metric.name == "debug.metric" {
                return None;
            }

            Some(metric)
        })),
        ..Default::default()
    },
));
```

### [Disabling Metrics](https://docs.sentry.io/platforms/rust/guides/actix-web/metrics.md#disabling-metrics)

Metrics are enabled by default when the `sentry` crate is compiled with the `metrics` feature. To stop sending metrics, set [`enable_metrics: false`](https://docs.rs/sentry/latest/sentry/struct.ClientOptions.html#structfield.enable_metrics) in the [`ClientOptions`](https://docs.rs/sentry/latest/sentry/struct.ClientOptions.html).

`main.rs`

```rust
let _guard = sentry::init((
    "___PUBLIC_DSN___",
    sentry::ClientOptions {
        enable_metrics: false,
        ..Default::default()
    },
));
```

## [Default Attributes](https://docs.sentry.io/platforms/rust/guides/actix-web/metrics.md#default-attributes)

Sentry automatically attaches these attributes to every metric:

| Attribute                            | Description                             | When Present                                       |
| ------------------------------------ | --------------------------------------- | -------------------------------------------------- |
| `sentry.sdk.name`                    | SDK name                                | Always                                             |
| `sentry.sdk.version`                 | SDK version                             | Always                                             |
| `sentry.environment`                 | Environment from SDK configuration      | If configured                                      |
| `sentry.release`                     | Release from SDK configuration          | If configured                                      |
| `server.address`                     | Server name from SDK configuration      | If configured                                      |
| `user.id`, `user.name`, `user.email` | User identifiers from the current scope | If a user is set and `send_default_pii` is enabled |
