diff --git a/CHANGELOG.md b/CHANGELOG.md index 11059d775d..6a2788c54e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +* Breadcrumbs should not be duplicated if there is no mechanism on Android ([#936](https://github.com/getsentry/sentry-dart/pull/936)) * Maps with Key Object, Object would fail during serialization if not String, Object ([#935](https://github.com/getsentry/sentry-dart/pull/935)) ## 6.6.3 diff --git a/dart/lib/src/sentry_client.dart b/dart/lib/src/sentry_client.dart index 4d116f9e08..5720fbb249 100644 --- a/dart/lib/src/sentry_client.dart +++ b/dart/lib/src/sentry_client.dart @@ -378,12 +378,11 @@ class SentryClient { } SentryEvent _eventWithRemovedBreadcrumbsIfHandled(SentryEvent event) { - final exceptions = event.exceptions ?? []; - final handled = exceptions.isNotEmpty - ? exceptions.first.mechanism?.handled == true - : false; + final foundNotHandled = event.exceptions + ?.any((element) => element.mechanism?.handled == false) ?? + false; - if (handled) { + if (!foundNotHandled) { return event.copyWith(breadcrumbs: []); } else { return event; diff --git a/dart/test/sentry_client_test.dart b/dart/test/sentry_client_test.dart index 8bd7c06b47..e676d9122a 100644 --- a/dart/test/sentry_client_test.dart +++ b/dart/test/sentry_client_test.dart @@ -898,6 +898,28 @@ void main() { expect((capturedEvent.breadcrumbs ?? []).isEmpty, true); }); + test('Clears breadcrumbs on Android if theres no mechanism', () async { + fixture.options.enableScopeSync = true; + fixture.options.platformChecker = + MockPlatformChecker(platform: MockPlatform.android()); + + final client = fixture.getSut(); + final event = SentryEvent(exceptions: [ + SentryException( + type: "type", + value: "value", + ) + ], breadcrumbs: [ + Breadcrumb() + ]); + await client.captureEvent(event); + + final capturedEnvelope = (fixture.transport).envelopes.first; + final capturedEvent = await eventFromEnvelope(capturedEnvelope); + + expect((capturedEvent.breadcrumbs ?? []).isEmpty, true); + }); + test('Does not clear breadcrumbs on Android if mechanism.handled is false', () async { fixture.options.enableScopeSync = true;