-
-
Notifications
You must be signed in to change notification settings - Fork 354
feat(replay): Add breadcrumbs mapping from RN to RRWeb format #3846
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
66b14d8
touch events on android
vaind a9139c6
fix touchevent tests
vaind fb1bb90
Update android/src/main/java/io/sentry/react/RNSentryReplayBreadcrumb…
vaind e725aa9
ios breadcrumb converter
vaind d5c8e67
delegate to default breadcrumb converter
vaind 3d76fae
fix: module access
vaind 9092169
Merge branch 'feat/replay' into feat/replay-breadcrumbs
vaind b4a1d8f
move replay stuff to RNSentrySessionReplay
vaind 2ebf638
move setBreadcrumbConverter to init
vaind 0f17b72
try to fix CI
vaind ae558fe
navigation breadcrumbs
vaind 04c5c9d
try to fix CI
vaind 6211bbf
pin xcode to 15.4 for e2e and sample app builds
krystofwoldrich 96c7aab
chore: update cocoa breadcrumb converter to match latest changes in t…
vaind 1a13827
more updates based on upstream changes
vaind 5564c88
Revert "pin xcode to 15.4 for e2e and sample app builds"
krystofwoldrich 8d4f937
review changes
vaind 272b4bb
fix changelog
vaind 0a95f72
Merge branch 'feat/replay' into feat/replay-breadcrumbs
vaind 30ed290
cleanup TODOs
vaind f71fb66
touch event path for replay breadcrumbs
vaind 2f2ff79
remove native navigation breadcrumbs on iOS
vaind dcc9753
renames
vaind a138db1
ignore native navigation breadcrumbs on android
vaind e3aaee8
fix android
vaind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
android/src/main/java/io/sentry/react/RNSentryReplayBreadcrumbConverter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package io.sentry.react; | ||
|
|
||
| import io.sentry.Breadcrumb; | ||
| import io.sentry.android.replay.DefaultReplayBreadcrumbConverter; | ||
| import io.sentry.rrweb.RRWebEvent; | ||
| import io.sentry.rrweb.RRWebBreadcrumbEvent; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| public final class RNSentryReplayBreadcrumbConverter extends DefaultReplayBreadcrumbConverter { | ||
| public RNSentryReplayBreadcrumbConverter() { | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable RRWebEvent convert(final @NotNull Breadcrumb breadcrumb) { | ||
| RRWebBreadcrumbEvent rrwebBreadcrumb = new RRWebBreadcrumbEvent(); | ||
| assert rrwebBreadcrumb.getCategory() == null; | ||
|
|
||
| if (breadcrumb.getCategory().equals("touch")) { | ||
| rrwebBreadcrumb.setCategory("ui.tap"); | ||
| ArrayList path = (ArrayList) breadcrumb.getData("path"); | ||
| if (path != null) { | ||
| StringBuilder message = new StringBuilder(); | ||
| for (int i = Math.min(3, path.size()); i >= 0; i--) { | ||
| HashMap item = (HashMap) path.get(i); | ||
| message.append(item.get("name")); | ||
| if (item.containsKey("element") || item.containsKey("file")) { | ||
| message.append('('); | ||
| if (item.containsKey("element")) { | ||
| message.append(item.get("element")); | ||
| if (item.containsKey("file")) { | ||
| message.append(", "); | ||
| message.append(item.get("file")); | ||
| } | ||
| } else if (item.containsKey("file")) { | ||
| message.append(item.get("file")); | ||
| } | ||
| message.append(')'); | ||
| } | ||
| if (i > 0) { | ||
| message.append(" > "); | ||
| } | ||
| } | ||
|
Comment on lines
+23
to
+45
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks good in the UI, let's leave it like this for now, in the Replay alpha branch. We should discuss this with the front end as they can assemble the string from the structured data. |
||
| rrwebBreadcrumb.setMessage(message.toString()); | ||
| } | ||
| rrwebBreadcrumb.setData(breadcrumb.getData()); | ||
| } else if (breadcrumb.getCategory().equals("navigation")) { | ||
| rrwebBreadcrumb.setCategory(breadcrumb.getCategory()); | ||
| rrwebBreadcrumb.setData(breadcrumb.getData()); | ||
| } | ||
|
|
||
| if (rrwebBreadcrumb.getCategory() != null && !rrwebBreadcrumb.getCategory().isEmpty()) { | ||
| rrwebBreadcrumb.setLevel(breadcrumb.getLevel()); | ||
| rrwebBreadcrumb.setTimestamp(breadcrumb.getTimestamp().getTime()); | ||
| rrwebBreadcrumb.setBreadcrumbTimestamp(breadcrumb.getTimestamp().getTime() / 1000.0); | ||
| rrwebBreadcrumb.setBreadcrumbType("default"); | ||
| return rrwebBreadcrumb; | ||
| } | ||
|
|
||
| RRWebEvent nativeBreadcrumb = super.convert(breadcrumb); | ||
|
|
||
| // ignore native navigation breadcrumbs | ||
| if (nativeBreadcrumb instanceof RRWebBreadcrumbEvent) { | ||
| rrwebBreadcrumb = (RRWebBreadcrumbEvent) nativeBreadcrumb; | ||
| if (rrwebBreadcrumb.getCategory() != null && rrwebBreadcrumb.getCategory().equals("navigation")) { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| return nativeBreadcrumb; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
|
|
||
| @interface RNSentryReplay : NSObject | ||
|
|
||
| + (void)updateOptions:(NSMutableDictionary *)options; | ||
|
|
||
| + (void)postInit; | ||
|
|
||
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #import "RNSentryReplay.h" | ||
| #import "RNSentryReplayBreadcrumbConverter.h" | ||
|
|
||
| #if SENTRY_TARGET_REPLAY_SUPPORTED | ||
|
|
||
| @implementation RNSentryReplay { | ||
| } | ||
|
|
||
| + (void)updateOptions:(NSMutableDictionary *)options { | ||
| NSDictionary *experiments = options[@"_experiments"]; | ||
| [options removeObjectForKey:@"_experiments"]; | ||
| if (experiments == nil) { | ||
| NSLog(@"Session replay disabled via configuration"); | ||
| return; | ||
| } | ||
|
|
||
| if (experiments[@"replaysSessionSampleRate"] == nil && | ||
| experiments[@"replaysOnErrorSampleRate"] == nil) { | ||
| NSLog(@"Session replay disabled via configuration"); | ||
| return; | ||
| } | ||
|
|
||
| NSLog(@"Setting up session replay"); | ||
| NSDictionary *replayOptions = options[@"mobileReplayOptions"] ?: @{}; | ||
|
|
||
| [options setValue:@{ | ||
| @"sessionReplay" : @{ | ||
| @"sessionSampleRate" : experiments[@"replaysSessionSampleRate"] | ||
| ?: [NSNull null], | ||
| @"errorSampleRate" : experiments[@"replaysOnErrorSampleRate"] | ||
| ?: [NSNull null], | ||
| @"redactAllImages" : replayOptions[@"maskAllImages"] ?: [NSNull null], | ||
| @"redactAllText" : replayOptions[@"maskAllText"] ?: [NSNull null], | ||
| } | ||
| } | ||
| forKey:@"experimental"]; | ||
|
|
||
| [RNSentryReplay addReplayRNRedactClasses:replayOptions]; | ||
| } | ||
|
|
||
| + (void)addReplayRNRedactClasses:(NSDictionary *_Nullable)replayOptions { | ||
| NSMutableArray *_Nonnull classesToRedact = [[NSMutableArray alloc] init]; | ||
| if ([replayOptions[@"maskAllImages"] boolValue] == YES) { | ||
| [classesToRedact addObject:NSClassFromString(@"RCTImageView")]; | ||
| } | ||
| if ([replayOptions[@"maskAllText"] boolValue] == YES) { | ||
| [classesToRedact addObject:NSClassFromString(@"RCTTextView")]; | ||
| } | ||
| [PrivateSentrySDKOnly addReplayRedactClasses:classesToRedact]; | ||
| } | ||
|
|
||
| + (void)postInit { | ||
| RNSentryReplayBreadcrumbConverter *breadcrumbConverter = | ||
| [[RNSentryReplayBreadcrumbConverter alloc] init]; | ||
| [PrivateSentrySDKOnly configureSessionReplayWith:breadcrumbConverter | ||
| screenshotProvider:nil]; | ||
| } | ||
|
|
||
| @end | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| @import Sentry; | ||
|
|
||
| #if SENTRY_TARGET_REPLAY_SUPPORTED | ||
| @class SentryRRWebEvent; | ||
|
|
||
| @interface RNSentryReplayBreadcrumbConverter | ||
| : NSObject <SentryReplayBreadcrumbConverter> | ||
|
|
||
| - (instancetype _Nonnull)init; | ||
|
|
||
| @end | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| #import "RNSentryReplayBreadcrumbConverter.h" | ||
|
|
||
| @import Sentry; | ||
|
|
||
| #if SENTRY_TARGET_REPLAY_SUPPORTED | ||
|
|
||
| @implementation RNSentryReplayBreadcrumbConverter { | ||
| SentrySRDefaultBreadcrumbConverter *defaultConverter; | ||
| } | ||
|
|
||
| - (instancetype _Nonnull)init { | ||
| if (self = [super init]) { | ||
| self->defaultConverter = | ||
| [SentrySessionReplayIntegration createDefaultBreadcrumbConverter]; | ||
| } | ||
| return self; | ||
| } | ||
|
|
||
| - (id<SentryRRWebEvent> _Nullable)convertFrom: | ||
| (SentryBreadcrumb *_Nonnull)breadcrumb { | ||
| assert(breadcrumb.timestamp != nil); | ||
|
|
||
| if ([breadcrumb.category isEqualToString:@"touch"]) { | ||
| NSMutableString *message; | ||
| if (breadcrumb.data) { | ||
| NSMutableArray *path = [breadcrumb.data valueForKey:@"path"]; | ||
| if (path != nil) { | ||
| message = [[NSMutableString alloc] init]; | ||
| for (NSInteger i = MIN(3, [path count] - 1); i >= 0; i--) { | ||
| NSDictionary *item = [path objectAtIndex:i]; | ||
| [message appendString:[item objectForKey:@"name"]]; | ||
| if ([item objectForKey:@"element"] || [item objectForKey:@"file"]) { | ||
| [message appendString:@"("]; | ||
| if ([item objectForKey:@"element"]) { | ||
| [message appendString:[item objectForKey:@"element"]]; | ||
| if ([item objectForKey:@"file"]) { | ||
| [message appendString:@", "]; | ||
| [message appendString:[item objectForKey:@"file"]]; | ||
| } | ||
| } else if ([item objectForKey:@"file"]) { | ||
| [message appendString:[item objectForKey:@"file"]]; | ||
| } | ||
| [message appendString:@")"]; | ||
| } | ||
| if (i > 0) { | ||
| [message appendString:@" > "]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return [SentrySessionReplayIntegration | ||
| createBreadcrumbwithTimestamp:breadcrumb.timestamp | ||
| category:@"ui.tap" | ||
| message:message | ||
| level:breadcrumb.level | ||
| data:breadcrumb.data]; | ||
| } else if ([breadcrumb.category isEqualToString:@"navigation"]) { | ||
| return [SentrySessionReplayIntegration | ||
| createBreadcrumbwithTimestamp:breadcrumb.timestamp | ||
| category:breadcrumb.category | ||
| message:nil | ||
| level:breadcrumb.level | ||
| data:breadcrumb.data]; | ||
| } else { | ||
| SentryRRWebEvent *nativeBreadcrumb = | ||
| [self->defaultConverter convertFrom:breadcrumb]; | ||
|
|
||
| // ignore native navigation breadcrumbs | ||
| if (nativeBreadcrumb && nativeBreadcrumb.data && | ||
| nativeBreadcrumb.data[@"payload"] && | ||
| nativeBreadcrumb.data[@"payload"][@"category"] && | ||
| [nativeBreadcrumb.data[@"payload"][@"category"] | ||
| isEqualToString:@"navigation"]) { | ||
| return nil; | ||
| } | ||
| return nativeBreadcrumb; | ||
| } | ||
| } | ||
|
|
||
| @end | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.