Sentry for Flutter

Learn how to set up Sentry in your Flutter app, capture your first events, and view them in Sentry.

Set up with Sentry CLI
curl https://cli.sentry.dev/install -fsS | bash

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 minSdk to 26 or 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:

Copied
brew install getsentry/tools/sentry-wizard && sentry-wizard -i flutter

This will patch your project and configure the SDK. Logs and Application Metrics are enabled by default in SDK v10, and you'll learn how to send them in steps #2 and #3. 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 following tasks will be performed by the Sentry Wizard
  • Update your pubspec.yaml with the sentry_flutter and sentry_dart_plugin packages.
  • Create a sentry.properties file (gitignored) with a Sentry CLI auth token.
  • Prompt you for optional features and patch main.dart with SentryFlutter.init.
  • Add a sample exception that is captured when the app starts so you can verify the setup.

Call Sentry.logger from your application code after initialization to send structured logs at different levels. You can add attributes to make logs easier to search and filter.

See Set Up Logs for all available logging methods and message formatting.

Copied
Sentry.logger.info('Order completed', attributes: {
  'order_id': SentryAttribute.string('12345'),
  'total': SentryAttribute.double(99.99),
});

Sentry.logger.warn('Slow operation detected');
Sentry.logger.error('Validation failed');

If you use the Dart logging package, add the sentry_logging integration to send its records to Sentry.

Call Sentry.metrics from your application code after initialization to send counters, gauges, and distributions. Add attributes to filter and group metrics in Sentry.

See Set Up Metrics for metric types, attributes, and configuration options.

Copied
Sentry.metrics.count('checkout.failed', 1);
Sentry.metrics.gauge('queue.depth', 42);
Sentry.metrics.distribution('api_latency', 187, unit: 'millisecond');

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:

Copied
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.

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).

Need help locating captured data in your Sentry project?
  • Open the Issues page and select an error from the issues list to view the full details and context of this error. For more details, see the Issue Details documentation.
  • Open the Traces page and select a trace to reveal more information about each span, its duration, and any errors. For an interactive UI walkthrough, click here.
  • Open the Replays page and select an entry from the list to get a detailed view where you can replay the interaction and get more information to help you troubleshoot.
  • Open the Logs page and filter by service, environment, or search keywords to view log entries from your application. For an interactive UI walkthrough, click here.
  • Open the Application Metrics page to view and analyze your metrics. For more details, see this interactive walkthrough.

At this point, you should have integrated Sentry into your Flutter application. Here's what to explore next:

Are you having problems setting up the SDK?
Was this helpful?
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").