Skip to content

Commit

Permalink
update native replay integration with touch breadcrumb path
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Sep 2, 2024
1 parent d9abf70 commit 30cc34b
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SentryFlutterReplayBreadcrumbConverter : DefaultReplayBreadcrumbConverter(
"ui.click" ->
newRRWebBreadcrumb(breadcrumb).apply {
category = "ui.tap"
message = breadcrumb.data["path"] as String?
message = getTouchPathMessage(breadcrumb.data["path"])
}

else -> {
Expand Down Expand Up @@ -83,4 +83,38 @@ class SentryFlutterReplayBreadcrumbConverter : DefaultReplayBreadcrumbConverter(
}
return rrWebEvent
}

private fun getTouchPathMessage(maybePath: Any?): String? {
if (maybePath !is List<*>) {
return null
}

if (maybePath.isEmpty()) {
return null
}

val message = StringBuilder()
for (i in Math.min(3, maybePath.size - 1) downTo 0) {
val item = maybePath[i]
if (item !is Map<*, *>) {
continue
}

message.append(item["element"] ?: "?")

var identifier = item["label"] ?: item["name"]
if (identifier is String && identifier.isNotEmpty()) {
if (identifier.length > 20) {
identifier = identifier.substring(0, 17) + "..."
}
message.append("(").append(identifier).append(")")
}

if (i > 0) {
message.append(" > ")
}
}

return message.toString()
}
}
38 changes: 37 additions & 1 deletion flutter/ios/Classes/SentryFlutterReplayBreadcrumbConverter.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ - (instancetype _Nonnull)init {
if ([breadcrumb.category isEqualToString:@"ui.click"]) {
return [self convertFrom:breadcrumb
withCategory:@"ui.tap"
andMessage:breadcrumb.data[@"path"]];
andMessage:[self getTouchPathMessage:breadcrumb.data[@"path"]]];
}

SentryRRWebEvent *nativeBreadcrumb =
Expand Down Expand Up @@ -112,6 +112,42 @@ - (NSDate *_Nonnull)dateFrom:(NSNumber *_Nonnull)timestamp {
return [NSDate dateWithTimeIntervalSince1970:(timestamp.doubleValue / 1000)];
}

- (NSString * _Nullable)getTouchPathMessage:(id _Nullable)maybePath {
if (![maybePath isKindOfClass:[NSArray class]]) {
return nil;
}

NSArray *path = (NSArray *)maybePath;
if (path.count == 0) {
return nil;
}

NSMutableString *message = [NSMutableString string];
for (NSInteger i = MIN(3, path.count - 1); i >= 0; i--) {
id item = path[i];
if (![item isKindOfClass:[NSDictionary class]]) {
continue;
}

NSDictionary *itemDict = (NSDictionary *)item;
[message appendString:itemDict[@"element"] ?: @"?"];

id identifier = itemDict[@"label"] ?: itemDict[@"name"];
if ([identifier isKindOfClass:[NSString class]] && [(NSString *)identifier length] > 0) {
NSString *identifierStr = (NSString *)identifier;
if (identifierStr.length > 20) {
identifierStr = [[identifierStr substringToIndex:17] stringByAppendingString:@"..."];
}
[message appendFormat:@"(%@)", identifierStr];
}

if (i > 0) {
[message appendString:@" > "];
}
}

return message.length > 0 ? message : nil;
}
@end

#endif

0 comments on commit 30cc34b

Please sign in to comment.