Set Up Metrics

Learn how to measure the data points you care about by configuring Metrics in your JavaScript app.

Sentry Metrics is currently in open beta, so be gentle - features are still in-progress and may have bugs. We recognize the irony. For any questions or feedback, you can reach us on Discord or GitHub.

Metrics for JavaScript are supported with Sentry JavaScript SDK version 7.103.0 and above.

Sentry metrics help you pinpoint and solve issues that impact user experience and app performance by measuring the data points that are important to you. You can track things like processing time, event size, user signups, and conversion rates, then correlate them back to tracing data in order to get deeper insights and solve issues faster.

To configure metrics for your client-side code, add the metricsAggregatorIntegration to your Sentry.init call in your entry.client.tsx file.

Copied
// entry.client.tsx
Sentry.init({
  dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
  integrations: [
    Sentry.metrics.metricsAggregatorIntegration(),
  ],
});

To configure metrics for your server-side code, add the metricsAggregator experimental option to your Sentry.init call in your entry.server.tsx file.

Copied
// entry.server.tsx
Sentry.init({
  dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
  _experiments: {
    metricsAggregator: true,
  },
});

Counters are one of the more basic types of metrics and can be used to count certain event occurrences.

To emit a counter, do the following:

Copied
// Increment a counter by one for each button click.
Sentry.metrics.increment("button_click", 1, {
  tags: { browser: "Firefox", app_version: "1.0.0" },
});

Distributions help you get the most insights from your data by allowing you to obtain aggregations such as p90, min, max, and avg.

To emit a distribution, do the following:

Copied
// Add '15.0' to a distribution used for tracking the loading times for component.
Sentry.metrics.distribution("component_load_time", 15.0, {
  tags: { type: "important" },
  unit: "millisecond",
});

Sets are useful for looking at unique occurrences and counting the unique elements you added.

To emit a set, do the following:

Copied
// Add 'jane' to a set used for tracking the number of users that viewed a page.
Sentry.metrics.set("user_view", "jane");

Gauges let you obtain aggregates like min, max, avg, sum, and count. They can be represented in a more space-efficient way than distributions, but they can't be used to get percentiles. If percentiles aren't important to you, we recommend using gauges.

To emit a gauge, do the following:

Copied
// Add 2 to a gauge tracking CPU usage.
Sentry.metrics.gauge("cpu_usage", 34, {
  tags: { os: "MacOS" },
  unit: "percent",
});

You can pass a unit as a optional parameter of the third argument of the increment, distribution, set, and gauge methods.

Units augment metric values by giving meaning to what otherwise might be abstract numbers. Adding units also allows Sentry to offer controls - unit conversions, filters, and so on - based on those units. For values that are unitless, you can supply an empty string or none.

These following units are understood by the Sentry backend, but you can supply any arbitrary units you want.

  • nanosecond
  • microsecond
  • millisecond
  • second
  • minute
  • hour
  • day
  • week

  • bit
  • byte
  • kilobyte
  • kibibyte
  • megabyte
  • mebibyte
  • gigabyte
  • gibibyte
  • terabyte
  • tebibyte
  • petabyte
  • pebibyte
  • exabyte
  • exbibyte

  • ratio
  • percent

If you want to explore further, you can find details about supported units in our event ingestion documentation.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").