Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(replay): Add app lifecycle breadcrumbs conversion tests #3932

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
module.exports = withSentryConfig(getDefaultConfig(__dirname), { annotateReactComponents: true });
```

### Fixes

- Add `app.foreground/background` breadcrumbs to iOS Replays ([#3932](https://github.com/getsentry/sentry-react-native/pull/3932))

## 5.25.0-alpha.2

### Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.sentry.rnsentryandroidtester

import io.sentry.Breadcrumb
import io.sentry.react.RNSentryReplayBreadcrumbConverter
import io.sentry.rrweb.RRWebBreadcrumbEvent
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -10,6 +11,30 @@ import org.junit.runners.JUnit4
@RunWith(JUnit4::class)
class RNSentryReplayBreadcrumbConverterTest {

@Test
fun testConvertForegroundBreadcrumb() {
val converter = RNSentryReplayBreadcrumbConverter()
val testBreadcrumb = Breadcrumb()
testBreadcrumb.type = "navigation"
testBreadcrumb.category = "app.lifecycle"
testBreadcrumb.setData("state", "foreground");
val actual = converter.convert(testBreadcrumb) as RRWebBreadcrumbEvent

assertEquals("app.foreground", actual.category)
}

@Test
fun testConvertBackgroundBreadcrumb() {
val converter = RNSentryReplayBreadcrumbConverter()
val testBreadcrumb = Breadcrumb()
testBreadcrumb.type = "navigation"
testBreadcrumb.category = "app.lifecycle"
testBreadcrumb.setData("state", "background");
val actual = converter.convert(testBreadcrumb) as RRWebBreadcrumbEvent

assertEquals("app.background", actual.category)
}

@Test
fun doesNotConvertSentryEventBreadcrumb() {
val converter = RNSentryReplayBreadcrumbConverter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@ import XCTest

final class RNSentryReplayBreadcrumbConverterTests: XCTestCase {

func testConvertForegroundBreadcrumb() {
let converter = RNSentryReplayBreadcrumbConverter()
let testBreadcrumb = Breadcrumb()
testBreadcrumb.type = "navigation"
testBreadcrumb.category = "app.lifecycle"
testBreadcrumb.data = ["state": "foreground"]
let actual = converter.convert(from: testBreadcrumb)

XCTAssertNotNil(actual)
let data = actual!.serialize()["data"] as! [String: Any?];
let payload = data["payload"] as! [String: Any?];
XCTAssertEqual(payload["category"] as! String, "app.foreground")
}

func testConvertBackgroundBreadcrumb() {
let converter = RNSentryReplayBreadcrumbConverter()
let testBreadcrumb = Breadcrumb()
testBreadcrumb.type = "navigation"
testBreadcrumb.category = "app.lifecycle"
testBreadcrumb.data = ["state": "background"]
let actual = converter.convert(from: testBreadcrumb)

XCTAssertNotNil(actual)
let data = actual!.serialize()["data"] as! [String: Any?];
let payload = data["payload"] as! [String: Any?];
XCTAssertEqual(payload["category"] as! String, "app.background")
}

func testNotConvertSentryEventBreadcrumb() {
let converter = RNSentryReplayBreadcrumbConverter()
let testBreadcrumb = Breadcrumb()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public RNSentryReplayBreadcrumbConverter() {
breadcrumb.getCategory().equals("sentry.transaction")) {
return null;
}
if (breadcrumb.getCategory().equals("http")) {
// Drop native http breadcrumbs to avoid duplicates
return null;
}

if (breadcrumb.getCategory().equals("touch")) {
return convertTouchBreadcrumb(breadcrumb);
Expand All @@ -42,10 +46,6 @@ public RNSentryReplayBreadcrumbConverter() {
if (breadcrumb.getCategory().equals("xhr")) {
return convertNetworkBreadcrumb(breadcrumb);
}
if (breadcrumb.getCategory().equals("http")) {
// Drop native http breadcrumbs to avoid duplicates
return null;
}

RRWebEvent nativeBreadcrumb = super.convert(breadcrumb);

Expand Down
12 changes: 4 additions & 8 deletions ios/RNSentryReplayBreadcrumbConverter.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ - (instancetype _Nonnull)init {
// Do not add Sentry Event breadcrumbs to replay
return nil;
}

if ([breadcrumb.category isEqualToString:@"http"]) {
// Drop native network breadcrumbs to avoid duplicates
return nil;
}
if ([breadcrumb.type isEqualToString:@"navigation"] && ![breadcrumb.category isEqualToString:@"navigation"]) {
// Drop native navigation breadcrumbs to avoid duplicates
return nil;
}

if ([breadcrumb.category isEqualToString:@"touch"]) {
return [self convertTouch:breadcrumb];
Expand Down Expand Up @@ -71,7 +67,7 @@ - (instancetype _Nonnull)init {
if (breadcrumb.data == nil) {
return nil;
}

NSMutableArray *path = [breadcrumb.data valueForKey:@"path"];
NSString* message = [RNSentryReplayBreadcrumbConverter getTouchPathMessageFrom:path];

Expand All @@ -87,7 +83,7 @@ + (NSString* _Nullable) getTouchPathMessageFrom:(NSArray* _Nullable) path {
if (path == nil) {
return nil;
}

NSInteger pathCount = [path count];
if (pathCount <= 0) {
return nil;
Expand Down Expand Up @@ -129,7 +125,7 @@ + (NSString* _Nullable) getTouchPathMessageFrom:(NSArray* _Nullable) path {
[message appendString:@" > "];
}
}

return message;
}

Expand Down
Loading