Skip to content

Commit f8be893

Browse files
Add File IO instrumentation docs (#5895)
Co-authored-by: Isabel <[email protected]>
1 parent 892ec15 commit f8be893

File tree

6 files changed

+113
-5
lines changed

6 files changed

+113
-5
lines changed

src/platform-includes/getting-started-primer/dart.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ Sentry's Dart SDK enables automatic reporting of errors, messages, and exception
1515
- [Performance Monitoring](/product/performance/) creates transactions for:
1616
- [HTTP requests](/platforms/dart/configuration/integrations/http-integration/#performance-monitoring-for-http-requests)
1717
- [Dio HTTP library](/platforms/dart/configuration/integrations/dio/#performance-monitoring-for-http-requests)
18+
- [File I/O Integration](/platforms/dart/configuration/integrations/file/)
1819
- [Logging Integration](/platforms/dart/configuration/integrations/logging)
1920
- [Dio Integration](/platforms/dart/configuration/integrations/dio/)

src/platform-includes/getting-started-primer/flutter.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Features:
3030
- [Cold and warm app start](/platforms/flutter/performance/instrumentation/automatic-instrumentation/#app-start-instrumentation)
3131
- [Slow and frozen frames](/platforms/flutter/performance/instrumentation/automatic-instrumentation/#slow-and-frozen-frames)
3232
- [AssetBundle Instrumentation](/platforms/flutter/performance/instrumentation/automatic-instrumentation/#assetbundle-instrumentation)
33+
- [File I/O Integration](/platforms/dart/configuration/integrations/file/)
3334
- [Logging Integration](/platforms/dart/configuration/integrations/logging)
3435
- [Screenshot attachments for errors](/platforms/flutter/enriching-events/screenshots/)
3536
- Limited support for Flutter Web, Windows, and Linux

src/platforms/dart/common/performance/instrumentation/automatic-instrumentation.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,15 @@ The span finishes once the request has been executed. The span `status` depends
3131
When the HTTP request throws an `Exception`, Sentry's SDK associates this exception to the running span. If you haven't set the SDK to swallow the exception and capture it, the span and `SentryEvent` will be linked when viewing it on the **Issue Details** page in [sentry.io](https://sentry.io).
3232

3333
Learn more in our [Dio integration documentation](/platforms/dart/configuration/integrations/dio/#performance-monitoring-for-http-requests).
34+
35+
### File I/O Instrumentation
36+
37+
The Sentry-specific file I/O implementation starts a span out of the active span, bound to the scope for each file I/O operation. The SDK sets the span `operation` to `file.copy`, `file.write`, `file.delete`, `file.open`, `file.read` or `file.rename`, and `description` to `filename` (for example, `file.txt`).
38+
39+
In addition, the span contains other useful information such as `file.size` (raw number of bytes), `file.path` (an absolute path to the file), and `file.async` (`true` if the called method returns a `Future`, or `false` if it's a `Sync` call) as part of the `data` payload.
40+
41+
The span finishes once the operation has been executed. The span `status` is set to `SpanStatus.ok` if successful or `SpanStatus.internalError` if there was any error.
42+
43+
When the operation throws an `Exception`, Sentry's SDK associates this exception to the running span. If you haven't set the SDK to swallow the exception and capture it, the span and `SentryEvent` will be linked when viewing it on the **Issue Details** page in [sentry.io](https://sentry.io).
44+
45+
For more information see our [file I/O integration](/platforms/dart/configuration/integrations/file/).
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
title: File I/O
3+
sidebar_order: 5
4+
description: "Learn more about the Sentry file I/O integration for the Dart SDK."
5+
---
6+
7+
<Include name="beta-note.mdx" />
8+
9+
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. The `SentryFile` is able to run performance monitoring for `File` operations.
10+
11+
The source can be found [on GitHub](https://github.com/getsentry/sentry-dart/tree/main/file/).
12+
13+
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`.
14+
15+
<Note>
16+
17+
The File I/O integration is only available for the `dart:io:File` class, not for the `dart:html:File` class.
18+
19+
</Note>
20+
21+
## Install
22+
23+
To use the `SentryFile` wrapper, add the `sentry_file` dependency.
24+
25+
```yml {filename:pubspec.yaml}
26+
dependencies:
27+
sentry: ^{{ packages.version('sentry.dart', '6.18.0') }}
28+
sentry_file: ^{{ packages.version('sentry.dart.file', '6.18.0') }}
29+
```
30+
31+
## Verify
32+
33+
<Note>
34+
35+
Capturing transactions requires that you first <PlatformLink to="/performance/">set up performance monitoring</PlatformLink> if you haven't already.
36+
37+
</Note>
38+
39+
```dart
40+
import 'package:sentry/sentry.dart';
41+
import 'package:sentry_file/sentry_file.dart';
42+
import 'dart:io';
43+
44+
Future<void> main() async {
45+
await Sentry.init(
46+
(options) {
47+
options.dsn = 'https://[email protected]/example';
48+
// To set a uniform sample rate
49+
options.tracesSampleRate = 1.0;
50+
},
51+
appRunner: runApp, // Init your App.
52+
);
53+
}
54+
55+
Future<void> runApp() async {
56+
final file = File('my_file.txt');
57+
// Call the Sentry extension method to wrap up the File
58+
final sentryFile = file.sentryTrace();
59+
60+
// Start a transaction if there's no active transaction
61+
final transaction = Sentry.startTransaction(
62+
'MyFileExample',
63+
'file',
64+
bindToScope: true,
65+
);
66+
67+
// create the File
68+
await sentryFile.create();
69+
// Write some content
70+
await sentryFile.writeAsString('Hello World');
71+
// Read the content
72+
final text = await sentryFile.readAsString();
73+
74+
print(text);
75+
76+
// Delete the file
77+
await sentryFile.delete();
78+
79+
// Finish the transaction
80+
await transaction.finish(status: SpanStatus.ok());
81+
82+
await Sentry.close();
83+
}
84+
```
85+
86+
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`.

src/platforms/flutter/common/configuration/integrations/user-interaction-instrumentation.mdx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ categories:
1010

1111
_(New in version 6.17.0)_
1212

13-
<Note>
14-
15-
This feature is currently in Beta. Beta features are still in-progress and may have bugs. We recognize the irony.
16-
17-
</Note>
13+
<Include name="beta-note.mdx" />
1814

1915
The UI instrumentation, once enabled, captures transactions and adds breadcrumbs for a set of different user interactions, which include clicks, long clicks, taps, and so on. The SDK composes the transaction name from the `key` of the `Widget` that captured the user interaction (for example, `login_button`). The transaction operation is set to `ui.action.click`.
2016

src/platforms/flutter/common/performance/instrumentation/automatic-instrumentation.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,15 @@ The `SentryAssetBundle` instrumentation starts a span out of the active transact
213213
The `enableStructuredDataTracing` feature is available in Beta. Beta features are still in-progress and may have bugs. We recognize the irony.
214214

215215
</Note>
216+
217+
### File I/O Instrumentation
218+
219+
The Sentry-specific file I/O implementation starts a span out of the active span, bound to the scope for each file I/O operation. The SDK sets the span `operation` to `file.copy`, `file.write`, `file.delete`, `file.open`, `file.read` or `file.rename`, and `description` to `filename` (for example, `file.txt`).
220+
221+
In addition, the span contains other useful information such as `file.size` (raw number of bytes), `file.path` (an absolute path to the file) and `file.async` (`true` if the called method returns a `Future`, or `false` if it's a `Sync` call) as part of the `data` payload.
222+
223+
The span finishes once the operation has been executed. The span `status` is set to `SpanStatus.ok` if successful or `SpanStatus.internalError` if there was any error.
224+
225+
When the operation throws an `Exception`, Sentry's SDK associates this exception to the running span. If you haven't set the SDK to swallow the exception and capture it, the span and `SentryEvent` will be linked when viewing it on the **Issue Details** page in [sentry.io](https://sentry.io).
226+
227+
Learn more about our [file I/O integration](/platforms/dart/configuration/integrations/file/).

0 commit comments

Comments
 (0)