From b83bd0f502686ad567db5bf5a7f317c692eef37e Mon Sep 17 00:00:00 2001 From: LucasZF Date: Wed, 16 Nov 2022 09:52:41 -0300 Subject: [PATCH] Avoid duplicating Breadcrumbs on Android (#254) * Ignore breadcrumbs if unhandled on Android --- CHANGELOG.md | 4 ++++ src/wrapper.ts | 4 +++- test/wrapper.test.ts | 10 +++------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfdb54d8..df1bac55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Fixes + +- Avoid duplicating Breadcrumbs on Android ([#254](https://github.com/getsentry/sentry-capacitor/pull/254)) + ### Dependencies - Bump Sentry JavaScript SDK to `7.15.0` ([#244](https://github.com/getsentry/sentry-capacitor/pull/244)) diff --git a/src/wrapper.ts b/src/wrapper.ts index c1275117..f35d4da9 100644 --- a/src/wrapper.ts +++ b/src/wrapper.ts @@ -44,8 +44,10 @@ export const NATIVE = { We then remove the breadcrumbs in all cases but if it is handled == false, this is a signal that the app would crash and android would lose the breadcrumbs by the time the app is restarted to read the envelope. + Since unhandled errors from Javascript are not going to crash the App, we can't rely on the + handled flag for filtering breadcrumbs. */ - if (event.exception?.values?.[0]?.mechanism?.handled != false && event.breadcrumbs) { + if (event.breadcrumbs) { event.breadcrumbs = []; } } diff --git a/test/wrapper.test.ts b/test/wrapper.test.ts index d92adfb9..62aa94cd 100644 --- a/test/wrapper.test.ts +++ b/test/wrapper.test.ts @@ -306,7 +306,7 @@ describe('Tests Native Wrapper', () => { exception: { values: [{ mechanism: { - handled: false + handled: true } }] }, @@ -327,18 +327,14 @@ describe('Tests Native Wrapper', () => { }); const expectedPayload = JSON.stringify({ ...event, - breadcrumbs: [ - { - message: 'crumb!', - }, - ], + breadcrumbs: [], message: { message: event.message, }, exception: { values: [{ mechanism: { - handled: false + handled: true } }] }