Sentry for Flutter
Learn how to set up Sentry in your Flutter app, capture your first errors and traces, and view them in Sentry.
Use curl to download, read and follow https://skills.sentry.dev/instrument to set up the Sentry Flutter SDK.These instructions use Sentry Flutter SDK v10. You need:
- A Sentry account and project
- A Flutter application using Flutter 3.44.0 and Dart 3.12.0 or later
- Android API 26 or later for Android apps. Set your app's
minSdkto26or higher. - iOS 15.0 or macOS 12.0 or later for Apple apps, with Swift Package Manager enabled
For an existing Sentry integration, review the migration guide before upgrading to v10.
Sentry captures data by using an SDK within your application's runtime.
We recommend installing the SDK through our Sentry Wizard. Run one of the following commands inside your project directory:
brew install getsentry/tools/sentry-wizard && sentry-wizard -i flutter
brew install getsentry/tools/sentry-wizard && sentry-wizard -i flutter
$downloadUrl = "https://github.com/getsentry/sentry-wizard/releases/download/v5.1.0/sentry-wizard-win-x64.exe"
Invoke-WebRequest $downloadUrl -OutFile sentry-wizard.exe
./sentry-wizard.exe -i flutter
downloadUrl="https://github.com/getsentry/sentry-wizard/releases/download/v5.1.0/sentry-wizard-darwin-x64"
curl -L $downloadUrl -o sentry-wizard
chmod +x sentry-wizard
./sentry-wizard -i flutter
downloadUrl="https://github.com/getsentry/sentry-wizard/releases/download/v5.1.0/sentry-wizard-darwin-arm64"
curl -L $downloadUrl -o sentry-wizard
chmod +x sentry-wizard
./sentry-wizard -i flutter
downloadUrl="https://github.com/getsentry/sentry-wizard/releases/download/v5.1.0/sentry-wizard-linux-x64"
curl -L $downloadUrl -o sentry-wizard
chmod +x sentry-wizard
./sentry-wizard -i flutter
downloadUrl="https://github.com/getsentry/sentry-wizard/releases/download/v5.1.0/sentry-wizard-linux-arm64"
curl -L $downloadUrl -o sentry-wizard
chmod +x sentry-wizard
./sentry-wizard -i flutter
npx @sentry/wizard@latest -i flutter
This will patch your project and configure the SDK. You only need to patch the project once, then you can add the patched files to your version control system. If you prefer, you can also set up the SDK manually.
The wizard will prompt you to enable optional features. Select the same options here so this guide can show you how to verify them:
Let's test your setup and confirm that data reaches your Sentry project.
The wizard added a sample exception to main.dart that is captured when the app starts. Run your app to send it to Sentry:
flutter run
flutter run
After you've confirmed the issue in Sentry, remove the sample exception from main.dart so it isn't captured on every launch.
To test your tracing configuration, create a custom transaction and span:
final transaction = Sentry.startTransaction('test-transaction', 'task');
final span = transaction.startChild('test-span');
await span.finish();
await transaction.finish();
final transaction = Sentry.startTransaction('test-transaction', 'task');
final span = transaction.startChild('test-span');
await span.finish();
await transaction.finish();
Logs are enabled by default. Use the Sentry logger to send structured logs from anywhere in your application:
Sentry.logger.info('User clicked checkout button');
Sentry.logger.info('Order completed', attributes: {
'order_id': SentryAttribute.string('12345'),
'total': SentryAttribute.double(99.99),
});
Sentry.logger.warn('Warning message');
Sentry.logger.error('Error occurred');
Sentry.logger.info('User clicked checkout button');
Sentry.logger.info('Order completed', attributes: {
'order_id': SentryAttribute.string('12345'),
'total': SentryAttribute.double(99.99),
});
Sentry.logger.warn('Warning message');
Sentry.logger.error('Error occurred');
Metrics are enabled by default. Send test metrics from your app to verify that metrics are arriving in Sentry:
Sentry.metrics.count('checkout.failed', 1);
Sentry.metrics.gauge('queue.depth', 42);
Sentry.metrics.distribution('cart.amount_usd', 187.5);
Sentry.metrics.count('checkout.failed', 1);
Sentry.metrics.gauge('queue.depth', 42);
Sentry.metrics.distribution('cart.amount_usd', 187.5);
Now, head over to your project on Sentry.io to view the collected data (it takes a couple of moments for the data to appear).
At this point, you should have integrated Sentry into your Flutter application and should already be sending data to your Sentry project.
Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:
- Explore practical guides on what to monitor, log, track, and investigate after setup
- Continue to customize your configuration
- Add readable stack traces to errors
- Learn about the features of Sentry's Flutter SDK
- Add performance instrumentation to your app
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").