Skip to content

Commit

Permalink
Upgrade the Dart/Flutter SDK to v4 (#2599)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Nov 26, 2020
1 parent 5cb82c1 commit 013c875
Show file tree
Hide file tree
Showing 54 changed files with 515 additions and 176 deletions.
11 changes: 11 additions & 0 deletions src/includes/before-breadcrumb/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```dart
import 'package:sentry/sentry.dart';
Breadcrumb beforeBreadcrumb(Breadcrumb breadcrumb, dynamic hint) {
return 'a.spammy.Logger' == breadcrumb.category ? null : breadcrumb;
}
Future<void> main() async {
await Sentry.init((options) => options.beforeBreadcrumb = beforeBreadcrumb);
}
```
5 changes: 5 additions & 0 deletions src/includes/breadcrumbs-example/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```dart
import 'package:sentry/sentry.dart';
Sentry.addBreadcrumb(Breadcrumb(message: 'Authenticated user'));
```
14 changes: 14 additions & 0 deletions src/includes/capture-error/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
In Dart you can capture any exception object that you caught:

```dart
import 'package:sentry/sentry.dart';
try {
aMethodThatMightFail();
} catch (exception, stackTrace) {
await Sentry.captureException(
exception,
stackTrace: stackTrace,
);
}
```
12 changes: 0 additions & 12 deletions src/includes/capture-error/flutter.mdx

This file was deleted.

5 changes: 5 additions & 0 deletions src/includes/capture-message/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```dart
import 'package:sentry/sentry.dart';
await Sentry.captureMessage('Something went wrong');
```
3 changes: 0 additions & 3 deletions src/includes/capture-message/flutter.mdx

This file was deleted.

14 changes: 14 additions & 0 deletions src/includes/configuration/auto-session-tracking/flutter.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```dart
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) => options.enableAutoSessionTracking = true, // it's enabled by default
() {
// Run your App
runApp(MyApp());
},
);
}
```
11 changes: 11 additions & 0 deletions src/includes/configuration/before-breadcrumb-hint/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```dart
import 'package:sentry/sentry.dart';
Breadcrumb beforeBreadcrumb(Breadcrumb crumb, dynamic hint) {
return hint is MyHint ? null : crumb;
}
Future<void> main() async {
await Sentry.init((options) => options.beforeBreadcrumb = beforeBreadcrumb);
}
```
14 changes: 14 additions & 0 deletions src/includes/configuration/before-send-fingerprint/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```dart
import 'package:sentry/sentry.dart';
SentryEvent beforeSend(SentryEvent event, dynamic hint) {
if (event.exception is DatabaseException) {
event = event.copyWith(fingerprint: ['database-connection-error']);
}
return event;
}
Future<void> main() async {
await Sentry.init((options) => options.beforeSend = beforeSend);
}
```
13 changes: 13 additions & 0 deletions src/includes/configuration/before-send-hint/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
A `BiFunction<SentryEvent, Object, SentryEvent>` can be used to mutate, discard (return null), or return a completely new event.

```dart
import 'package:sentry/sentry.dart';
SentryEvent beforeSend(SentryEvent event, dynamic hint) {
return hint is MyHint ? null : event;
}
Future<void> main() async {
await Sentry.init((options) => options.beforeSend = beforeSend);
}
```
15 changes: 15 additions & 0 deletions src/includes/configuration/before-send/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
A `BiFunction<SentryEvent, Object, SentryEvent>` can be used to mutate, discard (return null), or return a completely new event.

```dart
import 'package:sentry/sentry.dart';
SentryEvent beforeSend(SentryEvent event, dynamic hint) {
// Modify the event here:
event = event.copyWith(serverName: null); // Don't send server names.
return event;
}
Future<void> main() async {
await Sentry.init((options) => options.beforeSend = beforeSend);
}
```
12 changes: 12 additions & 0 deletions src/includes/configuration/config-intro/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Options are passed to the `Sentry.init` method:

```dart
import 'package:sentry/sentry.dart';
Future<void> main() async {
await Sentry.init((options) => options
..dsn = '___PUBLIC_DSN___'
..release = 'my-project-name@2.3.12'
..environment = 'staging');
}
```
24 changes: 16 additions & 8 deletions src/includes/configuration/config-intro/flutter.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
Options are passed to the `SentryClient()` class:
Options are passed to the `SentryFlutter.init` method:

```dart
final sentry = SentryClient(
dsn: '___PUBLIC_DSN___',
environmentAttributes: const Event(
release: 'my-project-name@2.3.12',
environment: 'production',
)
);
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) => options
..dsn = '___PUBLIC_DSN___'
..release = 'my-project-name@2.3.12'
..environment = 'staging',
() {
// Run your App
runApp(MyApp());
},
);
}
```
1 change: 1 addition & 0 deletions src/includes/configuration/drain-example/flutter.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Flutter SDK for Android and iOS stores the Sentry events on the device's disk before shutdown.
8 changes: 8 additions & 0 deletions src/includes/configuration/sample-rate/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```dart
import 'package:sentry/sentry.dart';
Future<void> main() async {
// Capture only 25% of events
await Sentry.init((options) => options.sampleRate = 0.25);
}
```
14 changes: 14 additions & 0 deletions src/includes/configuration/session-tracking-interval/flutter.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```dart
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) => options.autoSessionTrackingIntervalMillis = 10000, // it's 30000 millis by default
() {
// Run your App
runApp(MyApp());
},
);
}
```
7 changes: 7 additions & 0 deletions src/includes/configure-scope/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```dart
import 'package:sentry/sentry.dart';
Sentry.configureScope((scope) => scope
..setTag('my-tag', 'my value')
..user = User(id: '42', email: 'john.doe@example.com'));
```
7 changes: 7 additions & 0 deletions src/includes/getting-started-config/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```dart
import 'package:sentry/sentry.dart';
Future<void> main() async {
await Sentry.init((options) => options.dsn = '___PUBLIC_DSN___');
}
```
16 changes: 16 additions & 0 deletions src/includes/getting-started-config/flutter.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```dart
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) => options.dsn = '___PUBLIC_DSN___',
() {
// Run your App
runApp(MyApp());
},
);
// or define SENTRY_DSN via Dart environment variable (--dart-define)
}
```
4 changes: 4 additions & 0 deletions src/includes/getting-started-install/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```yml {filename:pubspec.yaml}
dependencies:
sentry: ^4.0.0
```
4 changes: 4 additions & 0 deletions src/includes/getting-started-install/flutter.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```yml {filename:pubspec.yaml}
dependencies:
sentry_flutter: ^4.0.0
```
5 changes: 5 additions & 0 deletions src/includes/getting-started-primer/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Note>

_Pure Dart SDK used by any Dart application like AngularDart, CLI and Server, it enables reporting messages and errors._

</Note>
7 changes: 7 additions & 0 deletions src/includes/getting-started-primer/flutter.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Note>

_Sentry's Flutter SDK enables capturing sessions for Release Health, offline caching as well as reporting messages and errors._

_Sentry's Flutter SDK depends on the [Dart SDK](/platforms/dart/) and includes support to native crashes through Sentry's native SDKs (Android and iOS), It'll capture errors in the native layer, including Java, Kotlin, C and C++ code for `Android` and ObjC, Swift and C for `iOS`._

</Note>
12 changes: 12 additions & 0 deletions src/includes/getting-started-verify/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```dart
import 'package:sentry/sentry.dart';
try {
aMethodThatMightFail();
} catch (exception, stackTrace) {
await Sentry.captureException(
exception,
stackTrace: stackTrace,
);
}
```
8 changes: 8 additions & 0 deletions src/includes/sensitive-data/set-tag/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```dart
import 'package:sentry/sentry.dart';
Sentry.configureScope((scope) => scope.setTag(
'birthday',
checksumOrHash('08/12/1990'),
));
```
8 changes: 8 additions & 0 deletions src/includes/sensitive-data/set-user/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```dart
import 'package:sentry/sentry.dart';
Sentry.configureScope((scope) => scope.user = User(
id: clientUser.id,
username: clientUser.username,
));
```
9 changes: 9 additions & 0 deletions src/includes/set-context/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```dart
import 'package:sentry/sentry.dart';
final person = {
'name': 'Mighty Fighter',
'age': '19',
};
Sentry.configureScope((scope) => scope.setContexts('person', person));
```
13 changes: 0 additions & 13 deletions src/includes/set-context/flutter.mdx

This file was deleted.

7 changes: 7 additions & 0 deletions src/includes/set-environment/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```dart
import 'package:sentry/sentry.dart';
Future<void> main() async {
await Sentry.init((options) => options.environment = 'staging');
}
```
20 changes: 14 additions & 6 deletions src/includes/set-environment/flutter.mdx
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
```dart
import 'package:sentry/sentry.dart';
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) => options.environment = 'staging',
() {
// Run your App
runApp(MyApp());
},
);
// or define SENTRY_ENVIRONMENT via Dart environment variable (--dart-define)
}
final sentry = SentryClient(
environmentAttributes: const Event(
environment: 'production'
)
);
```
8 changes: 8 additions & 0 deletions src/includes/set-extra/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```dart
import 'package:sentry/sentry.dart';
Sentry.configureScope((scope) => scope.setExtra(
'character.name',
'Mighty Fighter',
));
```
9 changes: 0 additions & 9 deletions src/includes/set-extra/flutter.mdx

This file was deleted.

14 changes: 14 additions & 0 deletions src/includes/set-fingerprint/basic/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```dart
import 'package:sentry/sentry.dart';
SentryEvent beforeSend(SentryEvent event, dynamic hint) {
if (event.exception is DatabaseException) {
event = event.copyWith(fingerprint: ['database-connection-error']);
}
return event;
}
Future<void> main() async {
await Sentry.init((options) => options.beforeSend = beforeSend);
}
```
14 changes: 14 additions & 0 deletions src/includes/set-fingerprint/database-connection/dart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```dart
import 'package:sentry/sentry.dart';
SentryEvent beforeSend(SentryEvent event, dynamic hint) {
if (event.exception is DatabaseException) {
event = event.copyWith(fingerprint: ['database-connection-error']);
}
return event;
}
Future<void> main() async {
await Sentry.init((options) => options.beforeSend = beforeSend);
}
```
Loading

1 comment on commit 013c875

@vercel
Copy link

@vercel vercel bot commented on 013c875 Nov 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

Please sign in to comment.