@@ -5,15 +5,22 @@ import com.automattic.android.tracks.crashlogging.CrashLogging
55import com.automattic.android.tracks.crashlogging.CrashLoggingDataProvider
66import com.automattic.android.tracks.crashlogging.CrashLoggingUser
77import com.automattic.android.tracks.crashlogging.ExtraKnownKey
8+ import com.automattic.android.tracks.crashlogging.JsException
9+ import com.automattic.android.tracks.crashlogging.JsExceptionCallback
810import com.automattic.android.tracks.crashlogging.PerformanceMonitoringConfig.Disabled
911import com.automattic.android.tracks.crashlogging.PerformanceMonitoringConfig.Enabled
1012import com.automattic.android.tracks.crashlogging.eventLevel
1113import io.sentry.Breadcrumb
14+ import io.sentry.Sentry
1215import io.sentry.SentryEvent
1316import io.sentry.SentryLevel
1417import io.sentry.SentryOptions
1518import io.sentry.android.fragment.FragmentLifecycleIntegration
19+ import io.sentry.protocol.Mechanism
1620import io.sentry.protocol.Message
21+ import io.sentry.protocol.SentryException
22+ import io.sentry.protocol.SentryStackFrame
23+ import io.sentry.protocol.SentryStackTrace
1724import io.sentry.protocol.User
1825import kotlinx.coroutines.CoroutineScope
1926import kotlinx.coroutines.launch
@@ -24,7 +31,6 @@ internal class SentryCrashLogging constructor(
2431 private val sentryWrapper : SentryErrorTrackerWrapper ,
2532 applicationScope : CoroutineScope
2633) : CrashLogging {
27-
2834 init {
2935 sentryWrapper.initialize(application) { options ->
3036
@@ -134,6 +140,46 @@ internal class SentryCrashLogging constructor(
134140 sentryWrapper.captureEvent(event)
135141 }
136142
143+ override fun sendJavaScriptReport (
144+ jsException : JsException ,
145+ callback : JsExceptionCallback
146+ ) {
147+ val frames = jsException.stackTrace.map {
148+ SentryStackFrame ().apply {
149+ this .filename = it.fileName
150+ this .function = it.function
151+ this .lineno = it.lineNumber
152+ this .colno = it.colNumber
153+ this .isInApp = true
154+ }
155+ }.toMutableList()
156+
157+ val sentryException = SentryException ().apply {
158+ this .type = jsException.type
159+ this .value = jsException.message
160+ this .module = " javascript"
161+ this .stacktrace = SentryStackTrace ().apply { this .frames = frames }
162+ this .mechanism = Mechanism ().apply {
163+ this .isHandled = jsException.isHandled
164+ this .type = jsException.handledBy
165+ }
166+ }
167+
168+ val event = SentryEvent ().apply {
169+ this .message = Message ().apply { this .message = message }
170+ this .level = SentryLevel .FATAL
171+ this .platform = " javascript"
172+ this .appendTags(jsException.tags)
173+ this .exceptions = mutableListOf (sentryException)
174+ }
175+
176+ Sentry .configureScope { scope ->
177+ scope.setContexts(" react_native_context" , jsException.context)
178+ }
179+ sentryWrapper.captureEvent(event)
180+ callback.onReportSent(true )
181+ }
182+
137183 private fun SentryEvent.appendTags (tags : Map <String , String >) {
138184 for ((key, value) in tags) {
139185 this .setTag(key, value)
0 commit comments