Metrics are enabled by default. Once you initialize the SDK, you can send metrics using the Sentry.metrics APIs.
The metrics namespace exposes three methods that you can use to capture different types of metric information: count, gauge, and distribution.
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:
# Record five total button clicks
Sentry.metrics.count(
"button_click",
value: 5,
attributes: { 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:
# Add '15.0' to a distribution used for tracking the loading times per page.
Sentry.metrics.distribution(
"page_load",
15.0,
unit: "millisecond",
attributes: { page: "/home" }
)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:
# Add '15.0' to a gauge used for tracking the loading times for a page.
Sentry.metrics.gauge(
"page_load",
15.0,
unit: "millisecond",
attributes: { "page": "/home" }
)