From 4ca137069c085e466cdc1071459ec245090795b7 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Tue, 5 Sep 2023 15:02:19 +0200 Subject: [PATCH 1/3] disable scope sync for cloned scopes --- dart/lib/src/scope.dart | 6 ++++-- dart/test/scope_test.dart | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dart/lib/src/scope.dart b/dart/lib/src/scope.dart index f9cb3796aa..fd5f4fdb11 100644 --- a/dart/lib/src/scope.dart +++ b/dart/lib/src/scope.dart @@ -136,6 +136,7 @@ class Scope { List.unmodifiable(_eventProcessors); final SentryOptions _options; + bool _enableScopeSync = true; final List _attachments = []; @@ -412,7 +413,8 @@ class Scope { ..level = level ..fingerprint = List.from(fingerprint) .._transaction = _transaction - ..span = span; + ..span = span + .._enableScopeSync = false; clone._setUserSync(user); @@ -450,7 +452,7 @@ class Scope { } Future _callScopeObservers(_OnScopeObserver action) async { - if (_options.enableScopeSync) { + if (_options.enableScopeSync && _enableScopeSync) { for (final scopeObserver in _options.scopeObservers) { await action(scopeObserver); } diff --git a/dart/test/scope_test.dart b/dart/test/scope_test.dart index e8d2e08bf9..6f21e5e63c 100644 --- a/dart/test/scope_test.dart +++ b/dart/test/scope_test.dart @@ -375,6 +375,14 @@ void main() { expect(1, fixture.mockScopeObserver.numberOfRemoveTagCalls); }); + test('clone has disabled scope sync', () async { + final sut = fixture.getSut(scopeObserver: fixture.mockScopeObserver); + final clone = sut.clone(); + + await clone.setContexts("fixture-contexts-key", "fixture-contexts-value"); + expect(0, fixture.mockScopeObserver.numberOfSetContextsCalls); + }); + group('Scope apply', () { final scopeUser = SentryUser( id: '800', From 880b7372f60bd9aebece10c4fb107c16e897f8bf Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Tue, 5 Sep 2023 15:05:09 +0200 Subject: [PATCH 2/3] run fix & format --- dio/test/dio_event_processor_test.dart | 24 +++++++++---------- dio/test/failed_request_interceptor_test.dart | 2 +- dio/test/mocks.dart | 2 +- sqflite/test/mocks/mocks.dart | 3 ++- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/dio/test/dio_event_processor_test.dart b/dio/test/dio_event_processor_test.dart index af45d0c681..3cd060ea8e 100644 --- a/dio/test/dio_event_processor_test.dart +++ b/dio/test/dio_event_processor_test.dart @@ -67,7 +67,7 @@ void main() { throwable: throwable, exceptions: [ fixture.sentryError(throwable), - fixture.sentryError(dioError) + fixture.sentryError(dioError), ], ); final processedEvent = sut.apply(event) as SentryEvent; @@ -96,7 +96,7 @@ void main() { throwable: throwable, exceptions: [ fixture.sentryError(throwable), - fixture.sentryError(dioError) + fixture.sentryError(dioError), ], ); final processedEvent = sut.apply(event) as SentryEvent; @@ -125,7 +125,7 @@ void main() { throwable: throwable, exceptions: [ fixture.sentryError(throwable), - fixture.sentryError(dioError) + fixture.sentryError(dioError), ], ); final processedEvent = sut.apply(event) as SentryEvent; @@ -177,7 +177,7 @@ void main() { throwable: throwable, exceptions: [ fixture.sentryError(throwable), - fixture.sentryError(dioError) + fixture.sentryError(dioError), ], ); final processedEvent = sut.apply(event) as SentryEvent; @@ -207,7 +207,7 @@ void main() { data: 'foobar', headers: Headers.fromMap(>{ 'foo': ['bar'], - 'set-cookie': ['foo=bar'] + 'set-cookie': ['foo=bar'], }), requestOptions: request, isRedirect: true, @@ -219,7 +219,7 @@ void main() { throwable: throwable, exceptions: [ fixture.sentryError(throwable), - fixture.sentryError(dioError) + fixture.sentryError(dioError), ], ); final processedEvent = sut.apply(event) as SentryEvent; @@ -248,7 +248,7 @@ void main() { response: Response( data: 'foobar', headers: Headers.fromMap(>{ - 'foo': ['bar'] + 'foo': ['bar'], }), requestOptions: request, isRedirect: true, @@ -260,7 +260,7 @@ void main() { throwable: throwable, exceptions: [ fixture.sentryError(throwable), - fixture.sentryError(dioError) + fixture.sentryError(dioError), ], ); final processedEvent = sut.apply(event) as SentryEvent; @@ -320,7 +320,7 @@ void main() { throwable: throwable, exceptions: [ fixture.sentryError(throwable), - fixture.sentryError(dioError) + fixture.sentryError(dioError), ], ); final processedEvent = sut.apply(event) as SentryEvent; @@ -338,7 +338,7 @@ void main() { final dataByType = { ResponseType.plain: ['plain'], ResponseType.bytes: [ - [1337] + [1337], ], ResponseType.json: [ 9001, @@ -347,7 +347,7 @@ void main() { true, ['list'], {'map-key': 'map-value'}, - ] + ], }; for (final entry in dataByType.entries) { @@ -375,7 +375,7 @@ void main() { throwable: throwable, exceptions: [ fixture.sentryError(throwable), - fixture.sentryError(dioError) + fixture.sentryError(dioError), ], ); final processedEvent = sut.apply(event) as SentryEvent; diff --git a/dio/test/failed_request_interceptor_test.dart b/dio/test/failed_request_interceptor_test.dart index 80eede8803..e7fb5a63e1 100644 --- a/dio/test/failed_request_interceptor_test.dart +++ b/dio/test/failed_request_interceptor_test.dart @@ -113,7 +113,7 @@ class Fixture { FailedRequestInterceptor getSut({ List failedRequestStatusCodes = const [ - SentryStatusCode.defaultRange() + SentryStatusCode.defaultRange(), ], List failedRequestTargets = const ['.*'], }) { diff --git a/dio/test/mocks.dart b/dio/test/mocks.dart index 83454cbfb3..5ed6dcd00a 100644 --- a/dio/test/mocks.dart +++ b/dio/test/mocks.dart @@ -42,7 +42,7 @@ final fakeEvent = SentryEvent( type: 'navigation', data: {'screen': 'MainActivity', 'state': 'created'}, level: SentryLevel.info, - ) + ), ], contexts: Contexts( operatingSystem: const SentryOperatingSystem( diff --git a/sqflite/test/mocks/mocks.dart b/sqflite/test/mocks/mocks.dart index 0a3115df74..3f0af8274c 100644 --- a/sqflite/test/mocks/mocks.dart +++ b/sqflite/test/mocks/mocks.dart @@ -33,7 +33,8 @@ ISentrySpan startTransactionShim( DatabaseExecutor, ], customMocks: [ - MockSpec(fallbackGenerators: {#startTransaction: startTransactionShim}) + MockSpec( + fallbackGenerators: {#startTransaction: startTransactionShim}), ], ) void main() {} From c8bc3cc2862d8db8403182f55b8aeb219a6726c7 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Tue, 5 Sep 2023 15:16:58 +0200 Subject: [PATCH 3/3] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd68f3d14a..1d6a265de4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Normalize data properties of `SentryUser` and `Breadcrumb` before sending over method channel ([#1591](https://github.com/getsentry/sentry-dart/pull/1591)) - Fixing memory leak issue in SentryFlutterPlugin (Android Plugin) ([#1588](https://github.com/getsentry/sentry-dart/pull/1588)) +- Disable scope sync for cloned scopes ([#1628](https://github.com/getsentry/sentry-dart/pull/1628)) ### Dependencies