-
-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replay breadcrumbs (android) (#2163)
* feat: replay breadcrumbs * ktlint format * fixup tests * cleanup * linter issues * detekt linter issue * move touch path build to dart to deduplicate * fix metrics app compilation * linter issue
- Loading branch information
Showing
4 changed files
with
148 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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
86 changes: 86 additions & 0 deletions
86
flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutterReplayBreadcrumbConverter.kt
This file contains 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,86 @@ | ||
package io.sentry.flutter | ||
|
||
import io.sentry.Breadcrumb | ||
import io.sentry.android.replay.DefaultReplayBreadcrumbConverter | ||
import io.sentry.rrweb.RRWebBreadcrumbEvent | ||
import io.sentry.rrweb.RRWebEvent | ||
import io.sentry.rrweb.RRWebSpanEvent | ||
import java.util.Date | ||
|
||
private const val MILLIS_PER_SECOND = 1000.0 | ||
|
||
class SentryFlutterReplayBreadcrumbConverter : DefaultReplayBreadcrumbConverter() { | ||
internal companion object { | ||
private val supportedNetworkData = | ||
mapOf( | ||
"status_code" to "statusCode", | ||
"method" to "method", | ||
"response_body_size" to "responseBodySize", | ||
"request_body_size" to "requestBodySize", | ||
) | ||
} | ||
|
||
override fun convert(breadcrumb: Breadcrumb): RRWebEvent? { | ||
return when (breadcrumb.category) { | ||
null -> null | ||
"sentry.event" -> null | ||
"sentry.transaction" -> null | ||
"http" -> convertNetworkBreadcrumb(breadcrumb) | ||
"navigation" -> newRRWebBreadcrumb(breadcrumb) | ||
"ui.click" -> | ||
newRRWebBreadcrumb(breadcrumb).apply { | ||
category = "ui.tap" | ||
message = breadcrumb.data["path"] as String? | ||
} | ||
|
||
else -> { | ||
val nativeBreadcrumb = super.convert(breadcrumb) | ||
|
||
// ignore native navigation breadcrumbs | ||
if (nativeBreadcrumb is RRWebBreadcrumbEvent) { | ||
if (nativeBreadcrumb.category == "navigation") { | ||
return null | ||
} | ||
} | ||
|
||
nativeBreadcrumb | ||
} | ||
} | ||
} | ||
|
||
private fun newRRWebBreadcrumb(breadcrumb: Breadcrumb): RRWebBreadcrumbEvent = | ||
RRWebBreadcrumbEvent().apply { | ||
category = breadcrumb.category | ||
level = breadcrumb.level | ||
data = breadcrumb.data | ||
timestamp = breadcrumb.timestamp.time | ||
breadcrumbTimestamp = doubleTimestamp(breadcrumb.timestamp) | ||
breadcrumbType = "default" | ||
} | ||
|
||
private fun doubleTimestamp(date: Date) = doubleTimestamp(date.time) | ||
|
||
private fun doubleTimestamp(timestamp: Long) = timestamp / MILLIS_PER_SECOND | ||
|
||
private fun convertNetworkBreadcrumb(breadcrumb: Breadcrumb): RRWebEvent? { | ||
var rrWebEvent = super.convert(breadcrumb) | ||
if (rrWebEvent == null && | ||
breadcrumb.data.containsKey("start_timestamp") && | ||
breadcrumb.data.containsKey("end_timestamp") | ||
) { | ||
rrWebEvent = | ||
RRWebSpanEvent().apply { | ||
op = "resource.http" | ||
timestamp = breadcrumb.timestamp.time | ||
description = breadcrumb.data["url"] as String | ||
startTimestamp = doubleTimestamp(breadcrumb.data["start_timestamp"] as Long) | ||
endTimestamp = doubleTimestamp(breadcrumb.data["end_timestamp"] as Long) | ||
data = | ||
breadcrumb.data | ||
.filterKeys { key -> supportedNetworkData.containsKey(key) } | ||
.mapKeys { (key, _) -> supportedNetworkData[key] } | ||
} | ||
} | ||
return rrWebEvent | ||
} | ||
} |