docs: review and fixes
This commit is contained in:
@@ -8,31 +8,36 @@ Error Reporting With Sentry
|
||||
|
||||
## Introduction
|
||||
|
||||
While one always tries to create apps that are free of bugs, they’re sure to crop up from time to time. Since buggy apps lead to unhappy users and customers, it’s important to understand how often your users experience bugs and where those bugs occur. That way, you can prioritize the bugs with the highest impact and work to fix them.
|
||||
How can you determine how often your users experiences bugs? Whenever an error occurs, create a report containing the error that occurred and the associated stacktrace. You can then send the report to an error tracking service, such as Sentry, Fabric, or Rollbar.
|
||||
The error tracking service aggregates all of the crashes your users experience and groups them together. This allows you to know how often your app fails and where the users run into trouble.
|
||||
While one always tries to create apps that are free of bugs, they're sure to crop up from time to time. Since buggy apps lead to unhappy users and customers, it's important to understand how often your users experience bugs and where those bugs occur. That way, you can prioritize the bugs with the highest impact and work to fix them.
|
||||
|
||||
In this guide, learn how to report errors to the [Sentry](https://sentry.io/welcome/) crash reporting service using the following steps:
|
||||
Whenever an error occurs, create a report containing the error that occurred and the associated stack trace. You can then send the report to an error tracking service, such as [Sentry](https://sentry.io/), [Rollbar](https://rollbar.com/), or [Firebase Crashlytics](https://firebase.google.com/docs/crashlytics).
|
||||
|
||||
### 1. Get a DSN from Sentry
|
||||
Before reporting errors to Sentry, you need a “DSN” to uniquely identify your app with the Sentry.io service.
|
||||
The error tracking service aggregates all of the crashes your users experience and groups them together. This allows you to know how often your app fails and where your users run into trouble.
|
||||
|
||||
In this guide, learn how to report Stream Chat errors to the [Sentry](https://sentry.io/welcome/) crash reporting service using the following steps.
|
||||
|
||||
### 1. Get a DSN From Sentry
|
||||
|
||||
Before reporting errors to Sentry, you need a “DSN” to uniquely identify your app with the Sentry service:
|
||||
To get a DSN, use the following steps:
|
||||
|
||||
* [Create an account with Sentry](https://sentry.io/signup/).
|
||||
* Log in to the account.
|
||||
* Create a new Flutter project.
|
||||
* Copy the code snippet that includes the DSN.
|
||||
- [Create an account with Sentry](https://sentry.io/signup/).
|
||||
- Log in to the account.
|
||||
- Create a new Flutter project.
|
||||
- Copy the code snippet that includes the DSN.
|
||||
|
||||
### 2. Import the Sentry package
|
||||
Import the `sentry_flutter` package into the app. The sentry package makes it easier to send error reports to the Sentry error tracking service.
|
||||
|
||||
Import the `sentry_flutter` package into your app. The sentry package makes it easier to send error reports to the Sentry error tracking service.
|
||||
|
||||
```yaml
|
||||
dependencies:
|
||||
sentry_flutter: <latest_version>
|
||||
```
|
||||
|
||||
### 3. Initialize the SDK to capture different unhandled errors automatically
|
||||
### 3. Initialize the Sentry SDK
|
||||
|
||||
Initialize the SDK to capture different unhandled errors automatically.
|
||||
|
||||
```dart
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
@@ -45,7 +50,7 @@ Future<void> main() async {
|
||||
}
|
||||
```
|
||||
|
||||
Or, if you want to run your app in your own error zone runZonedGuarded:
|
||||
Or, if you want to run your app in your own error zone, use `runZonedGuarded`:
|
||||
|
||||
```dart
|
||||
void main() async {
|
||||
@@ -55,7 +60,7 @@ void main() async {
|
||||
// In development mode, simply print to console.
|
||||
FlutterError.dumpErrorToConsole(details);
|
||||
} else {
|
||||
// In production mode, report to the application zone to report to sentry.
|
||||
// In production mode, report to the application zone to report to Sentry.
|
||||
Zone.current.handleUncaughtError(details.exception, details.stack!);
|
||||
}
|
||||
};
|
||||
@@ -63,7 +68,7 @@ void main() async {
|
||||
Future<void> _reportError(dynamic error, StackTrace stackTrace) async {
|
||||
// Print the exception to the console.
|
||||
if (kDebugMode) {
|
||||
// Print the full stacktrace in debug mode.
|
||||
// Print the full stack trace in debug mode.
|
||||
print(stackTrace);
|
||||
return;
|
||||
} else {
|
||||
@@ -84,13 +89,13 @@ void main() async {
|
||||
}
|
||||
```
|
||||
|
||||
Alternatively, you can pass the DSN to Flutter using the dart-define tag:
|
||||
Alternatively, you can pass the DSN to Flutter using the **dart-define** tag:
|
||||
|
||||
```dart
|
||||
```bash
|
||||
--dart-define SENTRY_DSN=https://example@sentry.io/example
|
||||
```
|
||||
|
||||
### 4. Integration with StreamChat applications
|
||||
### 4. Integration With StreamChat Applications
|
||||
|
||||
Override the default `logHandlerFunction` to send errors to Sentry.
|
||||
|
||||
@@ -98,7 +103,7 @@ Override the default `logHandlerFunction` to send errors to Sentry.
|
||||
void sampleAppLogHandler(LogRecord record) async {
|
||||
if (kDebugMode) StreamChatClient.defaultLogHandler(record);
|
||||
|
||||
// report errors to sentry
|
||||
// Report errors to Sentry
|
||||
if (record.error != null || record.stackTrace != null) {
|
||||
await Sentry.captureException(
|
||||
record.error,
|
||||
@@ -119,18 +124,21 @@ StreamChatClient buildStreamChatClient(
|
||||
}
|
||||
```
|
||||
|
||||
### 5. Capture errors programmatically
|
||||
### 5. Capture Errors Programmatically
|
||||
|
||||
Besides the automatic error reporting that Sentry generates by importing and initializing the SDK,
|
||||
you can use the API to report errors to Sentry:
|
||||
you can use the API to manually report errors to Sentry:
|
||||
|
||||
```dart
|
||||
await Sentry.captureException(exception, stackTrace: stackTrace);
|
||||
```
|
||||
|
||||
For more information, see the [Sentry API](https://pub.dev/documentation/sentry_flutter/latest/sentry_flutter/sentry_flutter-library.html) docs on pub.dev.
|
||||
For more information, see the [Sentry API](https://pub.dev/documentation/sentry_flutter/latest/sentry_flutter/sentry_flutter-library.html) docs on Pub.
|
||||
|
||||
### Complete Example
|
||||
|
||||
### Complete example
|
||||
To view a working example, see the [Stream Sample app](https://github.com/GetStream/flutter-samples/tree/main/packages/stream_chat_v1).
|
||||
|
||||
### Learn more
|
||||
Extensive documentation about using the Sentry SDK can be found on [Sentry’s site](https://docs.sentry.io/platforms/flutter/).
|
||||
### Learn More
|
||||
|
||||
Extensive documentation about using the Sentry SDK can be found on [Sentry's site](https://docs.sentry.io/platforms/flutter/).
|
||||
|
||||
Reference in New Issue
Block a user