Skip to content

Commit b47809a

Browse files
authored
Tracing for File IO integration (#1160)
1 parent 62dde43 commit b47809a

29 files changed

+1436
-13
lines changed

.craft.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ targets:
99
flutter:
1010
logging:
1111
dio:
12+
file:
1213
- name: github
1314
- name: registry
1415
sdks:
1516
pub:sentry:
1617
pub:sentry_flutter:
1718
pub:sentry_logging:
1819
pub:sentry_dio:
20+
#pub:sentry_file:

.github/workflows/file.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: sentry-file
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- release/**
7+
pull_request:
8+
paths-ignore:
9+
- 'logging/**'
10+
- 'flutter/**'
11+
- 'dio/**'
12+
13+
jobs:
14+
cancel-previous-workflow:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Cancel Previous Runs
18+
uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 # [email protected]
19+
with:
20+
access_token: ${{ github.token }}
21+
22+
build:
23+
name: Build ${{matrix.sdk}} on ${{matrix.os}}
24+
runs-on: ${{ matrix.os }}
25+
timeout-minutes: 30
26+
defaults:
27+
run:
28+
shell: bash
29+
working-directory: ./file
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
os: [ubuntu-latest, windows-latest, macos-latest]
34+
# removing beta because of Dart 2.19.0
35+
sdk: [stable]
36+
steps:
37+
- uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d # pin@v1
38+
with:
39+
sdk: ${{ matrix.sdk }}
40+
- uses: actions/checkout@v3
41+
42+
- name: Test VM
43+
run: |
44+
dart pub get
45+
dart test -p vm --coverage=coverage --test-randomize-ordering-seed=random --chain-stack-traces
46+
dart pub run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info --packages=.dart_tool/package_config.json --report-on=lib
47+
48+
- uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # pin@v3
49+
if: runner.os == 'Linux' && matrix.sdk == 'stable'
50+
with:
51+
name: sentry_file
52+
files: ./file/coverage/lcov.info
53+
54+
- uses: VeryGoodOpenSource/very_good_coverage@84e5b54ab888644554e5573dca87d7f76dec9fb3 # [email protected]
55+
if: runner.os == 'Linux' && matrix.sdk == 'stable'
56+
with:
57+
path: './file/coverage/lcov.info'
58+
min_coverage: 55
59+
60+
analyze:
61+
uses: ./.github/workflows/analyze.yml
62+
with:
63+
package: file
64+
panaThreshold: 90

.github/workflows/min_version_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- uses: subosito/flutter-action@dbf1fa04f4d2e52c33185153d06cdb5443aa189d # pin@v2
3232
with:
3333
flutter-version: '2.0.0'
34-
34+
# Add flutter build web (missing index)
3535
- name: Build
3636
run: |
3737
cd min_version_test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ build/
1919
dart/coverage/*
2020
logging/coverage/*
2121
dio/coverage/*
22+
file/coverage/*
2223
pubspec.lock
2324
Podfile.lock
2425
flutter/coverage/*

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- Tracing for File IO integration ([#1160](https://github.com/getsentry/sentry-dart/pull/1160))
8+
59
### Dependencies
610

711
- Bump Cocoa SDK from v7.31.2 to v7.31.3 ([#1157](https://github.com/getsentry/sentry-dart/pull/1157))

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ Sentry SDK for Dart and Flutter
2020
| sentry_flutter | [![build](https://github.com/getsentry/sentry-dart/workflows/sentry-flutter/badge.svg?branch=main)](https://github.com/getsentry/sentry-dart/actions?query=workflow%3Asentry-flutter) | [![pub package](https://img.shields.io/pub/v/sentry_flutter.svg)](https://pub.dev/packages/sentry_flutter) | [![likes](https://img.shields.io/pub/likes/sentry_flutter?logo=dart)](https://pub.dev/packages/sentry_flutter/score) | [![popularity](https://img.shields.io/pub/popularity/sentry_flutter?logo=dart)](https://pub.dev/packages/sentry_flutter/score) | [![pub points](https://img.shields.io/pub/points/sentry_flutter?logo=dart)](https://pub.dev/packages/sentry_flutter/score)
2121
| sentry_logging | [![build](https://github.com/getsentry/sentry-dart/workflows/sentry-logging/badge.svg?branch=main)](https://github.com/getsentry/sentry-dart/actions?query=workflow%3Alogging) | [![pub package](https://img.shields.io/pub/v/sentry_logging.svg)](https://pub.dev/packages/sentry_logging) | [![likes](https://img.shields.io/pub/likes/sentry_logging?logo=dart)](https://pub.dev/packages/sentry_logging/score) | [![popularity](https://img.shields.io/pub/popularity/sentry_logging?logo=dart)](https://pub.dev/packages/sentry_logging/score) | [![pub points](https://img.shields.io/pub/points/sentry_logging?logo=dart)](https://pub.dev/packages/sentry_logging/score)
2222
| sentry_dio | [![build](https://github.com/getsentry/sentry-dart/workflows/sentry-dio/badge.svg?branch=main)](https://github.com/getsentry/sentry-dart/actions?query=workflow%3Asentry-dio) | [![pub package](https://img.shields.io/pub/v/sentry_dio.svg)](https://pub.dev/packages/sentry_dio) | [![likes](https://img.shields.io/pub/likes/sentry_dio?logo=dart)](https://pub.dev/packages/sentry_dio/score) | [![popularity](https://img.shields.io/pub/popularity/sentry_dio?logo=dart)](https://pub.dev/packages/sentry_dio/score) | [![pub points](https://img.shields.io/pub/points/sentry_dio?logo=dart)](https://pub.dev/packages/sentry_dio/score)
23+
| sentry_file | [![build](https://github.com/getsentry/sentry-dart/workflows/sentry_file/badge.svg?branch=main)](https://github.com/getsentry/sentry-dart/actions?query=workflow%3Asentry_file) | [![pub package](https://img.shields.io/pub/v/sentry_file.svg)](https://pub.dev/packages/sentry_file) | [![likes](https://img.shields.io/pub/likes/sentry_file?logo=dart)](https://pub.dev/packages/sentry_file/score) | [![popularity](https://img.shields.io/pub/popularity/sentry_file?logo=dart)](https://pub.dev/packages/sentry_file/score) | [![pub points](https://img.shields.io/pub/points/sentry_file?logo=dart)](https://pub.dev/packages/sentry_file/score)
2324

2425
##### Usage
2526

26-
For detailed usage, check out the inner [dart](https://github.com/getsentry/sentry-dart/tree/main/dart), [flutter](https://github.com/getsentry/sentry-dart/tree/main/flutter), [logging](https://github.com/getsentry/sentry-dart/tree/main/logging) and [dio](https://github.com/getsentry/sentry-dart/tree/main/dio) `README's` or our `Resources` section below.
27+
For detailed usage, check out the inner [dart](https://github.com/getsentry/sentry-dart/tree/main/dart), [flutter](https://github.com/getsentry/sentry-dart/tree/main/flutter), [logging](https://github.com/getsentry/sentry-dart/tree/main/logging), [dio](https://github.com/getsentry/sentry-dart/tree/main/dio) and [file](https://github.com/getsentry/sentry-dart/tree/main/file) `README's` or our `Resources` section below.
2728

2829
#### Blog posts
2930

file/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../CHANGELOG.md

file/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Sentry
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

file/README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 | [![build](https://github.com/getsentry/sentry-dart/workflows/sentry-file/badge.svg?branch=main)](https://github.com/getsentry/sentry-dart/actions?query=workflow%3Asentry-file) | [![pub package](https://img.shields.io/pub/v/sentry_file.svg)](https://pub.dev/packages/sentry_file) | [![likes](https://img.shields.io/pub/likes/sentry_file)](https://pub.dev/packages/sentry_file/score) | [![popularity](https://img.shields.io/pub/popularity/sentry_file)](https://pub.dev/packages/sentry_file/score) | [![pub points](https://img.shields.io/pub/points/sentry_file)](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+
* [![Documentation](https://img.shields.io/badge/documentation-sentry.io-green.svg)](https://docs.sentry.io/platforms/dart/)
76+
* [![Forum](https://img.shields.io/badge/forum-sentry-green.svg)](https://forum.sentry.io/c/sdks)
77+
* [![Discord](https://img.shields.io/discord/621778831602221064)](https://discord.gg/Ww9hbqr)
78+
* [![Stack Overflow](https://img.shields.io/badge/stack%20overflow-sentry-green.svg)](https://stackoverflow.com/questions/tagged/sentry)
79+
* [![Twitter Follow](https://img.shields.io/twitter/follow/getsentry?label=getsentry&style=social)](https://twitter.com/intent/follow?screen_name=getsentry)

file/analysis_options.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
include: package:lints/recommended.yaml
2+
3+
analyzer:
4+
exclude:
5+
- example/** # the example has its own 'analysis_options.yaml'
6+
errors:
7+
# treat missing required parameters as a warning (not a hint)
8+
missing_required_param: error
9+
# treat missing returns as a warning (not a hint)
10+
missing_return: error
11+
language:
12+
strict-casts: true
13+
strict-inference: true
14+
strict-raw-types: true
15+
16+
linter:
17+
rules:
18+
prefer_relative_imports: true
19+
unnecessary_brace_in_string_interps: true
20+
prefer_function_declarations_over_variables: false
21+
no_leading_underscores_for_local_identifiers: false
22+
avoid_renaming_method_parameters: false
23+
unawaited_futures: true

file/example/example.dart

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import 'package:sentry/sentry.dart';
2+
import 'package:sentry_file/sentry_file.dart';
3+
import 'dart:io';
4+
5+
Future<void> main() async {
6+
// ATTENTION: Change the DSN below with your own to see the events in Sentry. Get one at sentry.io
7+
const dsn =
8+
'https://[email protected]/5428562';
9+
10+
// or SentryFlutter.init
11+
await Sentry.init(
12+
(options) {
13+
options.dsn = dsn;
14+
// To capture the absolute path of the file
15+
options.sendDefaultPii = true;
16+
// To set a uniform sample rate
17+
options.tracesSampleRate = 1.0;
18+
},
19+
appRunner: runApp, // Init your App.
20+
);
21+
}
22+
23+
Future<void> runApp() async {
24+
final file = File('my_file.txt');
25+
// Call the Sentry extension method to wrap up the File
26+
final sentryFile = file.sentryTrace();
27+
28+
// Start a transaction if there's no active transaction
29+
final transaction = Sentry.startTransaction(
30+
'MyFileExample',
31+
'file',
32+
bindToScope: true,
33+
);
34+
35+
// Create the File
36+
await sentryFile.create();
37+
// Write some content
38+
await sentryFile.writeAsString('Hello World');
39+
// Read the content
40+
final text = await sentryFile.readAsString();
41+
42+
print(text);
43+
44+
// Delete the file
45+
await sentryFile.delete();
46+
47+
// Finish the transaction
48+
await transaction.finish(status: SpanStatus.ok());
49+
50+
await Sentry.close();
51+
}

file/lib/sentry_file.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export 'src/sentry_file.dart';
2+
export 'src/sentry_file_extension.dart';

0 commit comments

Comments
 (0)