|
| 1 | +<p align="center"> |
| 2 | + <a href="https://sentry.io" target="_blank" align="center"> |
| 3 | + <img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280"> |
| 4 | + </a> |
| 5 | + <br /> |
| 6 | +</p> |
| 7 | + |
| 8 | +Sentry integration for `dart.io.File` |
| 9 | +=========== |
| 10 | + |
| 11 | +| package | build | pub | likes | popularity | pub points | |
| 12 | +| ------- | ------- | ------- | ------- | ------- | ------- | |
| 13 | +| sentry_file | [](https://github.com/getsentry/sentry-dart/actions?query=workflow%3Asentry-file) | [](https://pub.dev/packages/sentry_file) | [](https://pub.dev/packages/sentry_file/score) | [](https://pub.dev/packages/sentry_file/score) | [](https://pub.dev/packages/sentry_file/score) |
| 14 | + |
| 15 | +#### Usage |
| 16 | + |
| 17 | +- Sign up for a Sentry.io account and get a DSN at https://sentry.io. |
| 18 | + |
| 19 | +- Follow the installing instructions on [pub.dev](https://pub.dev/packages/sentry/install). |
| 20 | + |
| 21 | +- Initialize the Sentry SDK using the DSN issued by Sentry.io. |
| 22 | + |
| 23 | +- [Set Up](https://docs.sentry.io/platforms/dart/performance/) Performance. |
| 24 | + |
| 25 | +```dart |
| 26 | +import 'package:sentry/sentry.dart'; |
| 27 | +import 'package:sentry_file/sentry_file.dart'; |
| 28 | +import 'dart:io'; |
| 29 | +
|
| 30 | +Future<void> main() async { |
| 31 | + // or SentryFlutter.init |
| 32 | + await Sentry.init( |
| 33 | + (options) { |
| 34 | + options.dsn = 'https://[email protected]/example'; |
| 35 | + // To set a uniform sample rate |
| 36 | + options.tracesSampleRate = 1.0; |
| 37 | + }, |
| 38 | + appRunner: runApp, // Init your App. |
| 39 | + ); |
| 40 | +} |
| 41 | +
|
| 42 | +Future<void> runApp() async { |
| 43 | + final file = File('my_file.txt'); |
| 44 | + // Call the Sentry extension method to wrap up the File |
| 45 | + final sentryFile = file.sentryTrace(); |
| 46 | +
|
| 47 | + // Start a transaction if there's no active transaction |
| 48 | + final transaction = Sentry.startTransaction( |
| 49 | + 'MyFileExample', |
| 50 | + 'file', |
| 51 | + bindToScope: true, |
| 52 | + ); |
| 53 | +
|
| 54 | + // create the File |
| 55 | + await sentryFile.create(); |
| 56 | + // Write some content |
| 57 | + await sentryFile.writeAsString('Hello World'); |
| 58 | + // Read the content |
| 59 | + final text = await sentryFile.readAsString(); |
| 60 | +
|
| 61 | + print(text); |
| 62 | +
|
| 63 | + // Delete the file |
| 64 | + await sentryFile.delete(); |
| 65 | +
|
| 66 | + // Finish the transaction |
| 67 | + await transaction.finish(status: SpanStatus.ok()); |
| 68 | +
|
| 69 | + await Sentry.close(); |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +#### Resources |
| 74 | + |
| 75 | +* [](https://docs.sentry.io/platforms/dart/) |
| 76 | +* [](https://forum.sentry.io/c/sdks) |
| 77 | +* [](https://discord.gg/Ww9hbqr) |
| 78 | +* [](https://stackoverflow.com/questions/tagged/sentry) |
| 79 | +* [](https://twitter.com/intent/follow?screen_name=getsentry) |
0 commit comments