Skip to content

Commit de145dd

Browse files
authored
feat(flutter): use wizard in getting started (#12792)
* Update index.mdx * add sendDefaultPii to getting started * formatting * use platformlink in dart data-collected page * Update data-collected.mdx * update denylist link * update wizard usage * add tabs for brew and npx * fix link
1 parent d5cd117 commit de145dd

File tree

2 files changed

+141
-3
lines changed

2 files changed

+141
-3
lines changed

docs/platforms/flutter/index.mdx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,26 @@ Select which Sentry features you'd like to install in addition to Error Monitori
3737

3838
Sentry captures data by using an SDK within your application's runtime. These are platform-specific and allow Sentry to have a deep understanding of how your application works.
3939

40-
```yml {filename:pubspec.yaml}
41-
dependencies:
42-
sentry_flutter: ^{{@inject packages.version('sentry.dart.flutter') }}
40+
To install, run `@sentry/wizard`:
41+
42+
```bash {tabTitle:brew}
43+
brew install getsentry/tools/sentry-wizard && sentry-wizard -i flutter
44+
```
45+
46+
```bash {tabTitle:npx}
47+
npx @sentry/wizard@latest -i flutter
4348
```
4449

50+
[Sentry Wizard](https://github.com/getsentry/sentry-wizard) will patch your project accordingly, though you can [set up manually](/platforms/flutter/manual-setup/) if you prefer. You only need to patch the project once. Then you can add the patched files to your version control system.
51+
52+
<Expandable title="The following tasks will be performed by the Sentry Wizard">
53+
54+
- Configure the SDK with your DSN and performance monitoring options in your main.dart file.
55+
- Update your `pubspec.yaml` with the `sentry_flutter` and `sentry_dart_plugin` packages.
56+
- Add an example error to verify your setup.
57+
58+
</Expandable>
59+
4560
## Configure
4661

4762
Configuration should happen as early as possible in your application's lifecycle.
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
---
2+
title: Manual Setup
3+
sidebar_order: 1
4+
description: "Learn how to set up the SDK manually."
5+
---
6+
7+
If you can't (or prefer not to) run the [automatic setup](/platforms/flutter/#install), you can follow the instructions below to configure your application manually.
8+
9+
## Install
10+
11+
<OnboardingOptionButtons
12+
options={[
13+
'error-monitoring',
14+
'performance',
15+
'profiling',
16+
]}
17+
/>
18+
19+
Sentry captures data by using an SDK within your application's runtime. These are platform-specific and allow Sentry to have a deep understanding of how your application works.
20+
21+
```yml {filename:pubspec.yaml}
22+
dependencies:
23+
sentry_flutter: ^{{@inject packages.version('sentry.dart.flutter') }}
24+
```
25+
26+
## Configure
27+
28+
Configuration should happen as early as possible in your application's lifecycle.
29+
30+
```dart {"onboardingOptions": {"performance": "8-10", "profiling": "11-14"}}
31+
import 'package:flutter/widgets.dart';
32+
import 'package:sentry_flutter/sentry_flutter.dart';
33+
34+
Future<void> main() async {
35+
await SentryFlutter.init(
36+
(options) {
37+
options.dsn = '___PUBLIC_DSN___';
38+
// Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
39+
// We recommend adjusting this value in production.
40+
options.tracesSampleRate = 1.0;
41+
// The sampling rate for profiling is relative to tracesSampleRate
42+
// Setting to 1.0 will profile 100% of sampled transactions:
43+
// Note: Profiling alpha is available for iOS and macOS since SDK version 7.12.0
44+
options.profilesSampleRate = 1.0;
45+
// Adds request headers and IP for users,
46+
// visit: https://docs.sentry.io/platforms/flutter/data-management/data-collected/ for more info
47+
options.sendDefaultPii = true;
48+
},
49+
appRunner: () => runApp(
50+
SentryWidget(
51+
child: MyApp(),
52+
),
53+
),
54+
);
55+
56+
// you can also configure SENTRY_DSN, SENTRY_RELEASE, SENTRY_DIST, and
57+
// SENTRY_ENVIRONMENT via Dart environment variable (--dart-define)
58+
}
59+
```
60+
61+
```dart {tabTitle:With custom zone} {"onboardingOptions": {"performance": "16-18", "profiling": "19-22"}}
62+
import 'package:flutter/widgets.dart';
63+
import 'package:sentry_flutter/sentry_flutter.dart';
64+
65+
Future<void> main() async {
66+
// The SDK creates it's own custom zone on web for automatic error and breadcrumb tracking on web.
67+
// This could lead to zone mismatch errors if you needed to call `WidgetsBinding.ensureInitialized()` before Sentry in a cusom zone.
68+
// With `Sentry.runZonedGuarded` you still get convenient auto error and breadcrumb tracking and can also call `WidgetsBinding.ensureInitialized()` before Sentry.
69+
Sentry.runZonedGuarded(() async {
70+
WidgetsBinding.ensureInitialized();
71+
72+
// Errors before init will not be handled by Sentry
73+
74+
await SentryFlutter.init(
75+
(options) {
76+
options.dsn = '___PUBLIC_DSN___';
77+
// Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
78+
// We recommend adjusting this value in production.
79+
options.tracesSampleRate = 1.0;
80+
// The sampling rate for profiling is relative to tracesSampleRate
81+
// Setting to 1.0 will profile 100% of sampled transactions:
82+
// Note: Profiling alpha is available for iOS and macOS since SDK version 7.12.0
83+
options.profilesSampleRate = 1.0;
84+
},
85+
appRunner: () => runApp(
86+
SentryWidget(
87+
child: MyApp(),
88+
),
89+
),
90+
);
91+
} (error, stackTrace) {
92+
// Automatically sends errors to Sentry, no need to do any
93+
// captureException calls on your part.
94+
// On top of that, you can do your own custom stuff in this callback.
95+
});
96+
97+
// you can also configure SENTRY_DSN, SENTRY_RELEASE, SENTRY_DIST, and
98+
// SENTRY_ENVIRONMENT via Dart environment variable (--dart-define)
99+
}
100+
```
101+
102+
## Verify
103+
104+
Verify that your app is sending events to Sentry by adding the following snippet, which includes an intentional error. You should see the error reported in Sentry within a few minutes.
105+
106+
```dart
107+
import 'package:sentry/sentry.dart';
108+
109+
try {
110+
throw Exception('Sentry Test Exception');
111+
} catch (exception, stackTrace) {
112+
await Sentry.captureException(
113+
exception,
114+
stackTrace: stackTrace,
115+
);
116+
}
117+
```
118+
119+
## Next Steps
120+
121+
- <PlatformLink to="/features">Learn about the features of Sentry's Flutter SDK</PlatformLink>
122+
- <PlatformLink to="/upload-debug/#when-to-upload/">Add readable stack traces to errors</PlatformLink>
123+
- <PlatformLink to="/tracing/instrumentation">Add performance instrumentation to your app</PlatformLink>

0 commit comments

Comments
 (0)