Skip to content

Commit

Permalink
feat(replay): Filter Sentry event breadcrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich committed Jul 1, 2024
1 parent 897829f commit fcd3db2
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions ios/RNSentryReplayBreadcrumbConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@

+ (NSString* _Nullable) getTouchPathMessageFrom:(NSArray* _Nullable) path;

- (id<SentryRRWebEvent> _Nullable)convertFrom:(SentryBreadcrumb *_Nonnull) breadcrumb;

@end
#endif
6 changes: 6 additions & 0 deletions ios/RNSentryReplayBreadcrumbConverter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fcd3db2

Please sign in to comment.