sentry 3.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 99

Sentry.io client for Dart #

Build Status

Use this library in your Dart programs (Flutter for mobile, Flutter for web, command-line, and AngularDart) to report errors thrown by your program to https://sentry.io error tracking service.

Versions #

Versions 3.0.0 and higher support Flutter for mobile, Flutter for web, command-line, desktop, and AngularDart.

>=2.0.0 <3.0.0 is the range of versions that support Flutter for mobile and Dart VM only.

Versions <2.0.0 are deprecated.

Usage #

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

Add sentry dependency to your pubspec.yaml:

dependencies:
  sentry: ">=3.0.0 <4.0.0"

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

import 'package:sentry/sentry.dart';

final SentryClient sentry = new SentryClient(dsn: YOUR_DSN);

In an exception handler, call captureException():

main() async {
  try {
    doSomethingThatMightThrowAnError();
  } catch(error, stackTrace) {
    await sentry.captureException(
      exception: error,
      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 runZoned.

    var sentry = SentryClient(dsn: "https://...");
    // Run the whole app in a zone to capture all uncaught errors.
    runZoned(
      () => runApp(MyApp()),
      onError: (Object error, StackTrace stackTrace) {
        try {
          sentry.captureException(
            exception: error,
            stackTrace: stackTrace,
          );
          print('Error sent to sentry.io: $error');
        } catch (e) {
          print('Sending report to sentry.io failed: $e');
          print('Original error: $error');
        }
      },
    );
    
  • For Flutter-specific errors (such as layout failures), use FlutterError.onError. For example:

    var sentry = SentryClient(dsn: "https://...");
    FlutterError.onError = (details, {bool forceReport = false}) {
      try {
        sentry.captureException(
          exception: details.exception,
          stackTrace: details.stack,
        );
      } catch (e) {
        print('Sending report to sentry.io failed: $e');
      } finally {
        // Also use Flutter's pretty error logging to the device's console.
        FlutterError.dumpErrorToConsole(details, forceReport: forceReport);
      }
    };
    
  • Use Isolate.current.addErrorListener to capture uncaught errors in the root zone.

Found a bug? #

Please file it at https://github.com/flutter/flutter/issues/new

package:sentry changelog #

3.0.1 #

  • Add support for Contexts in Sentry events

3.0.0+1 #

  • pubspec.yaml and example code clean-up.

3.0.0 #

  • Support Web
    • SentryClient from package:sentry/sentry.dart with conditional import
    • SentryBrowserClient for web from package:sentry/browser_client.dart
    • SentryIOClient for VM and Flutter from package:sentry/io_client.dart

2.3.1 #

  • Support non-standard port numbers and paths in DSN URL.

2.3.0 #

2.2.0 #

  • Add a stackFrameFilter argument to SentryClient's capture method (96be842).
  • Clean-up code using pre-Dart 2 API (91c7706, b01ebf8).

2.1.1 #

2.1.0 #

  • Support DNS format without secret key.
  • Remove dependency on package:quiver.
  • The clock argument to SentryClient constructor should now be ClockProvider (but still accepts Clock for backwards compatibility).

2.0.2 #

  • Add support for user context in Sentry events.

2.0.1 #

  • Invert stack frames to be compatible with Sentry's default culprit detection.

2.0.0 #

  • Fixed deprecation warnings for Dart 2
  • Refactored tests to work with Dart 2

1.0.0 #

  • first and last Dart 1-compatible release (we may fix bugs on a separate branch if there's demand)
  • fix code for Dart 2

0.0.6 #

  • use UTC in the timestamp field

0.0.5 #

  • remove sub-seconds from the timestamp

0.0.4 #

  • parse and report async gaps in stack traces

0.0.3 #

  • environment attributes
  • auto-generate event_id and timestamp for events

0.0.2 #

  • parse and report stack traces
  • use x-sentry-error HTTP response header
  • gzip outgoing payloads by default

0.0.1 #

  • basic ability to send exception reports to Sentry.io

example/README.md

package:sentry example

The example in this directory throws an error and sends it to Sentry.io. Use it as a source of example code, or to smoke-test your Sentry.io configuration.

To use the example, create a Sentry.io account and get a DSN for your project. Then run the following command, replacing "{DSN}" with the one you got from Sentry.io:

dart example/main.dart {DSN}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  sentry: ^3.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:sentry/sentry.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
97
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
99
Learn more about scoring.

We analyzed this package on Jan 24, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

Fix lib/src/base.dart. (-0.50 points)

Analysis of lib/src/base.dart reported 1 hint:

line 894 col 31: Use isNotEmpty instead of length

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
http >=0.11.0 <2.0.0 0.12.0+4
meta >=1.0.0 <2.0.0 1.1.8
pedantic >=1.8.0 <2.0.0 1.9.0
stack_trace >=1.0.0 <2.0.0 1.9.3
usage >=3.0.0 <4.0.0 3.4.1
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
path 1.6.4
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
args >=0.13.0 <2.0.0
mockito >=2.0.0 <4.0.0
test >=0.12.0 <2.0.0
yaml >=2.1.0 <3.0.0