---
title: "Application 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/javascript/guides/electron/metrics/
---

# Set Up Metrics | Sentry for Electron

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

## [Prerequisites](https://docs.sentry.io/platforms/javascript/guides/electron/metrics.md#prerequisites)

Metrics are supported in Electron SDK version `7.5.0` and above.

## [Usage](https://docs.sentry.io/platforms/javascript/guides/electron/metrics.md#usage)

### [Metric Types](https://docs.sentry.io/platforms/javascript/guides/electron/metrics.md#metric-types)

| Type           | Use For                                      |
| -------------- | -------------------------------------------- |
| `count`        | Events (orders, clicks, API calls)           |
| `gauge`        | Current values (queue depth, connections)    |
| `distribution` | Value ranges (response times, payload sizes) |

No setup required beyond SDK initialization.

```javascript
import * as Sentry from "___SDK_PACKAGE___";

// Count occurrences
Sentry.metrics.count("orders_created", 1);

// Track current values
Sentry.metrics.gauge("active_connections", 42);

// Track distributions
Sentry.metrics.distribution("api_latency", 187, {
  unit: "millisecond",
});
```

### [Attributes](https://docs.sentry.io/platforms/javascript/guides/electron/metrics.md#attributes)

#### [Filtering and Grouping](https://docs.sentry.io/platforms/javascript/guides/electron/metrics.md#filtering-and-grouping)

Attributes let you filter and group metrics in Sentry. Use them for:

* Environment segmentation
* Feature flag tracking
* User tier analysis

Each metric has a **2KB size limit**. If you exceed this, the metric will be dropped.

```javascript
Sentry.metrics.count("api_calls", 1, {
  attributes: {
    endpoint: "/api/orders",
    user_tier: "pro",
    region: "us-west",
    user_id: user.id,
    order_id: order.id,
  },
});
```

#### [Scope Attributes](https://docs.sentry.io/platforms/javascript/guides/electron/metrics.md#scope-attributes)

With version `10.33.0`+, use scope APIs to set attributes that apply to all metrics while the scope is active.

Supported types: `string`, `number`, `boolean`

```javascript
Sentry.getGlobalScope().setAttributes({
  is_admin: true,
  auth_provider: "google",
});

Sentry.withScope((scope) => {
  scope.setAttribute("step", "authentication");

  // All scope attributes are added
  Sentry.metrics.count("clicks", 1);
  Sentry.metrics.gauge("time_since_refresh", 4, { unit: "hour" });
});
```

#### [Units](https://docs.sentry.io/platforms/javascript/guides/electron/metrics.md#units)

For `gauge` and `distribution` metrics, specify a unit to help Sentry display values in a human-readable format.

Common units: `millisecond`, `second`, `byte`, `kilobyte`, `megabyte`. See [supported units](https://develop.sentry.dev/sdk/foundations/data-model/attributes/#units) for the full list.

```javascript
Sentry.metrics.distribution("response_time", 187.5, {
  unit: "millisecond",
});

Sentry.metrics.gauge("memory_usage", 1024, {
  unit: "byte",
});
```

## [Options](https://docs.sentry.io/platforms/javascript/guides/electron/metrics.md#options)

### [beforeSendMetric](https://docs.sentry.io/platforms/javascript/guides/electron/metrics.md#beforesendmetric)

Filter or modify metrics before sending. Return `null` to drop a metric.

```javascript
Sentry.init({
  dsn: "___PUBLIC_DSN___",
  beforeSendMetric: (metric) => {
    // Drop specific metrics
    if (metric.name === "debug_metric") {
      return null;
    }

    // Add attributes
    metric.attributes = {
      ...metric.attributes,
      processed: true,
    };

    return metric;
  },
});
```

### [Disable Metrics](https://docs.sentry.io/platforms/javascript/guides/electron/metrics.md#disable-metrics)

Set `enableMetrics: false` to disable metrics collection entirely.

### [Flush Metrics](https://docs.sentry.io/platforms/javascript/guides/electron/metrics.md#flush-metrics)

Metrics are buffered and sent periodically. Use this snippet to flush immediately:

```javascript
// Disable metrics
Sentry.init({
  dsn: "___PUBLIC_DSN___",
  enableMetrics: false,
});

// Flush all pending metrics
await Sentry.flush();
```

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

By default the SDK will attach the following attributes to a metric:

* `environment`: The environment set in the SDK if defined. This is sent from the SDK as `sentry.environment`.
* `release`: The release set in the SDK if defined. This is sent from the SDK as `sentry.release`.
* `sdk.name`: The name of the SDK that sent the metric. This is sent from the SDK as `sentry.sdk.name`.
* `sdk.version`: The version of the SDK that sent the metric. This is sent from the SDK as `sentry.sdk.version`.

### [User Attributes](https://docs.sentry.io/platforms/javascript/guides/electron/metrics.md#user-attributes)

If user information is available in the current scope, the following attributes are added to the log:

* `user.id`: The user ID.
* `user.name`: The username.
* `user.email`: The email address.

### [Renderer Process Attributes](https://docs.sentry.io/platforms/javascript/guides/electron/metrics.md#renderer-process-attributes)

The SDK will attach renderer process information as attributes:

* `browser.name` (added during ingestion)
* `browser.version` (added during ingestion)
* `sentry.replay_id`: The replay id of the session replay that was active when the metric was collected.

## [Integrations](https://docs.sentry.io/platforms/javascript/guides/electron/metrics.md#integrations)

* [`elementTimingIntegration`](https://docs.sentry.io/platforms/javascript/guides/electron/configuration/integrations/elementtiming.md) — Automatically collect render and load timing distribution metrics for key UI elements using the browser's Element Timing API.

## [Related Features](https://docs.sentry.io/platforms/javascript/guides/electron/metrics.md#related-features)

* [Tracing](https://docs.sentry.io/platforms/javascript/guides/electron/tracing.md) — Drill down from metrics into related traces to understand performance patterns.

* [Logs](https://docs.sentry.io/platforms/javascript/guides/electron/logs.md) — Combine metrics with logs for full observability into your application's behavior.

* [Error Monitoring](https://docs.sentry.io/platforms/javascript/guides/electron/usage.md) — Use metrics alongside error tracking to understand the impact of issues.
