[ Web Proxy ]
URL:
Viewing: https://pub.dev/packages/sentry [Back]  [Original]

sentry | Dart package
[] [] [] []

A crash reporting library for Dart that sends crash reports to Sentry.io. This library supports Dart VM and Web. For Flutter consider sentry_flutter instead.

More...

https%3A%2F%2Fsentry-brand.storage.googleapis.com%2Fsentry-logo-black.png [https%3A%2F%2Fsentry-brand.storage.googleapis.com%2Fsentry-logo-black.png]

Sentry SDK for Dart #

package build pub likes popularity pub points
sentry build [build] pub package [pub package] likes [likes] popularity [popularity] pub points [pub points]

Pure Dart SDK used by any Dart application like AngularDart, CLI and Server.

Flutter

For Flutter applications there's sentry_flutter which builds on top of this package. That will give you native crash support (for Android and iOS), release health, offline caching and more.

Usage

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

  • Follow the installing instructions on pub.dev.

  • Initialize the Sentry SDK using the DSN issued by Sentry.io:

import 'package:sentry/sentry.dart';

Future<void> main() async {
  await Sentry.init(
    (options) {
      options.dsn = 'https://example@sentry.io/example';
    },
    appRunner: initApp, // Init your App.
  );
}

void initApp() {
  // your app code
}

Or, if you want to run your app in your own error zone [runZonedGuarded]:

import 'dart:async';

import 'package:sentry/sentry.dart';

Future<void> main() async {
  runZonedGuarded(() async {
    await Sentry.init(
      (options) {
        options.dsn = 'https://example@sentry.io/example';
      },
    );

    // Init your App.
    initApp();
  }, (exception, stackTrace) async {
    await Sentry.captureException(exception, stackTrace: stackTrace);
  });
}

void initApp() {
  // your app code
}

The SentryHttpClient can be used as a standalone client like this:

import 'package:sentry/sentry.dart';

var client = SentryHttpClient();
try {
 var uriResponse = await client.post('https://example.com/whatsit/create',
     body: {'name': 'doodle', 'color': 'blue'});
 print(await client.get(uriResponse.bodyFields['uri']));
} finally {
 client.close();
}

The SentryHttpClient can also be used as a wrapper for your own HTTP Client:

import 'package:sentry/sentry.dart';
import 'package:http/http.dart' as http;

final myClient = http.Client();

var client = SentryHttpClient(client: myClient);
try {
var uriResponse = await client.post('https://example.com/whatsit/create',
     body: {'name': 'doodle', 'color': 'blue'});
 print(await client.get(uriResponse.bodyFields['uri']));
} finally {
 client.close();
}
Reporting Bad HTTP Requests as Errors

The SentryHttpClient can also catch exceptions that may occur during requests such as SocketExceptions. This is currently an opt-in feature. The following example shows how to enable it.

import 'package:sentry/sentry.dart';

var client = SentryHttpClient();
try {
var uriResponse = await client.post('https://example.com/whatsit/create',
     body: {'name': 'doodle', 'color': 'blue'});
 print(await client.get(uriResponse.bodyFields['uri']));
} finally {
 client.close();
}

Furthermore you can track HTTP requests which are considered bad by you. The following example shows how to do it. It captures exceptions for each request with a status code range from 400 to 404 and also for 500.

import 'package:sentry/sentry.dart';

var client = SentryHttpClient(
  failedRequestStatusCodes: [
    SentryStatusCode.range(400, 404),
    SentryStatusCode(500),
  ],
);

try {
var uriResponse = await client.post('https://example.com/whatsit/create',
     body: {'name': 'doodle', 'color': 'blue'});
 print(await client.get(uriResponse.bodyFields['uri']));
} finally {
 client.close();
}
Performance Monitoring for HTTP Requests

The SentryHttpClient starts a span out of the active span bound to the scope for each HTTP Request. This is currently an opt-in feature. The following example shows how to enable it.

import 'package:sentry/sentry.dart';

final transaction = Sentry.startTransaction(
  'webrequest',
  'request',
  bindToScope: true,
);

var client = SentryHttpClient();
try {
var uriResponse = await client.post('https://example.com/whatsit/create',
     body: {'name': 'doodle', 'color': 'blue'});
 print(await client.get(uriResponse.bodyFields['uri']));
} finally {
 client.close();
}

await transaction.finish(status: SpanStatus.ok());

Read more about Automatic Instrumentation.

Tips for catching errors
  • Use a try/catch block.
  • Use a catchError block for Futures, examples on dart.dev.
  • The SDK already runs your callback on an error handler, e.g. using runZonedGuarded, events caught by the runZonedGuarded are captured automatically.
  • Current Isolate errors which is the equivalent of a main or UI thread, are captured automatically (Only for non-Web Apps).
  • For your own Isolates, add an Error Listener by calling isolate.addSentryErrorListener().

Resources

Resources

580
likes
160
points
1.77M
downloads

Documentation

Documentation
API reference

Publisher

verified publisher [verified publisher]sentry.io

Weekly Downloads

A crash reporting library for Dart that sends crash reports to Sentry.io. This library supports Dart VM and Web. For Flutter consider sentry_flutter instead.

Homepage
Repository (GitHub)
View/report issues
Contributing

License

[]BSD-3-Clause (license)

Dependencies

ffi, http, meta, stack_trace, uuid, web

More

Packages that depend on sentry

Metadata

580
likes
160
points
1.77M
downloads

Documentation

Documentation
API reference

Publisher

verified publisher [verified publisher]sentry.io

Weekly Downloads

A crash reporting library for Dart that sends crash reports to Sentry.io. This library supports Dart VM and Web. For Flutter consider sentry_flutter instead.

Homepage
Repository (GitHub)
View/report issues
Contributing

License

[]BSD-3-Clause (license)

Dependencies

ffi, http, meta, stack_trace, uuid, web

More

Packages that depend on sentry

Back

Dart languageReport packagePolicyTermsAPI TermsSecurityPrivacyHelpRSS [RSS]bug report [bug report]
Web Proxy Viewer  |  New URL  |  Original Page