-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
docs(flutter): Use sentry flutter init in samples #11858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
denrase
merged 13 commits into
getsentry:master
from
denrase:denrase/use-sentry-flutter-init-in-samples
Nov 26, 2024
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f59ee0b
add flutter.mdx in configuration/sample-rate
denrase 8c66851
add code samples with SentryFlutter.init instead of Sentry.init
denrase 96288a5
implement feedback
denrase 42595d0
add missing sample, format samples
denrase 720c58a
Make dart/flutter samples more concise, Also update dart counterparts
denrase 71c58b0
add missing flutter sample
denrase 7833bab
fix formatting
denrase 0a9d684
updat formatting
denrase f93e871
update dart/flutter code samples
denrase ca52aab
Update dart.mdx
buenaflor 9006eb8
Update flutter.mdx
buenaflor 67b29bb
Update dart.mdx
buenaflor ff99d44
more updated/improvements
denrase File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,7 @@ | ||
| ```dart | ||
| import 'package:sentry/sentry.dart'; | ||
|
|
||
| Future<void> main() async { | ||
| await Sentry.init( | ||
| (options) { | ||
| options.dsn = '___PUBLIC_DSN___'; | ||
| options.allowUrls = ["^https://sentry.com.*\$", "my-custom-domain"]; | ||
| }, | ||
| appRunner: initApp, // Init your App. | ||
| ); | ||
| } | ||
| ```dart {3} | ||
| await Sentry.init( | ||
| (options) { | ||
| options.allowUrls = ["^https://sentry.com.*\$", "my-custom-domain"]; | ||
| }, | ||
| ); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ```dart {3} | ||
| await SentryFlutter.init( | ||
| (options) { | ||
| options.allowUrls = ["^https://sentry.com.*\$", "my-custom-domain"]; | ||
| }, | ||
| ); | ||
| ``` |
18 changes: 8 additions & 10 deletions
18
platform-includes/configuration/before-breadcrumb-hint/dart.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,9 @@ | ||
| ```dart | ||
| import 'package:sentry/sentry.dart'; | ||
|
|
||
| Breadcrumb? beforeBreadcrumb(Breadcrumb? breadcrumb, Hint hint) { | ||
| return hint is MyHint ? null : crumb; | ||
| } | ||
|
|
||
| Future<void> main() async { | ||
| await Sentry.init((options) => options.beforeBreadcrumb = beforeBreadcrumb); | ||
| } | ||
| ```dart {4} | ||
| await Sentry.init( | ||
| (options) { | ||
| options.beforeBreadcrumb = (breadcrumb, hint) { | ||
| return hint is MyHint ? null : crumb; | ||
| }; | ||
| }, | ||
| ); | ||
| ``` |
9 changes: 9 additions & 0 deletions
9
platform-includes/configuration/before-breadcrumb-hint/flutter.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| ```dart {4} | ||
| await SentryFlutter.init( | ||
| (options) { | ||
| options.beforeBreadcrumb = (breadcrumb, hint) { | ||
| return hint is MyHint ? null : crumb; | ||
| }; | ||
| }, | ||
| ); | ||
| ``` |
24 changes: 11 additions & 13 deletions
24
platform-includes/configuration/before-send-fingerprint/dart.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,12 @@ | ||
| ```dart | ||
| import 'package:sentry/sentry.dart'; | ||
|
|
||
| FutureOr<SentryEvent?> beforeSend(SentryEvent event, Hint hint) async { | ||
| if (event.throwable is DatabaseException) { | ||
| event = event.copyWith(fingerprint: ['database-connection-error']); | ||
| } | ||
| return event; | ||
| } | ||
|
|
||
| Future<void> main() async { | ||
| await Sentry.init((options) => options.beforeSend = beforeSend); | ||
| } | ||
| ```dart {4-7} | ||
| await Sentry.init( | ||
| (options) { | ||
| options.beforeSend = (event, hint) { | ||
| if (event.throwable is DatabaseException) { | ||
| event = event.copyWith(fingerprint: ['database-connection-error']); | ||
| } | ||
| return event; | ||
| }; | ||
| }, | ||
| ); | ||
| ``` |
12 changes: 12 additions & 0 deletions
12
platform-includes/configuration/before-send-fingerprint/flutter.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ```dart {4-7} | ||
| await SentryFlutter.init( | ||
| (options) { | ||
| options.beforeSend = (event, hint) { | ||
| if (event.throwable is DatabaseException) { | ||
| event = event.copyWith(fingerprint: ['database-connection-error']); | ||
| } | ||
| return event; | ||
| }; | ||
| }, | ||
| ); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,9 @@ | ||
| ```dart | ||
| import 'package:sentry/sentry.dart'; | ||
|
|
||
| FutureOr<SentryEvent?> beforeSend(SentryEvent event, Hint hint) async { | ||
| return hint is MyHint ? null : event; | ||
| } | ||
|
|
||
| Future<void> main() async { | ||
| await Sentry.init((options) => options.beforeSend = beforeSend); | ||
| } | ||
| ```dart {4} | ||
| await Sentry.init( | ||
| (options) { | ||
| options.beforeSend = (event, hint) { | ||
| return hint is MyHint ? null : event; | ||
| }; | ||
| }, | ||
| ); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| ```dart {4} | ||
| await SentryFlutter.init( | ||
| (options) { | ||
| options.beforeSend = (event, hint) { | ||
| return hint is MyHint ? null : event; | ||
| }; | ||
| }, | ||
| ); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,9 @@ | ||
| ```dart | ||
| import 'package:sentry/sentry.dart'; | ||
|
|
||
| FutureOr<SentryEvent?> beforeSend(SentryEvent event, Hint hint) async { | ||
| // 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); | ||
| } | ||
| ```dart {4} | ||
| await Sentry.init( | ||
| (options) { | ||
| options.beforeSend = (event, hint) { | ||
| return event.copyWith(serverName: null); // Don't send server names. | ||
| }; | ||
| }, | ||
| ); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| ```dart {4} | ||
| await SentryFlutter.init( | ||
| (options) { | ||
| options.beforeSend = (event, hint) { | ||
| return event.copyWith(serverName: null); // Don't send server names. | ||
| }; | ||
| }, | ||
| ); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,7 @@ | ||
| ```dart | ||
| import 'package:sentry/sentry.dart'; | ||
|
|
||
| Future<void> main() async { | ||
| await Sentry.init( | ||
| (options) { | ||
| options.dsn = '___PUBLIC_DSN___'; | ||
| options.denyUrls = ["^.*ends-with-this\$", "denied-url"]; | ||
| }, | ||
| appRunner: initApp, // Init your App. | ||
| ); | ||
| } | ||
| ```dart {3} | ||
| await Sentry.init( | ||
| (options) { | ||
| options.denyUrls = ["^.*ends-with-this\$", "denied-url"]; | ||
| }, | ||
| ); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ```dart {3} | ||
| await SentryFlutter.init( | ||
| (options) { | ||
| options.denyUrls = ["^.*ends-with-this\$", "denied-url"]; | ||
| }, | ||
| ); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,4 @@ | ||
| ```dart | ||
| import 'package:sentry/sentry.dart'; | ||
| Future<void> main() async { | ||
| // Capture only 25% of events | ||
| await Sentry.init((options) => options.sampleRate = 0.25); | ||
| } | ||
| // Capture only 25% of events | ||
| await Sentry.init((options) => options.sampleRate = 0.25); | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| ```dart | ||
| // Capture only 25% of events | ||
| await SentryFlutter.init((options) => options.sampleRate = 0.25); | ||
| ``` |
19 changes: 6 additions & 13 deletions
19
platform-includes/enriching-events/attach-viewhierarchy/flutter.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,7 @@ | ||
| ```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___'; | ||
| options.attachViewHierarchy = true; | ||
| }, | ||
| appRunner: () => runApp(MyApp()), | ||
| ); | ||
| } | ||
| ```dart {3} | ||
| await SentryFlutter.init( | ||
| (options) { | ||
| options.attachViewHierarchy = true; | ||
| }, | ||
| ); | ||
denrase marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
18 changes: 8 additions & 10 deletions
18
platform-includes/enriching-events/breadcrumbs/before-breadcrumb/dart.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,9 @@ | ||
| ```dart | ||
| import 'package:sentry/sentry.dart'; | ||
|
|
||
| Breadcrumb? beforeBreadcrumb(Breadcrumb? breadcrumb, Hint hint) { | ||
| return 'a.spammy.Logger' == breadcrumb.category ? null : breadcrumb; | ||
| } | ||
|
|
||
| Future<void> main() async { | ||
| await Sentry.init((options) => options.beforeBreadcrumb = beforeBreadcrumb); | ||
| } | ||
| ```dart {4} | ||
| await Sentry.init( | ||
| (options) { | ||
| options.beforeBreadcrumb = (breadcrumb, hint) { | ||
| return 'a.spammy.Logger' == breadcrumb.category ? null : breadcrumb; | ||
| }; | ||
| }, | ||
| ); | ||
| ``` |
9 changes: 9 additions & 0 deletions
9
platform-includes/enriching-events/breadcrumbs/before-breadcrumb/flutter.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| ```dart {4} | ||
| await SentryFlutter.init( | ||
| (options) { | ||
| options.beforeBreadcrumb = (breadcrumb, hint) { | ||
| return 'a.spammy.Logger' == breadcrumb.category ? null : breadcrumb; | ||
| }; | ||
| }, | ||
| ); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| ```dart | ||
| import 'package:sentry/sentry.dart'; | ||
| Sentry.init((options) => { | ||
| options.tracesSampleRate = 0.2, | ||
| }); | ||
| Sentry.init( | ||
| (options) { | ||
| options.tracesSampleRate = 0.2; | ||
| }, | ||
| ); | ||
denrase marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,12 @@ | ||
| ```dart | ||
| import 'package:sentry/sentry.dart'; | ||
| FutureOr<SentryEvent?> beforeSend(SentryEvent event, Hint hint) async { | ||
| if (event.throwable is DatabaseException) { | ||
| event = event.copyWith(fingerprint: ['database-connection-error']); | ||
| } | ||
| return event; | ||
| } | ||
| Future<void> main() async { | ||
| await Sentry.init((options) => options.beforeSend = beforeSend); | ||
| } | ||
| ```dart {4-7} | ||
| await SentryFlutter.init( | ||
| (options) { | ||
| options.beforeSend = (event, hint) { | ||
| if (event.throwable is DatabaseException) { | ||
| event = event.copyWith(fingerprint: ['database-connection-error']); | ||
| } | ||
| return event; | ||
| }; | ||
| }, | ||
| ); | ||
denrase marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ```dart {4-7} | ||
| await SentryFlutter.init( | ||
| (options) { | ||
| options.beforeSend = (event, hint) { | ||
| if (event.throwable is DatabaseException) { | ||
| event = event.copyWith(fingerprint: ['database-connection-error']); | ||
| } | ||
| return event; | ||
| }; | ||
| }, | ||
| ); | ||
| ``` |
24 changes: 11 additions & 13 deletions
24
platform-includes/set-fingerprint/database-connection/dart.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,12 @@ | ||
| ```dart | ||
| import 'package:sentry/sentry.dart'; | ||
|
|
||
| FutureOr<SentryEvent?> beforeSend(SentryEvent event, Hint hint) async { | ||
| if (event.throwable is DatabaseException) { | ||
| event = event.copyWith(fingerprint: ['database-connection-error']); | ||
| } | ||
| return event; | ||
| } | ||
|
|
||
| Future<void> main() async { | ||
| await Sentry.init((options) => options.beforeSend = beforeSend); | ||
| } | ||
| ```dart {4-7} | ||
| await Sentry.init( | ||
| (options) { | ||
| options.beforeSend = (event, hint) { | ||
| if (event.throwable is DatabaseException) { | ||
| event = event.copyWith(fingerprint: ['database-connection-error']); | ||
| } | ||
| return event; | ||
| }; | ||
| }, | ||
| ); | ||
| ``` |
12 changes: 12 additions & 0 deletions
12
platform-includes/set-fingerprint/database-connection/flutter.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ```dart {4-7} | ||
| await SentryFlutter.init( | ||
| (options) { | ||
| options.beforeSend = (event, hint) { | ||
| if (event.throwable is DatabaseException) { | ||
| event = event.copyWith(fingerprint: ['database-connection-error']); | ||
| } | ||
| return event; | ||
| }; | ||
| }, | ||
| ); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,24 @@ | ||
| ```dart | ||
| import 'package:sentry/sentry.dart'; | ||
|
|
||
| class MyRpcException implements Exception { | ||
| final String function; | ||
| final int httpStatusCode; | ||
|
|
||
| MyRpcException(this.function, this.httpStatusCode); | ||
| } | ||
|
|
||
| FutureOr<SentryEvent?> beforeSend(SentryEvent event, Hint hint) async { | ||
| if (event.throwable is MyRpcException) { | ||
| final exception = event.throwable as MyRpcException; | ||
| event = event.copyWith(fingerprint: [ | ||
| '{{ default }}', | ||
| exception.function, | ||
| exception.httpStatusCode.toString(), | ||
| ]); | ||
| } | ||
| return event; | ||
| } | ||
|
|
||
| Future<void> main() async { | ||
| await Sentry.init((options) => options.beforeSend = beforeSend); | ||
| } | ||
| await Sentry.init( | ||
| (options) { | ||
| options.beforeSend = (event, hint) { | ||
| if (event.throwable is MyRpcException) { | ||
| final exception = event.throwable as MyRpcException; | ||
| event = event.copyWith(fingerprint: [ | ||
| '{{ default }}', | ||
| exception.function, | ||
| exception.httpStatusCode.toString(), | ||
| ]); | ||
| } | ||
| return event; | ||
| }; | ||
| }, | ||
| ); | ||
| ``` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.