Skip to content

Commit c9d3212

Browse files
authored
Disable scope sync for cloned scopes (#1628)
1 parent 6852b33 commit c9d3212

File tree

6 files changed

+27
-16
lines changed

6 files changed

+27
-16
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
- Normalize data properties of `SentryUser` and `Breadcrumb` before sending over method channel ([#1591](https://github.com/getsentry/sentry-dart/pull/1591))
1717
- Fixing memory leak issue in SentryFlutterPlugin (Android Plugin) ([#1588](https://github.com/getsentry/sentry-dart/pull/1588))
18+
- Disable scope sync for cloned scopes ([#1628](https://github.com/getsentry/sentry-dart/pull/1628))
1819

1920
### Dependencies
2021

dart/lib/src/scope.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class Scope {
142142
List.unmodifiable(_eventProcessors);
143143

144144
final SentryOptions _options;
145+
bool _enableScopeSync = true;
145146

146147
final List<SentryAttachment> _attachments = [];
147148

@@ -423,7 +424,8 @@ class Scope {
423424
..level = level
424425
..fingerprint = List.from(fingerprint)
425426
.._transaction = _transaction
426-
..span = span;
427+
..span = span
428+
.._enableScopeSync = false;
427429

428430
clone._setUserSync(user);
429431

@@ -461,7 +463,7 @@ class Scope {
461463
}
462464

463465
Future<void> _callScopeObservers(_OnScopeObserver action) async {
464-
if (_options.enableScopeSync) {
466+
if (_options.enableScopeSync && _enableScopeSync) {
465467
for (final scopeObserver in _options.scopeObservers) {
466468
await action(scopeObserver);
467469
}

dart/test/scope_test.dart

+8
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,14 @@ void main() {
375375
expect(1, fixture.mockScopeObserver.numberOfRemoveTagCalls);
376376
});
377377

378+
test('clone has disabled scope sync', () async {
379+
final sut = fixture.getSut(scopeObserver: fixture.mockScopeObserver);
380+
final clone = sut.clone();
381+
382+
await clone.setContexts("fixture-contexts-key", "fixture-contexts-value");
383+
expect(0, fixture.mockScopeObserver.numberOfSetContextsCalls);
384+
});
385+
378386
group('Scope apply', () {
379387
final scopeUser = SentryUser(
380388
id: '800',

dio/test/dio_event_processor_test.dart

+12-12
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void main() {
6767
throwable: throwable,
6868
exceptions: [
6969
fixture.sentryError(throwable),
70-
fixture.sentryError(dioError)
70+
fixture.sentryError(dioError),
7171
],
7272
);
7373
final processedEvent = sut.apply(event) as SentryEvent;
@@ -96,7 +96,7 @@ void main() {
9696
throwable: throwable,
9797
exceptions: [
9898
fixture.sentryError(throwable),
99-
fixture.sentryError(dioError)
99+
fixture.sentryError(dioError),
100100
],
101101
);
102102
final processedEvent = sut.apply(event) as SentryEvent;
@@ -125,7 +125,7 @@ void main() {
125125
throwable: throwable,
126126
exceptions: [
127127
fixture.sentryError(throwable),
128-
fixture.sentryError(dioError)
128+
fixture.sentryError(dioError),
129129
],
130130
);
131131
final processedEvent = sut.apply(event) as SentryEvent;
@@ -177,7 +177,7 @@ void main() {
177177
throwable: throwable,
178178
exceptions: [
179179
fixture.sentryError(throwable),
180-
fixture.sentryError(dioError)
180+
fixture.sentryError(dioError),
181181
],
182182
);
183183
final processedEvent = sut.apply(event) as SentryEvent;
@@ -207,7 +207,7 @@ void main() {
207207
data: 'foobar',
208208
headers: Headers.fromMap(<String, List<String>>{
209209
'foo': ['bar'],
210-
'set-cookie': ['foo=bar']
210+
'set-cookie': ['foo=bar'],
211211
}),
212212
requestOptions: request,
213213
isRedirect: true,
@@ -219,7 +219,7 @@ void main() {
219219
throwable: throwable,
220220
exceptions: [
221221
fixture.sentryError(throwable),
222-
fixture.sentryError(dioError)
222+
fixture.sentryError(dioError),
223223
],
224224
);
225225
final processedEvent = sut.apply(event) as SentryEvent;
@@ -248,7 +248,7 @@ void main() {
248248
response: Response<dynamic>(
249249
data: 'foobar',
250250
headers: Headers.fromMap(<String, List<String>>{
251-
'foo': ['bar']
251+
'foo': ['bar'],
252252
}),
253253
requestOptions: request,
254254
isRedirect: true,
@@ -260,7 +260,7 @@ void main() {
260260
throwable: throwable,
261261
exceptions: [
262262
fixture.sentryError(throwable),
263-
fixture.sentryError(dioError)
263+
fixture.sentryError(dioError),
264264
],
265265
);
266266
final processedEvent = sut.apply(event) as SentryEvent;
@@ -320,7 +320,7 @@ void main() {
320320
throwable: throwable,
321321
exceptions: [
322322
fixture.sentryError(throwable),
323-
fixture.sentryError(dioError)
323+
fixture.sentryError(dioError),
324324
],
325325
);
326326
final processedEvent = sut.apply(event) as SentryEvent;
@@ -338,7 +338,7 @@ void main() {
338338
final dataByType = {
339339
ResponseType.plain: ['plain'],
340340
ResponseType.bytes: [
341-
[1337]
341+
[1337],
342342
],
343343
ResponseType.json: [
344344
9001,
@@ -347,7 +347,7 @@ void main() {
347347
true,
348348
['list'],
349349
{'map-key': 'map-value'},
350-
]
350+
],
351351
};
352352

353353
for (final entry in dataByType.entries) {
@@ -375,7 +375,7 @@ void main() {
375375
throwable: throwable,
376376
exceptions: [
377377
fixture.sentryError(throwable),
378-
fixture.sentryError(dioError)
378+
fixture.sentryError(dioError),
379379
],
380380
);
381381
final processedEvent = sut.apply(event) as SentryEvent;

dio/test/failed_request_interceptor_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class Fixture {
113113

114114
FailedRequestInterceptor getSut({
115115
List<SentryStatusCode> failedRequestStatusCodes = const [
116-
SentryStatusCode.defaultRange()
116+
SentryStatusCode.defaultRange(),
117117
],
118118
List<String> failedRequestTargets = const ['.*'],
119119
}) {

dio/test/mocks.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final fakeEvent = SentryEvent(
4242
type: 'navigation',
4343
data: <String, dynamic>{'screen': 'MainActivity', 'state': 'created'},
4444
level: SentryLevel.info,
45-
)
45+
),
4646
],
4747
contexts: Contexts(
4848
operatingSystem: const SentryOperatingSystem(

0 commit comments

Comments
 (0)