Advanced Usage

Requirements

  • For the usage of the Dart SDK, the minimal required Dart SDK version is 2.12.0.

Automatic Breadcrumbs

To track automatic Breadcrumbs for HTTP requests, you can add a Sentry wrapper that does it automatically for you.

This is only possible if you are using the http.Client class from the http library.

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

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

final client = SentryHttpClient();
try {
  final url = 'https://example.com/whatsit/create';
  final response = await client.post(url, body: {
    'name': 'doodle',
    'color': 'blue',
  });
  print('Response body: ${response.body}');
} finally {
  client.close();
}

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

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

final myClient = http.Client();
final client = SentryHttpClient(client: myClient);
try {
  final url = 'https://example.com/whatsit/create';
  final response = await client.post(url, body: {
    'name': 'doodle',
    'color': 'blue',
  });
  print('Response body: ${response.body}');
} finally {
  client.close();
}

Tips for catching errors

  • Use a try/catch block
  • Use a catchError block for Futures
  • Isolate errors on the current Isolate which is the equivalent of a main/UI thread, e.g. using Isolate.current.addErrorListener, are captured automatically (Only for non-Web Apps).
  • For your own Isolates, add an ErrorListener and call Sentry.captureException
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").