From 494a619bd8891bffe32b95419a8da4810587f3d5 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 27 Sep 2024 17:55:37 +0300 Subject: [PATCH 01/45] Adds breadcrumb origin in RNSentryBreadcrumb dictionary parsing --- android/src/main/java/io/sentry/react/RNSentryBreadcrumb.java | 4 ++++ ios/RNSentryBreadcrumb.m | 1 + 2 files changed, 5 insertions(+) diff --git a/android/src/main/java/io/sentry/react/RNSentryBreadcrumb.java b/android/src/main/java/io/sentry/react/RNSentryBreadcrumb.java index 3fcfffcf83..2c7db0be0d 100644 --- a/android/src/main/java/io/sentry/react/RNSentryBreadcrumb.java +++ b/android/src/main/java/io/sentry/react/RNSentryBreadcrumb.java @@ -48,6 +48,10 @@ public static Breadcrumb fromMap(ReadableMap from) { breadcrumb.setCategory(from.getString("category")); } + if (from.hasKey("origin")) { + breadcrumb.setOrigin(from.getString("origin")); + } + if (from.hasKey("level")) { switch (from.getString("level")) { case "fatal": diff --git a/ios/RNSentryBreadcrumb.m b/ios/RNSentryBreadcrumb.m index e900ba4833..4d0b094eb6 100644 --- a/ios/RNSentryBreadcrumb.m +++ b/ios/RNSentryBreadcrumb.m @@ -23,6 +23,7 @@ +(SentryBreadcrumb*) from: (NSDictionary *) dict [crumb setLevel:sentryLevel]; [crumb setCategory:dict[@"category"]]; + [crumb setOrigin:dict[@"origin"]]; [crumb setType:dict[@"type"]]; [crumb setMessage:dict[@"message"]]; [crumb setData:dict[@"data"]]; From a636be5ea5ab91f1d1b11ab8c4735403fcdf3d43 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Tue, 8 Oct 2024 13:05:18 +0300 Subject: [PATCH 02/45] Use 8.38.0-beta.1 Cocoa SDK that has the new origin field --- RNSentry.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RNSentry.podspec b/RNSentry.podspec index 5059662f04..beca2ba0cf 100644 --- a/RNSentry.podspec +++ b/RNSentry.podspec @@ -37,7 +37,7 @@ Pod::Spec.new do |s| s.compiler_flags = other_cflags - s.dependency 'Sentry/HybridSDK', '8.36.0' + s.dependency 'Sentry/HybridSDK', '8.38.0-beta.1' if defined? install_modules_dependencies # Default React Native dependencies for 0.71 and above (new and legacy architecture) From 197f863e8547fbac608a7df1689004aea71ba686 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Wed, 9 Oct 2024 17:16:55 +0300 Subject: [PATCH 03/45] Adds changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54033f5b6d..f5221a10a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +- Adds breadcrumb origin field to prevent exception capture context from being overwritten by native scope sync ([#4124](https://github.com/getsentry/sentry-react-native/pull/4124)) - Use `appLaunchedInForeground` to determine invalid app start data on Android ([#4146](https://github.com/getsentry/sentry-react-native/pull/4146)) - Upload source maps for all release variants on Android (not only the last found) ([#4125](https://github.com/getsentry/sentry-react-native/pull/4125)) From 9bee5c9af25a625061510a7a30b5fff92f0e2a21 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Wed, 9 Oct 2024 17:51:20 +0300 Subject: [PATCH 04/45] Fixes sentry-java breaking changes --- android/src/main/java/io/sentry/react/RNSentryModuleImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/io/sentry/react/RNSentryModuleImpl.java b/android/src/main/java/io/sentry/react/RNSentryModuleImpl.java index cd498308f3..37e36bb4c1 100644 --- a/android/src/main/java/io/sentry/react/RNSentryModuleImpl.java +++ b/android/src/main/java/io/sentry/react/RNSentryModuleImpl.java @@ -317,7 +317,7 @@ private SentryReplayOptions getReplayOptions(@NotNull ReadableMap rnOptions) { androidReplayOptions.setSessionSampleRate(rnExperimentsOptions.hasKey("replaysSessionSampleRate") ? rnExperimentsOptions.getDouble("replaysSessionSampleRate") : null); - androidReplayOptions.setErrorSampleRate(rnExperimentsOptions.hasKey("replaysOnErrorSampleRate") + androidReplayOptions.setOnErrorSampleRate(rnExperimentsOptions.hasKey("replaysOnErrorSampleRate") ? rnExperimentsOptions.getDouble("replaysOnErrorSampleRate") : null); if (!rnOptions.hasKey("mobileReplayOptions")) { @@ -333,7 +333,7 @@ private SentryReplayOptions getReplayOptions(@NotNull ReadableMap rnOptions) { final boolean redactVectors = !rnMobileReplayOptions.hasKey("maskAllVectors") || rnMobileReplayOptions.getBoolean("maskAllVectors"); if (redactVectors) { - androidReplayOptions.addClassToRedact("com.horcrux.svg.SvgView"); // react-native-svg + androidReplayOptions.addRedactViewClass("com.horcrux.svg.SvgView"); // react-native-svg } return androidReplayOptions; From 611cd97f7175edd4f5bb6af1d522ce43058f8cc0 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Wed, 23 Oct 2024 16:15:54 +0300 Subject: [PATCH 05/45] Adds origin native tests --- .../RNSentryBreadcrumbTest.kt | 23 +++++++++++++++++++ .../project.pbxproj | 2 ++ .../RNSentryBreadcrumbTests.swift | 4 +++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/core/RNSentryAndroidTester/app/src/test/java/io/sentry/rnsentryandroidtester/RNSentryBreadcrumbTest.kt b/packages/core/RNSentryAndroidTester/app/src/test/java/io/sentry/rnsentryandroidtester/RNSentryBreadcrumbTest.kt index a41c3b964d..f1ae67e33e 100644 --- a/packages/core/RNSentryAndroidTester/app/src/test/java/io/sentry/rnsentryandroidtester/RNSentryBreadcrumbTest.kt +++ b/packages/core/RNSentryAndroidTester/app/src/test/java/io/sentry/rnsentryandroidtester/RNSentryBreadcrumbTest.kt @@ -1,6 +1,7 @@ package io.sentry.rnsentryandroidtester import com.facebook.react.bridge.JavaOnlyMap +import io.sentry.SentryLevel import io.sentry.react.RNSentryBreadcrumb import junit.framework.TestCase.assertEquals import org.junit.Test @@ -10,6 +11,28 @@ import org.junit.runners.JUnit4 @RunWith(JUnit4::class) class RNSentryBreadcrumbTest { + @Test + fun generatesSentryBreadcrumbFromMap() { + val testData = JavaOnlyMap.of( + "test", "data", + ) + val map = JavaOnlyMap.of( + "level", "error", + "category", "testCategory", + "origin", "testOrigin", + "type", "testType", + "message", "testMessage", + "data", testData, + ) + val actual = RNSentryBreadcrumb.fromMap(map) + assertEquals(SentryLevel.ERROR, actual.level) + assertEquals("testCategory", actual.category) + assertEquals("testOrigin", actual.origin) + assertEquals("testType", actual.type) + assertEquals("testMessage", actual.message) + assertEquals(testData.toHashMap(), actual.data) + } + @Test fun nullForMissingCategory() { val map = JavaOnlyMap.of() diff --git a/packages/core/RNSentryCocoaTester/RNSentryCocoaTester.xcodeproj/project.pbxproj b/packages/core/RNSentryCocoaTester/RNSentryCocoaTester.xcodeproj/project.pbxproj index b1cc2aa6f4..a473ae7d57 100644 --- a/packages/core/RNSentryCocoaTester/RNSentryCocoaTester.xcodeproj/project.pbxproj +++ b/packages/core/RNSentryCocoaTester/RNSentryCocoaTester.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 33AFDFED2B8D14B300AAB120 /* RNSentryFramesTrackerListenerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33AFDFEC2B8D14B300AAB120 /* RNSentryFramesTrackerListenerTests.m */; }; 33AFDFF12B8D15E500AAB120 /* RNSentryDependencyContainerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33AFDFF02B8D15E500AAB120 /* RNSentryDependencyContainerTests.m */; }; 33F58AD02977037D008F60EA /* RNSentryTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 33F58ACF2977037D008F60EA /* RNSentryTests.mm */; }; + AEFB00422CC90C4B00EC8A9A /* RNSentryBreadcrumbTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3360843C2C340C76008CC412 /* RNSentryBreadcrumbTests.swift */; }; B5859A50A3E865EF5E61465A /* libPods-RNSentryCocoaTesterTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 650CB718ACFBD05609BF2126 /* libPods-RNSentryCocoaTesterTests.a */; }; /* End PBXBuildFile section */ @@ -212,6 +213,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + AEFB00422CC90C4B00EC8A9A /* RNSentryBreadcrumbTests.swift in Sources */, 33AFDFF12B8D15E500AAB120 /* RNSentryDependencyContainerTests.m in Sources */, 336084392C32E382008CC412 /* RNSentryReplayBreadcrumbConverterTests.swift in Sources */, 33F58AD02977037D008F60EA /* RNSentryTests.mm in Sources */, diff --git a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryBreadcrumbTests.swift b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryBreadcrumbTests.swift index f4bd3ce8e9..9979f0cb58 100644 --- a/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryBreadcrumbTests.swift +++ b/packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryBreadcrumbTests.swift @@ -1,12 +1,13 @@ import XCTest import Sentry -class RNSentryBreadcrumbTests: XCTestCase { +final class RNSentryBreadcrumbTests: XCTestCase { func testGeneratesSentryBreadcrumbFromNSDictionary() { let actualCrumb = RNSentryBreadcrumb.from([ "level": "error", "category": "testCategory", + "origin": "testOrigin", "type": "testType", "message": "testMessage", "data": [ @@ -16,6 +17,7 @@ class RNSentryBreadcrumbTests: XCTestCase { XCTAssertEqual(actualCrumb!.level, SentryLevel.error) XCTAssertEqual(actualCrumb!.category, "testCategory") + XCTAssertEqual(actualCrumb!.origin, "testOrigin") XCTAssertEqual(actualCrumb!.type, "testType") XCTAssertEqual(actualCrumb!.message, "testMessage") XCTAssertEqual((actualCrumb!.data)!["test"] as! String, "data") From 37553f296a99d532ff69a63c1953247c67ec7d1e Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Wed, 23 Oct 2024 16:16:52 +0300 Subject: [PATCH 06/45] Adds Capture exception with breadcrumb in the sample --- samples/react-native/src/Screens/ErrorsScreen.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/samples/react-native/src/Screens/ErrorsScreen.tsx b/samples/react-native/src/Screens/ErrorsScreen.tsx index 6430440295..2890f8d19d 100644 --- a/samples/react-native/src/Screens/ErrorsScreen.tsx +++ b/samples/react-native/src/Screens/ErrorsScreen.tsx @@ -88,6 +88,13 @@ const ErrorsScreen = (_props: Props) => { Sentry.captureException(error); }} /> +