Set Up Metrics

Learn how to measure the data points you care about by configuring Metrics in your Symfony 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 Symfony are supported with Sentry Symfony SDK version 5.0.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.

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(
    key: 'button_click',
    value: 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 per page.
\Sentry\metrics()->distribution(
    key: 'page_load',
    value: 15.0,
    unit: \Sentry\Metrics\MetricsUnit::millisecond(),
    tags: [
        'page' => '/home',
    ],
)

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(
    key: 'user_view',
    value: 'jane',
    unit: \Sentry\Metrics\MetricsUnit::custom('username'),
    tags: [
        '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:

Copied
// Add '15.0' to a gauge used for tracking the loading times for a page.
\Sentry\metrics()->gauge(
    key: 'page_load',
    value: 15.0,
    unit: \Sentry\Metrics\MetricsUnit::millisecond(),
    tags: [
        'page' => '/home',
    ],
)

Timers can be used to measure the execution time of a specific block of code. They're implemented like distributions, but measured in seconds.

To emit a timer, do the following:

Copied
\Sentry\metrics()->timing(
    key: 'event_processing_time',
    callback: static fn() => process(),
);

To attach the code location of your metrics, set attach_metric_code_locations to true (the default is false).

config/packages/sentry.yaml
Copied
attach_metric_code_locations: true
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").