From fcd3db2fdd75b12aaa1bb665ba2179f9ae0f8037 Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Mon, 1 Jul 2024 19:26:48 +0200 Subject: [PATCH] feat(replay): Filter Sentry event breadcrumbs --- CHANGELOG.md | 1 + .../RNSentryReplayBreadcrumbConverterTest.kt | 19 ++++++++++++++++ ...SentryReplayBreadcrumbConverterTests.swift | 22 ++++++++++++++++--- .../RNSentryReplayBreadcrumbConverter.java | 6 +++++ ios/RNSentryReplayBreadcrumbConverter.h | 2 ++ ios/RNSentryReplayBreadcrumbConverter.m | 6 +++++ 6 files changed, 53 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 808d4feb65..1d082742df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Improve touch event component info if annotated with [`@sentry/babel-plugin-component-annotate`](https://www.npmjs.com/package/@sentry/babel-plugin-component-annotate) ([#3899](https://github.com/getsentry/sentry-react-native/pull/3899)) - Add replay breadcrumbs for touch & navigation events ([#3846](https://github.com/getsentry/sentry-react-native/pull/3846)) - Add network data to Session Replays ([#3912](https://github.com/getsentry/sentry-react-native/pull/3912)) +- Filter Sentry Event Breadcrumbs from Mobile Replays ### Dependencies diff --git a/RNSentryAndroidTester/app/src/test/java/io/sentry/rnsentryandroidtester/RNSentryReplayBreadcrumbConverterTest.kt b/RNSentryAndroidTester/app/src/test/java/io/sentry/rnsentryandroidtester/RNSentryReplayBreadcrumbConverterTest.kt index 7b3c6b8ac1..fbc7e2ef55 100644 --- a/RNSentryAndroidTester/app/src/test/java/io/sentry/rnsentryandroidtester/RNSentryReplayBreadcrumbConverterTest.kt +++ b/RNSentryAndroidTester/app/src/test/java/io/sentry/rnsentryandroidtester/RNSentryReplayBreadcrumbConverterTest.kt @@ -1,5 +1,6 @@ package io.sentry.rnsentryandroidtester +import io.sentry.Breadcrumb import io.sentry.react.RNSentryReplayBreadcrumbConverter import org.junit.Assert.assertEquals import org.junit.Test @@ -9,6 +10,24 @@ import org.junit.runners.JUnit4 @RunWith(JUnit4::class) class RNSentryReplayBreadcrumbConverterTest { + @Test + fun doesNotConvertSentryEventBreadcrumb() { + val converter = RNSentryReplayBreadcrumbConverter() + val testBreadcrumb = Breadcrumb(); + testBreadcrumb.category = "sentry.event" + val actual = converter.convert(testBreadcrumb) + assertEquals(null, actual) + } + + @Test + fun doesNotConvertSentryTransactionBreadcrumb() { + val converter = RNSentryReplayBreadcrumbConverter() + val testBreadcrumb = Breadcrumb(); + testBreadcrumb.category = "sentry.transaction" + val actual = converter.convert(testBreadcrumb) + assertEquals(null, actual) + } + @Test fun doesNotConvertNullPath() { val actual = RNSentryReplayBreadcrumbConverter.getTouchPathMessage(null) diff --git a/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryReplayBreadcrumbConverterTests.swift b/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryReplayBreadcrumbConverterTests.swift index 09b94b2bca..ca287f1394 100644 --- a/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryReplayBreadcrumbConverterTests.swift +++ b/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryReplayBreadcrumbConverterTests.swift @@ -1,14 +1,30 @@ import XCTest final class RNSentryReplayBreadcrumbConverterTests: XCTestCase { - + + func testNotConvertSentryEventBreadcrumb() { + let converter = RNSentryReplayBreadcrumbConverter() + let testBreadcrumb = Breadcrumb() + testBreadcrumb.category = "sentry.event" + let actual = converter.convert(from: testBreadcrumb) + XCTAssertNil(actual) + } + + func testNotConvertSentryTransactionBreadcrumb() { + let converter = RNSentryReplayBreadcrumbConverter() + let testBreadcrumb = Breadcrumb() + testBreadcrumb.category = "sentry.transaction" + let actual = converter.convert(from: testBreadcrumb) + XCTAssertNil(actual) + } + func testTouchMessageReturnsNilOnEmptyArray() throws { - let actual = RNSentryReplayBreadcrumbConverter.getTouchPathMessage(from: []) + let actual = RNSentryReplayBreadcrumbConverter.getTouchPathMessage(from: []) XCTAssertEqual(actual, nil); } func testTouchMessageReturnsNilOnNilArray() throws { - let actual = RNSentryReplayBreadcrumbConverter.getTouchPathMessage(from: nil as [Any]?) + let actual = RNSentryReplayBreadcrumbConverter.getTouchPathMessage(from: nil as [Any]?) XCTAssertEqual(actual, nil); } diff --git a/android/src/main/java/io/sentry/react/RNSentryReplayBreadcrumbConverter.java b/android/src/main/java/io/sentry/react/RNSentryReplayBreadcrumbConverter.java index 36b3b9c57a..c402190ade 100644 --- a/android/src/main/java/io/sentry/react/RNSentryReplayBreadcrumbConverter.java +++ b/android/src/main/java/io/sentry/react/RNSentryReplayBreadcrumbConverter.java @@ -24,6 +24,12 @@ public RNSentryReplayBreadcrumbConverter() { return null; } + // Do not add Sentry Event breadcrumbs to replay + if (breadcrumb.getCategory().equals("sentry.event") || + breadcrumb.getCategory().equals("sentry.transaction")) { + return null; + } + if (breadcrumb.getCategory().equals("touch")) { return convertTouchBreadcrumb(breadcrumb); } diff --git a/ios/RNSentryReplayBreadcrumbConverter.h b/ios/RNSentryReplayBreadcrumbConverter.h index 92a2451cca..ce12fcf39c 100644 --- a/ios/RNSentryReplayBreadcrumbConverter.h +++ b/ios/RNSentryReplayBreadcrumbConverter.h @@ -10,5 +10,7 @@ + (NSString* _Nullable) getTouchPathMessageFrom:(NSArray* _Nullable) path; +- (id _Nullable)convertFrom:(SentryBreadcrumb *_Nonnull) breadcrumb; + @end #endif diff --git a/ios/RNSentryReplayBreadcrumbConverter.m b/ios/RNSentryReplayBreadcrumbConverter.m index 17be5509cd..056da5ee0a 100644 --- a/ios/RNSentryReplayBreadcrumbConverter.m +++ b/ios/RNSentryReplayBreadcrumbConverter.m @@ -20,6 +20,12 @@ - (instancetype _Nonnull)init { (SentryBreadcrumb *_Nonnull)breadcrumb { assert(breadcrumb.timestamp != nil); + if ([breadcrumb.category isEqualToString:@"sentry.event"] || + [breadcrumb.category isEqualToString:@"sentry.transaction"]) { + // Do not add Sentry Event breadcrumbs to replay + return nil; + } + if ([breadcrumb.category isEqualToString:@"http"]) { // Drop native network breadcrumbs to avoid duplicates return nil;