Skip to content

Commit 3b28c40

Browse files
fix(replay): Add app lifecycle breadcrumbs conversion tests (#3932)
1 parent 6067ecc commit 3b28c40

File tree

5 files changed

+65
-12
lines changed

5 files changed

+65
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
module.exports = withSentryConfig(getDefaultConfig(__dirname), { annotateReactComponents: true });
1818
```
1919

20+
### Fixes
21+
22+
- Add `app.foreground/background` breadcrumbs to iOS Replays ([#3932](https://github.com/getsentry/sentry-react-native/pull/3932))
23+
2024
## 5.25.0-alpha.2
2125

2226
### Features

RNSentryAndroidTester/app/src/test/java/io/sentry/rnsentryandroidtester/RNSentryReplayBreadcrumbConverterTest.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package io.sentry.rnsentryandroidtester
22

33
import io.sentry.Breadcrumb
44
import io.sentry.react.RNSentryReplayBreadcrumbConverter
5+
import io.sentry.rrweb.RRWebBreadcrumbEvent
56
import org.junit.Assert.assertEquals
67
import org.junit.Test
78
import org.junit.runner.RunWith
@@ -10,6 +11,30 @@ import org.junit.runners.JUnit4
1011
@RunWith(JUnit4::class)
1112
class RNSentryReplayBreadcrumbConverterTest {
1213

14+
@Test
15+
fun testConvertForegroundBreadcrumb() {
16+
val converter = RNSentryReplayBreadcrumbConverter()
17+
val testBreadcrumb = Breadcrumb()
18+
testBreadcrumb.type = "navigation"
19+
testBreadcrumb.category = "app.lifecycle"
20+
testBreadcrumb.setData("state", "foreground");
21+
val actual = converter.convert(testBreadcrumb) as RRWebBreadcrumbEvent
22+
23+
assertEquals("app.foreground", actual.category)
24+
}
25+
26+
@Test
27+
fun testConvertBackgroundBreadcrumb() {
28+
val converter = RNSentryReplayBreadcrumbConverter()
29+
val testBreadcrumb = Breadcrumb()
30+
testBreadcrumb.type = "navigation"
31+
testBreadcrumb.category = "app.lifecycle"
32+
testBreadcrumb.setData("state", "background");
33+
val actual = converter.convert(testBreadcrumb) as RRWebBreadcrumbEvent
34+
35+
assertEquals("app.background", actual.category)
36+
}
37+
1338
@Test
1439
fun doesNotConvertSentryEventBreadcrumb() {
1540
val converter = RNSentryReplayBreadcrumbConverter()

RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryReplayBreadcrumbConverterTests.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@ import XCTest
22

33
final class RNSentryReplayBreadcrumbConverterTests: XCTestCase {
44

5+
func testConvertForegroundBreadcrumb() {
6+
let converter = RNSentryReplayBreadcrumbConverter()
7+
let testBreadcrumb = Breadcrumb()
8+
testBreadcrumb.type = "navigation"
9+
testBreadcrumb.category = "app.lifecycle"
10+
testBreadcrumb.data = ["state": "foreground"]
11+
let actual = converter.convert(from: testBreadcrumb)
12+
13+
XCTAssertNotNil(actual)
14+
let data = actual!.serialize()["data"] as! [String: Any?];
15+
let payload = data["payload"] as! [String: Any?];
16+
XCTAssertEqual(payload["category"] as! String, "app.foreground")
17+
}
18+
19+
func testConvertBackgroundBreadcrumb() {
20+
let converter = RNSentryReplayBreadcrumbConverter()
21+
let testBreadcrumb = Breadcrumb()
22+
testBreadcrumb.type = "navigation"
23+
testBreadcrumb.category = "app.lifecycle"
24+
testBreadcrumb.data = ["state": "background"]
25+
let actual = converter.convert(from: testBreadcrumb)
26+
27+
XCTAssertNotNil(actual)
28+
let data = actual!.serialize()["data"] as! [String: Any?];
29+
let payload = data["payload"] as! [String: Any?];
30+
XCTAssertEqual(payload["category"] as! String, "app.background")
31+
}
32+
533
func testNotConvertSentryEventBreadcrumb() {
634
let converter = RNSentryReplayBreadcrumbConverter()
735
let testBreadcrumb = Breadcrumb()

android/src/main/java/io/sentry/react/RNSentryReplayBreadcrumbConverter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public RNSentryReplayBreadcrumbConverter() {
2929
breadcrumb.getCategory().equals("sentry.transaction")) {
3030
return null;
3131
}
32+
if (breadcrumb.getCategory().equals("http")) {
33+
// Drop native http breadcrumbs to avoid duplicates
34+
return null;
35+
}
3236

3337
if (breadcrumb.getCategory().equals("touch")) {
3438
return convertTouchBreadcrumb(breadcrumb);
@@ -42,10 +46,6 @@ public RNSentryReplayBreadcrumbConverter() {
4246
if (breadcrumb.getCategory().equals("xhr")) {
4347
return convertNetworkBreadcrumb(breadcrumb);
4448
}
45-
if (breadcrumb.getCategory().equals("http")) {
46-
// Drop native http breadcrumbs to avoid duplicates
47-
return null;
48-
}
4949

5050
RRWebEvent nativeBreadcrumb = super.convert(breadcrumb);
5151

ios/RNSentryReplayBreadcrumbConverter.m

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,11 @@ - (instancetype _Nonnull)init {
2525
// Do not add Sentry Event breadcrumbs to replay
2626
return nil;
2727
}
28-
28+
2929
if ([breadcrumb.category isEqualToString:@"http"]) {
3030
// Drop native network breadcrumbs to avoid duplicates
3131
return nil;
3232
}
33-
if ([breadcrumb.type isEqualToString:@"navigation"] && ![breadcrumb.category isEqualToString:@"navigation"]) {
34-
// Drop native navigation breadcrumbs to avoid duplicates
35-
return nil;
36-
}
3733

3834
if ([breadcrumb.category isEqualToString:@"touch"]) {
3935
return [self convertTouch:breadcrumb];
@@ -71,7 +67,7 @@ - (instancetype _Nonnull)init {
7167
if (breadcrumb.data == nil) {
7268
return nil;
7369
}
74-
70+
7571
NSMutableArray *path = [breadcrumb.data valueForKey:@"path"];
7672
NSString* message = [RNSentryReplayBreadcrumbConverter getTouchPathMessageFrom:path];
7773

@@ -87,7 +83,7 @@ + (NSString* _Nullable) getTouchPathMessageFrom:(NSArray* _Nullable) path {
8783
if (path == nil) {
8884
return nil;
8985
}
90-
86+
9187
NSInteger pathCount = [path count];
9288
if (pathCount <= 0) {
9389
return nil;
@@ -129,7 +125,7 @@ + (NSString* _Nullable) getTouchPathMessageFrom:(NSArray* _Nullable) path {
129125
[message appendString:@" > "];
130126
}
131127
}
132-
128+
133129
return message;
134130
}
135131

0 commit comments

Comments
 (0)