-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add File IO instrumentation docs #5895
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
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8c45da9
Add File IO instrumentation docs
marandaneto ee131d5
auto instrumentation
marandaneto 951a9b7
fix
marandaneto 28bf6f1
Update src/platforms/dart/common/performance/instrumentation/automati…
marandaneto c5b7495
Update src/platforms/dart/common/performance/instrumentation/automati…
marandaneto 83e5fa7
Update src/platforms/dart/configuration/integrations/file.mdx
marandaneto 45481d4
Update src/platforms/flutter/common/performance/instrumentation/autom…
marandaneto 60621ad
Update src/platforms/flutter/common/performance/instrumentation/autom…
marandaneto 9d9e407
Update src/platforms/flutter/common/performance/instrumentation/autom…
marandaneto 1921fe4
Update src/platforms/flutter/common/performance/instrumentation/autom…
marandaneto 1af1d8c
Update src/platforms/dart/common/performance/instrumentation/automati…
marandaneto f49f804
fixes
marandaneto 4b5d7c0
fix
marandaneto 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
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
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
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,90 @@ | ||
| --- | ||
| title: File I/O | ||
| sidebar_order: 5 | ||
| description: "Learn more about the Sentry file I/O integration for the Dart SDK." | ||
| --- | ||
|
|
||
| <Note> | ||
|
|
||
| This feature is currently in Beta. Beta features are still in-progress and may have bugs. We recognize the irony. | ||
|
|
||
| </Note> | ||
marandaneto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The `sentry_file` library provides [File](https://api.dart.dev/stable/2.18.5/dart-io/File-class.html) support for Sentry wrapping the `File` class with a `SentryFile` wrapper. It is able to run performance monitoring for `File` operations. | ||
marandaneto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The source can be found [on GitHub](https://github.com/getsentry/sentry-dart/tree/main/file/). | ||
|
|
||
| On this page, we get you up and running with Sentry's file I/O integration, so that it will automatically start a span out of the active transaction, bound to the scope for operations such as `copy`, `create`, `delete`, `open`, `rename`, `read` and `write`. | ||
marandaneto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <Note> | ||
|
|
||
| The File I/O integration is only available for the `dart:io:File` class, not for the `dart:html:File` class. | ||
|
|
||
| </Note> | ||
|
|
||
| ## Install | ||
|
|
||
| To use the `SentryFile` wrapper, add the `sentry_file` dependency. | ||
|
|
||
| ```yml {filename:pubspec.yaml} | ||
| dependencies: | ||
| sentry: ^{{ packages.version('sentry.dart', '6.18.0') }} | ||
| sentry_file: ^{{ packages.version('sentry.dart.file', '6.18.0') }} | ||
| ``` | ||
| ## Verify | ||
| <Note> | ||
| Capturing transactions requires that you first <PlatformLink to="/performance/">set up performance monitoring</PlatformLink> if you haven't already. | ||
| </Note> | ||
| ```dart | ||
| import 'package:sentry/sentry.dart'; | ||
| import 'package:sentry_file/sentry_file.dart'; | ||
| import 'dart:io'; | ||
|
|
||
| Future<void> main() async { | ||
| await Sentry.init( | ||
| (options) { | ||
| options.dsn = 'https://[email protected]/example'; | ||
| // To set a uniform sample rate | ||
| options.tracesSampleRate = 1.0; | ||
| }, | ||
| appRunner: runApp, // Init your App. | ||
| ); | ||
| } | ||
|
|
||
| Future<void> runApp() async { | ||
| final file = File('my_file.txt'); | ||
| // Call the Sentry extension method to wrap up the File | ||
| final sentryFile = file.sentryTrace(); | ||
|
|
||
| // Start a transaction if there's no active transaction | ||
| final transaction = Sentry.startTransaction( | ||
| 'MyFileExample', | ||
| 'file', | ||
| bindToScope: true, | ||
| ); | ||
|
|
||
| // create the File | ||
| await sentryFile.create(); | ||
| // Write some content | ||
| await sentryFile.writeAsString('Hello World'); | ||
| // Read the content | ||
| final text = await sentryFile.readAsString(); | ||
|
|
||
| print(text); | ||
|
|
||
| // Delete the file | ||
| await sentryFile.delete(); | ||
|
|
||
| // Finish the transaction | ||
| await transaction.finish(status: SpanStatus.ok()); | ||
|
|
||
| await Sentry.close(); | ||
| } | ||
| ``` | ||
|
|
||
| To view the recorded transaction, log into [sentry.io](https://sentry.io) and open your project. Clicking **Performance** will open a page with transactions, where you can select the just recorded transaction with the name `MyFileExample`. | ||
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
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.