Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix readme
  • Loading branch information
marandaneto committed Oct 28, 2020
commit 2efe1ca23277687529b01d08b84b9aca3573316f
104 changes: 49 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ We also run CI against the Flutter `stable` and `beta` channels so you should be

##### Versions

Versions `3.0.1` and higher support [Flutter][flutter] (mobile, web, desktop),
command-line/server Dart VM, and [AngularDart][angular_sentry].
Versions `3.0.1` and higher support `Flutter` (mobile, web, desktop),
command-line/server Dart VM, and `AngularDart`.

Versions below `3.0.1` are deprecated.

Expand All @@ -52,29 +52,26 @@ Add `sentry` dependency to your `pubspec.yaml`:

```yaml
dependencies:
sentry: ^4.0.0
sentry: ">=3.0.1 <4.0.0"
```

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

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

Sentry.init((options) => options.dsn = '___PUBLIC_DSN___');
final SentryClient sentry = new SentryClient(dsn: YOUR_DSN);
```

In an exception handler, call `captureException()`:

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

void main() async {
main() async {
try {
aMethodThatMightFail();
} catch (exception, stackTrace) {
await Sentry.captureException(
exception,
doSomethingThatMightThrowAnError();
} catch(error, stackTrace) {
await sentry.captureException(
exception: error,
stackTrace: stackTrace,
);
}
Expand All @@ -84,48 +81,45 @@ void main() async {
##### 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][run_zoned_guarded].

```dart
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][flutter_error]. For example:

```dart
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,
);
- Create a `Zone` with an error handler, e.g. using `runZonedGuarded`.

```dart
var sentry = SentryClient(dsn: "https://...");
// Run the whole app in a zone to capture all uncaught errors.
runZonedGuarded(
() => runApp(MyApp()),
(error, 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:

```dart
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.

Expand All @@ -135,4 +129,4 @@ Future<void> main() async {
* [![Forum](https://img.shields.io/badge/forum-sentry-green.svg)](https://forum.sentry.io/c/sdks)
* [![Discord](https://img.shields.io/discord/621778831602221064)](https://discord.gg/Ww9hbqr)
* [![Stack Overflow](https://img.shields.io/badge/stack%20overflow-sentry-green.svg)](https://stackoverflow.com/questions/tagged/sentry)
* [![Twitter Follow](https://img.shields.io/twitter/follow/getsentry?label=getsentry&style=social)](https://twitter.com/intent/follow?screen_name=getsentry)
* [![Twitter Follow](https://img.shields.io/twitter/follow/getsentry?label=getsentry&style=social)](https://twitter.com/intent/follow?screen_name=getsentry)
1 change: 0 additions & 1 deletion dart/README.md

This file was deleted.

95 changes: 95 additions & 0 deletions dart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<p align="center">
<a href="https://sentry.io" target="_blank" align="center">
<img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280">
</a>
<br />
</p>

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:

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

Sentry.init((options) => options.dsn = '___PUBLIC_DSN___');
```

In an exception handler, call `captureException()`:

```dart
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`.

```dart
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:

```dart
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](https://img.shields.io/badge/documentation-sentry.io-green.svg)](https://docs.sentry.io/platforms/flutter/)
* [![Forum](https://img.shields.io/badge/forum-sentry-green.svg)](https://forum.sentry.io/c/sdks)
* [![Discord](https://img.shields.io/discord/621778831602221064)](https://discord.gg/Ww9hbqr)
* [![Stack Overflow](https://img.shields.io/badge/stack%20overflow-sentry-green.svg)](https://stackoverflow.com/questions/tagged/sentry)
* [![Twitter Follow](https://img.shields.io/twitter/follow/getsentry?label=getsentry&style=social)](https://twitter.com/intent/follow?screen_name=getsentry)