Skip to content

Commit 7e7f0b1

Browse files
vaindjosh-burton
andauthored
feat: enable wasm compilation (#2113)
* feat: migrates to package:web and js_interop * fix: enhances comment * chore: Adds changelog * chore: formatting * fix: changes min flutter version to 3.13.0 and dart sdk 3.1.0 to be compatible with package:web 0.5.1 * compat with dart:html & dart:web * fixups * more fixups * analyzer * chore: changelog entry * run dart test for all supported dart version * update web example tests * update ci * update deps so that we can run test with old dart versions * fix ci * fix web enricher test * fix ci * ci fixes * ignore pana error * fix CI * fix ci * remove dart 2.17 build * fixes * fix CI * test dart2wasm * cleanup * disable dart2wasm on windows * fix tests for wasm --------- Co-authored-by: Josh Burton <[email protected]>
1 parent 389a4e1 commit 7e7f0b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+716
-127
lines changed

.github/actions/dart-test/action.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ runs:
2323
working-directory: ${{ inputs.directory }}
2424

2525
- name: Test VM
26-
run: dart test -p vm --coverage=coverage --test-randomize-ordering-seed=random --chain-stack-traces
26+
run: dart test -p vm ${{ (runner.os == 'Linux' && matrix.sdk == 'stable' && '--coverage=coverage') || '' }} --test-randomize-ordering-seed=random --chain-stack-traces
2727
shell: bash
2828
working-directory: ${{ inputs.directory }}
2929

@@ -32,3 +32,9 @@ runs:
3232
run: dart test -p chrome --test-randomize-ordering-seed=random --chain-stack-traces
3333
shell: bash
3434
working-directory: ${{ inputs.directory }}
35+
36+
- name: Test dart2wasm
37+
if: ${{ inputs.web == 'true' && (matrix.sdk == 'stable' || matrix.sdk == 'beta') && runner.os != 'Windows' }}
38+
run: dart test -p chrome --compiler dart2wasm --test-randomize-ordering-seed=random --chain-stack-traces
39+
shell: bash
40+
working-directory: ${{ inputs.directory }}

.github/workflows/analyze.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939

4040
- run: ${{ inputs.sdk }} pub get
4141
- run: dart format --set-exit-if-changed ./
42-
42+
4343
- name: dart analyze
4444
uses: invertase/github-action-dart-analyzer@e981b01a458d0bab71ee5da182e5b26687b7101b # [email protected]
4545
with:
@@ -78,6 +78,6 @@ jobs:
7878
PERCENTAGE=$(( $TOTAL * 100 / $TOTAL_MAX ))
7979
if (( $PERCENTAGE < ${{ inputs.panaThreshold }} ))
8080
then
81-
echo Score too low!
81+
echo "Score too low ($PERCENTAGE % is less than the expected ${{ inputs.panaThreshold }} %)!"
8282
exit 1
8383
fi

.github/workflows/dart.yml

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,28 @@ jobs:
2121
access_token: ${{ github.token }}
2222

2323
build:
24-
name: Build ${{matrix.sdk}} on ${{matrix.os}}
25-
runs-on: ${{ matrix.os }}
24+
name: Dart ${{matrix.sdk}} on ${{matrix.os}}
25+
runs-on: ${{ matrix.os }}-latest
2626
timeout-minutes: 30
2727
strategy:
2828
fail-fast: false
2929
matrix:
30-
os: [ubuntu-latest, windows-latest, macos-latest]
31-
sdk: [stable, beta]
32-
exclude:
33-
- os: windows-latest
34-
sdk: beta
35-
- os: macos-latest
36-
sdk: beta
30+
os: [ubuntu]
31+
sdk:
32+
- '2.18'
33+
- '2.19'
34+
- '3.0'
35+
- '3.1'
36+
- '3.2'
37+
- '3.3'
38+
- '3.4'
39+
- stable
40+
- beta
41+
include:
42+
- os: windows
43+
sdk: stable
44+
- os: macos
45+
sdk: stable
3746
steps:
3847
- uses: actions/checkout@v4
3948

@@ -49,24 +58,14 @@ jobs:
4958
coverage: sentry
5059
min-coverage: 85
5160

52-
- name: Install webdev
53-
if: runner.os != 'Windows'
54-
run: dart pub global activate webdev
55-
5661
- name: Build example
5762
working-directory: dart/example
5863
run: |
5964
dart pub get
6065
dart compile aot-snapshot bin/example.dart
6166
62-
- name: Build Web example
63-
if: runner.os != 'Windows'
64-
working-directory: dart/example_web
65-
run: |
66-
dart pub get
67-
webdev build
68-
6967
analyze:
7068
uses: ./.github/workflows/analyze.yml
7169
with:
7270
package: dart
71+
panaThreshold: 87

.github/workflows/flutter.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ jobs:
144144
with:
145145
package: flutter
146146
sdk: flutter
147+
panaThreshold: 87
147148

148149
pod-lint:
149150
runs-on: macos-latest

CHANGELOG.md

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

33
## Unreleased
44

5+
### Features
6+
7+
- Support WebAssembly compilation (dart2wasm) ([#2113](https://github.com/getsentry/sentry-dart/pull/2113))
8+
59
### Dependencies
610

711
- Bump Cocoa SDK from v8.29.0 to v8.29.1 ([#2109](https://github.com/getsentry/sentry-dart/pull/2109))
@@ -122,7 +126,7 @@ This release contains breaking changes, please read the changelog carefully.
122126

123127
### Features
124128

125-
- Experimental: Add support for Sentry Developer Metrics ([#1940](https://github.com/getsentry/sentry-dart/pull/1940), [#1949](https://github.com/getsentry/sentry-dart/pull/1949), [#1954](https://github.com/getsentry/sentry-dart/pull/1954), [#1958](https://github.com/getsentry/sentry-dart/pull/1958))
129+
- Experimental: Add support for Sentry Developer Metrics ([#1940](https://github.com/getsentry/sentry-dart/pull/1940), [#1949](https://github.com/getsentry/sentry-dart/pull/1949), [#1954](https://github.com/getsentry/sentry-dart/pull/1954), [#1958](https://github.com/getsentry/sentry-dart/pull/1958))
126130
Use the Metrics API to track processing time, download sizes, user signups, and conversion rates and correlate them back to tracing data in order to get deeper insights and solve issues faster. Our API supports counters, distributions, sets, gauges and timers, and it's easy to get started:
127131
```dart
128132
Sentry.metrics()
@@ -235,14 +239,14 @@ This release contains breaking changes, please read the changelog carefully.
235239
- Now the device context from Android is available in `BeforeSendCallback`
236240
- Set ip_address to {{auto}} by default, even if sendDefaultPII is disabled ([#1665](https://github.com/getsentry/sentry-dart/pull/1665))
237241
- Instead use the "Prevent Storing of IP Addresses" option in the "Security & Privacy" project settings on sentry.io
238-
239-
### Fixes
242+
243+
### Fixes
240244

241245
- Remove Flutter dependency from Drift integration ([#1867](https://github.com/getsentry/sentry-dart/pull/1867))
242246
- Remove dead code, cold start bool is now always present ([#1861](https://github.com/getsentry/sentry-dart/pull/1861))
243247
- Fix iOS "Arithmetic Overflow" ([#1874](https://github.com/getsentry/sentry-dart/pull/1874))
244248

245-
### Dependencies
249+
### Dependencies
246250

247251
- Bump Cocoa SDK from v8.19.0 to v8.20.0 ([#1856](https://github.com/getsentry/sentry-dart/pull/1856))
248252
- [changelog](https://github.com/getsentry/sentry-cocoa/blob/main/CHANGELOG.md#8200)

dart/example_web/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ environment:
99
dependencies:
1010
sentry:
1111
path: ../../dart/
12+
web: ^0.5.1
1213

1314
dev_dependencies:
1415
build_runner: ^2.4.2

dart/example_web/web/main.dart

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'dart:async';
2-
import 'dart:html';
2+
import 'package:web/web.dart';
33

44
import 'package:sentry/sentry.dart';
55
import 'package:sentry/src/version.dart';
@@ -24,7 +24,7 @@ Future<void> main() async {
2424
Future<void> runApp() async {
2525
print('runApp');
2626

27-
querySelector('#output')?.text = 'Your Dart app is running.';
27+
document.querySelector('#output')?.text = 'Your Dart app is running.';
2828

2929
await Sentry.addBreadcrumb(
3030
Breadcrumb(
@@ -57,12 +57,20 @@ Future<void> runApp() async {
5757
);
5858
});
5959

60-
querySelector('#btEvent')
60+
document
61+
.querySelector('#btEvent')
6162
?.onClick
6263
.listen((event) => captureCompleteExampleEvent());
63-
querySelector('#btMessage')?.onClick.listen((event) => captureMessage());
64-
querySelector('#btException')?.onClick.listen((event) => captureException());
65-
querySelector('#btUnhandledException')
64+
document
65+
.querySelector('#btMessage')
66+
?.onClick
67+
.listen((event) => captureMessage());
68+
document
69+
.querySelector('#btException')
70+
?.onClick
71+
.listen((event) => captureException());
72+
document
73+
.querySelector('#btUnhandledException')
6674
?.onClick
6775
.listen((event) => captureUnhandledException());
6876
}
@@ -76,7 +84,8 @@ Future<void> captureMessage() async {
7684
);
7785
print('capture message result : $sentryId');
7886
if (sentryId != SentryId.empty()) {
79-
querySelector('#messageResult')?.style.display = 'block';
87+
(document.querySelector('#messageResult') as HTMLElement?)?.style.display =
88+
'block';
8089
}
8190
}
8291

@@ -93,13 +102,16 @@ Future<void> captureException() async {
93102
print('Capture exception : SentryId: $sentryId');
94103

95104
if (sentryId != SentryId.empty()) {
96-
querySelector('#exceptionResult')?.style.display = 'block';
105+
(document.querySelector('#exceptionResult') as HTMLElement?)
106+
?.style
107+
.display = 'block';
97108
}
98109
}
99110
}
100111

101112
Future<void> captureUnhandledException() async {
102-
querySelector('#unhandledResult')?.style.display = 'block';
113+
(document.querySelector('#unhandledResult') as HTMLElement?)?.style.display =
114+
'block';
103115

104116
await buildCard();
105117
}
@@ -111,7 +123,8 @@ Future<void> captureCompleteExampleEvent() async {
111123
print('Response SentryId: $sentryId');
112124

113125
if (sentryId != SentryId.empty()) {
114-
querySelector('#eventResult')?.style.display = 'block';
126+
(document.querySelector('#eventResult') as HTMLElement?)?.style.display =
127+
'block';
115128
}
116129
}
117130

dart/example_web_legacy/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Files and directories created by pub
2+
.dart_tool/
3+
.packages
4+
5+
# Conventional directory for build outputs
6+
build/
7+
8+
# Directory created by dartdoc
9+
doc/api/

dart/example_web_legacy/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Sentry Dart : web example
2+
3+
```sh
4+
dart pub get
5+
6+
# run the project ( see https://dart.dev/tools/webdev#serve )
7+
dart run webdev serve --release
8+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include: package:lints/recommended.yaml
2+
3+
analyzer:
4+
errors:
5+
path_does_not_exist: ignore

dart/example_web_legacy/pubspec.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: sentry_dart_web_example
2+
description: An absolute bare-bones web app.
3+
4+
publish_to: 'none'
5+
6+
environment:
7+
sdk: '>=2.17.0 <4.0.0'
8+
9+
dependencies:
10+
sentry:
11+
path: ../../dart/
12+
13+
dev_dependencies:
14+
build_runner: ^2.3.0
15+
build_web_compilers: ^3.2.3
16+
lints: ^2.0.0
17+
webdev: ^2.7.0
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import 'package:sentry/src/protocol.dart';
2+
3+
final event = SentryEvent(
4+
logger: 'main',
5+
serverName: 'server.dart',
6+
release: '1.4.0-preview.1',
7+
environment: 'Test',
8+
message: SentryMessage('This is an example Dart event.'),
9+
tags: const <String, String>{'project-id': '7371'},
10+
// ignore: deprecated_member_use, deprecated_member_use_from_same_package
11+
extra: const <String, String>{'section': '1'},
12+
// fingerprint: const <String>['example-dart'],
13+
user: SentryUser(
14+
id: '800',
15+
username: 'first-user',
16+
17+
// ipAddress: '127.0.0.1',
18+
data: <String, String>{'first-sign-in': '2020-01-01'},
19+
),
20+
breadcrumbs: [
21+
Breadcrumb(
22+
message: 'UI Lifecycle',
23+
timestamp: DateTime.now().toUtc(),
24+
category: 'ui.lifecycle',
25+
type: 'navigation',
26+
data: {'screen': 'MainActivity', 'state': 'created'},
27+
level: SentryLevel.info,
28+
)
29+
],
30+
contexts: Contexts(
31+
operatingSystem: const SentryOperatingSystem(
32+
name: 'Android',
33+
version: '5.0.2',
34+
build: 'LRX22G.P900XXS0BPL2',
35+
kernelVersion:
36+
'Linux version 3.4.39-5726670 (dpi@SWHC3807) (gcc version 4.8 (GCC) ) #1 SMP PREEMPT Thu Dec 1 19:42:39 KST 2016',
37+
rooted: false,
38+
),
39+
runtimes: [const SentryRuntime(name: 'ART', version: '5')],
40+
app: SentryApp(
41+
name: 'Example Dart App',
42+
version: '1.42.0',
43+
identifier: 'HGT-App-13',
44+
build: '93785',
45+
buildType: 'release',
46+
deviceAppHash: '5afd3a6',
47+
startTime: DateTime.now().toUtc(),
48+
),
49+
browser: const SentryBrowser(name: 'Firefox', version: '42.0.1'),
50+
device: SentryDevice(
51+
name: 'SM-P900',
52+
family: 'SM-P900',
53+
model: 'SM-P900 (LRX22G)',
54+
modelId: 'LRX22G',
55+
arch: 'armeabi-v7a',
56+
batteryLevel: 99,
57+
orientation: SentryOrientation.landscape,
58+
manufacturer: 'samsung',
59+
brand: 'samsung',
60+
screenDensity: 2.1,
61+
screenDpi: 320,
62+
online: true,
63+
charging: true,
64+
lowMemory: true,
65+
simulator: false,
66+
memorySize: 1500,
67+
freeMemory: 200,
68+
usableMemory: 4294967296,
69+
storageSize: 4294967296,
70+
freeStorage: 2147483648,
71+
externalStorageSize: 8589934592,
72+
externalFreeStorage: 2863311530,
73+
bootTime: DateTime.now().toUtc(),
74+
),
75+
),
76+
);
3.48 KB
Binary file not shown.

0 commit comments

Comments
 (0)