sentry 4.0.0-alpha.1 copy "sentry: ^4.0.0-alpha.1" to clipboard
sentry: ^4.0.0-alpha.1 copied to clipboard

outdated

A crash reporting library for Dart that sends crash reports to Sentry.io. This library supports Dart Native, and Flutter for mobile, web, and desktop.


Sentry SDK for Dart and Flutter #

Usage

Sign up for a Sentry.io account and get a DSN at http://sentry.io.

In your Dart code, import package:sentry/sentry.dart and initialize the Sentry SDK using the DSN issued by Sentry.io:

import 'package:sentry/sentry.dart';

Sentry.init((options) => options.dsn = 'https://[email protected]/add-your-dsn-here');

In an exception handler, call captureException():

import 'dart:async';
import 'package:sentry/sentry.dart';

void main() async {
  try {
    aMethodThatMightFail();
  } catch (exception, stackTrace) {
    await Sentry.captureException(
      exception,
      stackTrace: stackTrace,
    );
  }
}
Tips for catching errors
  • Use a try/catch block, like in the example above.
  • Create a Zone with an error handler, e.g. using runZonedGuarded.
import 'dart:async';

import 'package:flutter/material.dart';

import 'package:sentry/sentry.dart';

// Wrap your 'runApp(MyApp())' as follows:

Future<void> main() async {
  runZonedGuarded<Future<void>>(() async {
    runApp(MyApp());
  }, (exception, stackTrace) async {
    await Sentry.captureException(
      exception,
      stackTrace: stackTrace,
    );
  });
}
  • For Flutter-specific errors (such as layout failures), use FlutterError.onError. For example:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:sentry/sentry.dart';

// Wrap your 'runApp(MyApp())' as follows:

Future<void> main() async {
  FlutterError.onError = (FlutterErrorDetails details) async {
    await Sentry.captureException(
      details.exception,
      stackTrace: details.stack,
    );
  };
}
  • Use Isolate.current.addErrorListener to capture uncaught errors in the root zone.

Resources

  • Documentation
  • Forum
  • Discord
  • Stack Overflow
  • Twitter Follow
462
likes
0
pub points
97%
popularity

Publisher

verified publishersentry.io

A crash reporting library for Dart that sends crash reports to Sentry.io. This library supports Dart Native, and Flutter for mobile, web, and desktop.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

http, meta, stack_trace, uuid

More

Packages that depend on sentry