Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions develop-docs/sdk/telemetry/metrics.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
title: Metrics
description: Counter, gauge, and distribution metrics sent as batched trace_metric envelope items.
spec_id: sdk/telemetry/metrics
spec_version: 2.11.1
spec_version: 3.0.0
spec_status: stable
spec_depends_on:
- id: sdk/foundations/transport/envelopes
version: ">=1.0.0"
- id: sdk/foundations/state-management/scopes/attributes
version: ">=1.0.0"
spec_changelog:
- version: 3.0.0
date: 2026-09-28
summary: Removed the global metrics enablement option; retained explicit opt-in for integrations
- version: 2.11.1
date: 2026-09-28
summary: Removed obsolete experimental namespace guidance and example from the stable spec
Expand Down Expand Up @@ -110,20 +113,19 @@ An SDK **SHOULD** implement [Tracing without Performance](/sdk/foundations/trace

</Alert>

<SpecSection id="processing-pipeline" status="stable" since="2.0.0">
<SpecSection id="processing-pipeline" status="stable" since="3.0.0">

### Processing Pipeline

Metric processing **MUST** follow this order:

1. Capture metric via [Public APIs](#metrics-module) (e.g. `Sentry.metrics.count`).
2. Check if metrics are disabled as per `enableMetrics`/`enable_metrics` configuration — if so, skip the rest of the steps.
3. Pass the metric to Hub/Scope via a generic method (e.g., `captureMetric(metric)`).
4. Pass the metric to the Client via a generic method (e.g., `captureMetric(metric)`).
5. Process captured metric (attach default attributes as per [Default Attributes](#default-attributes)).
6. Run `beforeSendMetric`/`before_send_metric` to filter or modify the metric.
7. Add metric to buffer/batch processor as detailed in [Buffering](#buffering).
8. At time of flushing buffer, send array of metrics to Sentry via `trace_metric` envelope, apply rate limiting as per [Data Category and Rate Limiting](#data-category-and-rate-limiting).
2. Pass the metric to Hub/Scope via a generic method (e.g., `captureMetric(metric)`).
3. Pass the metric to the Client via a generic method (e.g., `captureMetric(metric)`).
4. Process captured metric (attach default attributes as per [Default Attributes](#default-attributes)).
5. Run `beforeSendMetric`/`before_send_metric` to filter or modify the metric.
6. Add metric to buffer/batch processor as detailed in [Buffering](#buffering).
7. At time of flushing buffer, send array of metrics to Sentry via `trace_metric` envelope, apply rate limiting as per [Data Category and Rate Limiting](#data-category-and-rate-limiting).

</SpecSection>

Expand Down Expand Up @@ -246,13 +248,11 @@ If `debug` is set to `true` in SDK init, calls to the Sentry metrics API **SHOUL

</SpecSection>

<SpecSection id="auto-emitted-metrics" status="candidate" since="2.7.0">
<SpecSection id="auto-emitted-metrics" status="candidate" since="3.0.0">

### Auto-Emitted Metrics

Metrics emitted via the [public API](#metrics-module) are opt-out. The `enableMetrics`/`enable_metrics` option **MUST** act as a general kill switch for all metrics sent to Sentry — when set to `false`, no metrics **MUST** be sent, regardless of whether they originate from the public API, auto-emitting integrations, or third-party bindings.

However, metrics that are **automatically emitted by integrations or libraries** without an explicit user call follow different rules because they can generate unexpected volume and cost.
Metrics that are **automatically emitted by integrations or libraries** without an explicit user call require opt-in because they can generate unexpected volume and cost.

**Integrations that auto-emit metrics** — An SDK integration that automatically captures metrics (e.g., recording HTTP request durations, database query counts, or runtime resource usage) **MUST** be opt-in. The integration **MUST NOT** emit any metrics unless the user explicitly enables it. The opt-in mechanism **MAY** be a dedicated integration-level option or requiring the user to explicitly add the integration.

Expand Down Expand Up @@ -356,16 +356,16 @@ Each metric in the `items` array is a JSON object with the following fields:

## Public API

<SpecSection id="initialization-options" status="stable" since="2.0.0">
<SpecSection id="initialization-options" status="stable" since="3.0.0">

### Initialization Options

SDKs **MUST** expose the following configuration options:

- `enableMetrics`/`enable_metrics` — a boolean flag to control if metric envelopes will be generated and sent to Sentry. If `false`, the SDK **MUST NOT** send metrics. Defaults to `true`.
SDKs **MUST** expose the following configuration option:

- `beforeSendMetric`/`before_send_metric` — an **OPTIONAL** function that takes a metric object and returns a metric object. Called before sending the metric to Sentry. Can be used to modify the metric or prevent it from being sent (by returning `null`/`None`).

SDKs **SHOULD NOT** provide an API whose sole purpose is to disable all metrics.

</SpecSection>

<SpecSection id="metrics-module" status="stable" since="2.0.0">
Expand Down
Loading