-
-
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 4 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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ```dart {3} | ||
| await SentryFlutter.init( | ||
| (options) { | ||
| options.allowUrls = ["^https://sentry.com.*\$", "my-custom-domain"]; | ||
| }, | ||
| ); | ||
| ``` |
14 changes: 14 additions & 0 deletions
14
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,14 @@ | ||
| ```dart {10} | ||
| FutureOr<SentryEvent?> beforeSend(SentryEvent event, Hint hint) async { | ||
| if (event.throwable is DatabaseException) { | ||
| event = event.copyWith(fingerprint: ['database-connection-error']); | ||
| } | ||
| return event; | ||
| } | ||
| await Sentry.init( | ||
| (options) { | ||
| options.beforeSend = beforeSend; | ||
| }, | ||
| ); | ||
| ``` | ||
11 changes: 11 additions & 0 deletions
11
platform-includes/configuration/before-send-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,11 @@ | ||
| ```dart {7} | ||
| FutureOr<SentryEvent?> beforeSend(SentryEvent event, Hint hint) async { | ||
| return hint is MyHint ? null : event; | ||
| } | ||
| await SentryFlutter.init( | ||
| (options) { | ||
| options.beforeSend = beforeSend; | ||
| }, | ||
| ); | ||
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,13 @@ | ||
| ```dart {9} | ||
| FutureOr<SentryEvent?> beforeSend(SentryEvent event, Hint hint) async { | ||
| // Modify the event here: | ||
| event = event.copyWith(serverName: null); // Don't send server names. | ||
| return event; | ||
| } | ||
| await SentryFlutter.init( | ||
| (options) { | ||
| options.beforeSend = beforeSend; | ||
| }, | ||
| ); | ||
| ``` | ||
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,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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| ```dart | ||
| import 'package:flutter/widgets.dart'; | ||
| import 'package:sentry_flutter/sentry_flutter.dart'; | ||
| Future<void> main() async { | ||
| // Capture only 25% of events | ||
| await SentryFlutter.init((options) => options.sampleRate = 0.25); | ||
| } | ||
| ``` | ||
denrase marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
20 changes: 7 additions & 13 deletions
20
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,8 @@ | ||
| ```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; | ||
| }, | ||
| appRunner: () => runApp(MyApp()), | ||
denrase marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
| ``` | ||
11 changes: 11 additions & 0 deletions
11
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,11 @@ | ||
| ```dart {7} | ||
| Breadcrumb? beforeBreadcrumb(Breadcrumb? breadcrumb, Hint hint) { | ||
| return 'a.spammy.Logger' == breadcrumb.category ? null : breadcrumb; | ||
| } | ||
|
|
||
| await SentryFlutter.init( | ||
| (options) { | ||
| options.beforeBreadcrumb = beforeBreadcrumb; | ||
| }, | ||
| ); | ||
| ``` |
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,10 @@ | ||
| ```dart | ||
| FutureOr<SentryEvent?> beforeSend(SentryEvent event, Hint hint) async { | ||
| if (event.throwable is DatabaseException) { | ||
| event = event.copyWith(fingerprint: ['database-connection-error']); | ||
| } | ||
| return event; | ||
| } | ||
|
|
||
| await SentryFlutter.init((options) => options.beforeSend = beforeSend); | ||
| ``` |
10 changes: 10 additions & 0 deletions
10
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,10 @@ | ||
| ```dart | ||
| FutureOr<SentryEvent?> beforeSend(SentryEvent event, Hint hint) async { | ||
| if (event.throwable is DatabaseException) { | ||
| event = event.copyWith(fingerprint: ['database-connection-error']); | ||
| } | ||
| return event; | ||
| } | ||
|
|
||
| await SentryFlutter.init((options) => options.beforeSend = beforeSend); | ||
| ``` |
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,22 @@ | ||
| ```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; | ||
| } | ||
|
|
||
| await SentryFlutter.init((options) => options.beforeSend = beforeSend); | ||
| ``` |
26 changes: 26 additions & 0 deletions
26
platform-includes/user-feedback/sdk-api-example/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,26 @@ | ||
| ```dart | ||
| // Option 1: Retrieving SentryId from beforeSend | ||
| SentryId sentryId = SentryId.empty(); | ||
| await SentryFlutter.init((options) { | ||
| options.beforeSend = (event, hint) async { | ||
| sentryId = event.eventId; | ||
| return event; | ||
| }; | ||
| }); | ||
| // Option 2: Retrieving SentryId from the method capturing the event | ||
| SentryId sentryId = Sentry.captureMessage("My message"); | ||
| // Option 3: Retrieving SentryId from the beforeSend callback | ||
| SentryId sentryId = Sentry.lastEventId; | ||
| final userFeedback = SentryUserFeedback( | ||
| eventId: sentryId, | ||
| comments: 'Hello World!', | ||
| email: '[email protected]', | ||
| name: 'John Doe', | ||
| ); | ||
| Sentry.captureUserFeedback(userFeedback); | ||
| ``` | ||
buenaflor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.