Set Up Metrics
Metrics are supported with Sentry Flutter SDK version 7.19.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.
Here's how to add Metrics to your application:
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) {
options.dsn = 'https://examplePublicKey@o0.ingest.sentry.io/0';
options.enableMetrics = true;
},
appRunner: initApp, // Init your App.
);
}
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:
Sentry.metrics().increment(
'button_login_click', // key
value: 1,
unit: null,
tags: {'provider': 'e-mail'},
);
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:
Sentry.metrics().distribution(
'image_download_duration', // key
value: 150,
unit: DurationSentryMeasurementUnit.milliSecond,
tags: {'type': 'thumbnail'},
);
Sets are useful for looking at unique occurrences and counting the unique elements you added.
To emit a set, do the following:
Sentry.metrics().set(
'user_view', // key
stringValue: 'jane',
unit: CustomSentryMeasurementUnit('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:
Sentry.metrics().gauge(
'page_load', // key
value: 15,
unit: DurationSentryMeasurementUnit.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:
Sentry.metrics().timing('load_user_profile', function: () {
//db.load(); ...
});
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").
- Package:
- pub:sentry_flutter
- Version:
- 8.0.0
- Repository:
- https://github.com/getsentry/sentry-dart
- API Documentation:
- https://pub.dev/documentation/sentry_flutter/latest/