Skip to content

Commit ea071ab

Browse files
authored
[v9] Enable JS SDK native integration by default (#2688)
* load js by default * fix test * update CHANGELOG * maybe fix integration test * remove enableSentryJs * fix test
1 parent 5ce593b commit ea071ab

File tree

9 files changed

+17
-82
lines changed

9 files changed

+17
-82
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Remove deprecated `beforeScreenshot` ([#2662](https://github.com/getsentry/sentry-dart/pull/2662))
1111
- Remove deprecated loggers ([#2685](https://github.com/getsentry/sentry-dart/pull/2685))
1212
- Remove user segment ([#2687](https://github.com/getsentry/sentry-dart/pull/2687))
13+
- Enable JS SDK native integration by default ([#2688](https://github.com/getsentry/sentry-dart/pull/2688))
1314
- Remove `enableTracing` ([#2695](https://github.com/getsentry/sentry-dart/pull/2695))
1415
- Remove `options.autoAppStart` and `setAppStartEnd` ([#2680](https://github.com/getsentry/sentry-dart/pull/2680))
1516
- Add hint for transactions ([#2675](https://github.com/getsentry/sentry-dart/pull/2675))

dart/lib/src/sentry_client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class SentryClient {
6363
options,
6464
options.transport,
6565
);
66-
// TODO: Web might change soon to use the JS SDK so we can remove it here later on
66+
// TODO: Use spotlight integration directly through JS SDK, then we can remove isWeb check
6767
final enableFlutterSpotlight = (options.spotlight.enabled &&
6868
(options.platformChecker.isWeb ||
6969
options.platformChecker.platform.isLinux ||

flutter/example/integration_test/web_sdk_test.dart

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import 'dart:js_interop_unsafe';
1111
import 'package:flutter_test/flutter_test.dart';
1212
import 'package:integration_test/integration_test.dart';
1313
import 'package:sentry_flutter/sentry_flutter.dart';
14-
import 'package:sentry_flutter/src/web/javascript_transport.dart';
1514
import 'package:sentry_flutter_example/main.dart' as app;
1615

1716
import 'utils.dart';
@@ -48,11 +47,14 @@ void main() {
4847
group('Web SDK Integration', () {
4948
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
5049

50+
tearDown(() async {
51+
await Sentry.close();
52+
});
53+
5154
group('enabled', () {
5255
testWidgets('Sentry JS SDK initialized', (tester) async {
5356
await restoreFlutterOnErrorAfter(() async {
5457
await SentryFlutter.init((options) {
55-
options.enableSentryJs = true;
5658
options.dsn = fakeDsn;
5759
}, appRunner: () async {
5860
await tester.pumpWidget(const app.MyApp());
@@ -72,25 +74,20 @@ void main() {
7274
});
7375

7476
testWidgets('sends the correct envelope', (tester) async {
75-
SentryFlutterOptions? configuredOptions;
7677
SentryEvent? dartEvent;
7778

7879
await restoreFlutterOnErrorAfter(() async {
7980
await SentryFlutter.init((options) {
80-
options.enableSentryJs = true;
8181
options.dsn = fakeDsn;
8282
options.beforeSend = (event, hint) {
8383
dartEvent = event;
8484
return event;
8585
};
86-
configuredOptions = options;
8786
}, appRunner: () async {
8887
await tester.pumpWidget(const app.MyApp());
8988
});
9089
});
9190

92-
expect(configuredOptions!.transport, isA<JavascriptTransport>());
93-
9491
final client = _getClient()!;
9592
final completer = Completer<List<Object?>>();
9693

@@ -131,7 +128,6 @@ void main() {
131128

132129
await restoreFlutterOnErrorAfter(() async {
133130
await SentryFlutter.init((options) {
134-
options.enableSentryJs = true;
135131
options.dsn = fakeDsn;
136132
options.attachScreenshot = true;
137133

@@ -165,8 +161,8 @@ void main() {
165161
testWidgets('Sentry JS SDK is not initialized', (tester) async {
166162
await restoreFlutterOnErrorAfter(() async {
167163
await SentryFlutter.init((options) {
168-
options.enableSentryJs = false;
169164
options.dsn = fakeDsn;
165+
options.autoInitializeNativeSdk = false;
170166
}, appRunner: () async {
171167
await tester.pumpWidget(const app.MyApp());
172168
});

flutter/example/lib/main.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ Future<void> setupSentry(
8181
options.debug = kDebugMode;
8282
options.spotlight = Spotlight(enabled: true);
8383
options.enableTimeToFullDisplayTracing = true;
84-
options.enableSentryJs = true;
8584

8685
options.maxRequestBodySize = MaxRequestBodySize.always;
8786
options.maxResponseBodySize = MaxResponseBodySize.always;

flutter/lib/src/integrations/web_sdk_integration.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'package:sentry/sentry.dart';
55

66
import '../native/sentry_native_binding.dart';
77
import '../sentry_flutter_options.dart';
8-
import '../web/javascript_transport.dart';
98
import '../web/script_loader/sentry_script_loader.dart';
109
import '../web/sentry_js_bundle.dart';
1110

@@ -27,7 +26,7 @@ class WebSdkIntegration implements Integration<SentryFlutterOptions> {
2726

2827
@override
2928
FutureOr<void> call(Hub hub, SentryFlutterOptions options) async {
30-
if (!options.enableSentryJs || !options.autoInitializeNativeSdk) {
29+
if (!options.autoInitializeNativeSdk) {
3130
return;
3231
}
3332

@@ -39,9 +38,6 @@ class WebSdkIntegration implements Integration<SentryFlutterOptions> {
3938
: productionScripts;
4039
await _scriptLoader.loadWebSdk(scripts);
4140
await _web.init(hub);
42-
if (_web.supportsCaptureEnvelope) {
43-
options.transport = JavascriptTransport(_web, options);
44-
}
4541
options.sdk.addIntegration(name);
4642
} catch (exception, stackTrace) {
4743
options.logger(

flutter/lib/src/sentry_flutter.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import 'replay/integration.dart';
2929
import 'utils/platform_dispatcher_wrapper.dart';
3030
import 'version.dart';
3131
import 'view_hierarchy/view_hierarchy_integration.dart';
32+
import 'web/javascript_transport.dart';
3233

3334
/// Configuration options callback
3435
typedef FlutterOptionsConfiguration = FutureOr<void> Function(
@@ -125,10 +126,9 @@ mixin SentryFlutter {
125126
// Not all platforms have a native integration.
126127
if (_native != null) {
127128
if (_native!.supportsCaptureEnvelope) {
128-
// Sentry's native web integration is only enabled when enableSentryJs=true.
129-
// Transport configuration happens in web_integration because the configuration
130-
// options aren't available until after the options callback executes.
131-
if (!options.platformChecker.isWeb) {
129+
if (options.platformChecker.isWeb) {
130+
options.transport = JavascriptTransport(_native!, options);
131+
} else {
132132
options.transport = FileSystemTransport(_native!, options);
133133
}
134134
}

flutter/lib/src/sentry_flutter_options.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,6 @@ class SentryFlutterOptions extends SentryOptions {
284284
/// you must use `SentryWidgetsFlutterBinding.ensureInitialized()` instead.
285285
bool enableFramesTracking = true;
286286

287-
/// Controls initialization of the Sentry Javascript SDK on web platforms.
288-
/// When enabled and [autoInitializeNativeSdk] is true, loads and initializes
289-
/// the JS SDK in the document head.
290-
///
291-
/// Defaults to `false`
292-
bool enableSentryJs = false;
293-
294287
/// By using this, you are disabling native [Breadcrumb] tracking and instead
295288
/// you are just tracking [Breadcrumb]s which result from events available
296289
/// in the current Flutter environment.

flutter/test/integrations/web_sdk_integration_test.dart

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ library;
33

44
import 'package:flutter_test/flutter_test.dart';
55
import 'package:mockito/mockito.dart';
6-
import 'package:sentry/src/transport/noop_transport.dart';
76
import 'package:sentry_flutter/src/integrations/web_sdk_integration.dart';
8-
import 'package:sentry_flutter/src/web/javascript_transport.dart';
97
import 'package:sentry_flutter/src/web/script_loader/sentry_script_loader.dart';
108

119
import '../mocks.dart';
@@ -27,7 +25,6 @@ void main() {
2725

2826
group('enabled', () {
2927
setUp(() {
30-
fixture.options.enableSentryJs = true;
3128
fixture.options.autoInitializeNativeSdk = true;
3229
});
3330

@@ -52,17 +49,9 @@ void main() {
5249
_TestScenario(
5350
'with autoInitializeNativeSdk=false',
5451
() {
55-
fixture.options.enableSentryJs = true;
5652
fixture.options.autoInitializeNativeSdk = false;
5753
},
5854
),
59-
_TestScenario(
60-
'with enableSentryJs=false',
61-
() {
62-
fixture.options.enableSentryJs = false;
63-
fixture.options.autoInitializeNativeSdk = true;
64-
},
65-
),
6655
];
6756

6857
for (final scenario in disabledScenarios) {
@@ -84,46 +73,6 @@ void main() {
8473
}
8574
});
8675

87-
group('transport configuration', () {
88-
test('integration disabled: does not use javascript transport', () async {
89-
fixture.options.enableSentryJs = false;
90-
fixture.options.autoInitializeNativeSdk = false;
91-
92-
expect(fixture.options.transport, isA<NoOpTransport>());
93-
94-
await sut.call(fixture.hub, fixture.options);
95-
96-
expect(fixture.options.transport, isA<NoOpTransport>());
97-
});
98-
99-
test(
100-
'integration enabled and supportsCaptureEnvelope is false: does not use javascript transport',
101-
() async {
102-
fixture.options.enableSentryJs = true;
103-
fixture.options.autoInitializeNativeSdk = true;
104-
when(fixture.web.supportsCaptureEnvelope).thenReturn(false);
105-
106-
expect(fixture.options.transport, isA<NoOpTransport>());
107-
108-
await sut.call(fixture.hub, fixture.options);
109-
110-
expect(fixture.options.transport, isA<NoOpTransport>());
111-
});
112-
113-
test(
114-
'integration enabled and supportsCaptureEnvelope is true: uses javascript transport',
115-
() async {
116-
fixture.options.enableSentryJs = true;
117-
fixture.options.autoInitializeNativeSdk = true;
118-
119-
expect(fixture.options.transport, isA<NoOpTransport>());
120-
121-
await sut.call(fixture.hub, fixture.options);
122-
123-
expect(fixture.options.transport, isA<JavascriptTransport>());
124-
});
125-
});
126-
12776
test('closes resources', () async {
12877
await sut.close();
12978

flutter/test/sentry_flutter_test.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import 'package:sentry_flutter/src/renderer/renderer.dart';
1717
import 'package:sentry_flutter/src/replay/integration.dart';
1818
import 'package:sentry_flutter/src/version.dart';
1919
import 'package:sentry_flutter/src/view_hierarchy/view_hierarchy_integration.dart';
20+
import 'package:sentry_flutter/src/web/javascript_transport.dart';
2021

2122
import 'mocks.dart';
2223
import 'mocks.mocks.dart';
@@ -336,7 +337,7 @@ void main() {
336337
options: sentryFlutterOptions,
337338
);
338339

339-
expect(transport, isNot(isA<FileSystemTransport>()));
340+
expect(transport, isA<JavascriptTransport>());
340341

341342
testScopeObserver(
342343
options: sentryFlutterOptions,
@@ -409,7 +410,7 @@ void main() {
409410
options: sentryFlutterOptions,
410411
);
411412

412-
expect(transport, isNot(isA<FileSystemTransport>()));
413+
expect(transport, isA<JavascriptTransport>());
413414

414415
testConfiguration(
415416
integrations: integrations,
@@ -452,7 +453,7 @@ void main() {
452453
options: sentryFlutterOptions,
453454
);
454455

455-
expect(transport, isNot(isA<FileSystemTransport>()));
456+
expect(transport, isA<JavascriptTransport>());
456457

457458
testConfiguration(
458459
integrations: integrations,
@@ -495,7 +496,7 @@ void main() {
495496
options: sentryFlutterOptions,
496497
);
497498

498-
expect(transport, isNot(isA<FileSystemTransport>()));
499+
expect(transport, isA<JavascriptTransport>());
499500

500501
testConfiguration(
501502
integrations: integrations,

0 commit comments

Comments
 (0)