-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
177 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,14 @@ jobs: | |
run: | | ||
git config --global url."https://${{ secrets.GH_TOKEN }}:[email protected]/".insteadOf "https://github.com/" | ||
- name: Setup Sentry CLI | ||
uses: mathieu-bour/setup-sentry-cli@v1 | ||
with: | ||
version: latest | ||
token: ${{ SECRETS.SENTRY_TOKEN }} # from GitHub secrets | ||
organization: getlantern | ||
project: android | ||
|
||
- name: Setup JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
|
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 |
---|---|---|
|
@@ -82,6 +82,14 @@ jobs: | |
run: | | ||
git config --global url."https://${{ secrets.GH_TOKEN }}:[email protected]/".insteadOf "https://github.com/" | ||
- name: Setup Sentry CLI | ||
uses: mathieu-bour/setup-sentry-cli@v1 | ||
with: | ||
version: latest | ||
token: ${{ SECRETS.SENTRY_TOKEN }} # from GitHub secrets | ||
organization: getlantern | ||
project: android | ||
|
||
- name: Setup JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
|
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
Git LFS file not shown
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
56 changes: 56 additions & 0 deletions
56
android/app/src/main/kotlin/org/getlantern/lantern/util/SentryUtil.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,56 @@ | ||
package org.getlantern.lantern.util | ||
|
||
import android.content.Context | ||
import android.os.Process | ||
import io.sentry.SentryOptions | ||
import io.sentry.android.core.SentryAndroid | ||
import org.getlantern.mobilesdk.Logger | ||
import java.io.BufferedReader | ||
import java.io.InputStreamReader | ||
|
||
object SentryUtil { | ||
private val TAG = SentryUtil::class.java.name | ||
|
||
/** | ||
* Enables enrichment of sentry crash reports with the most recent Go panic from logcat. | ||
* Keep in mind that Sentry only finds panics the next time that it runs after the process | ||
* actually panicked. So, we can safely exclude logs from our current run. | ||
* | ||
* Keep in mind also that there's no guarantee that the panic log in question belongs to our | ||
* specific panic, we're just picking up the most recent panic log information. | ||
*/ | ||
@JvmStatic | ||
fun enableGoPanicEnrichment(ctx: Context) { | ||
SentryAndroid.init(ctx) { options -> | ||
options.beforeSend = SentryOptions.BeforeSendCallback { event, _ -> | ||
// enable enrichment only for exceptions related to OS signals like SIGABRT | ||
if (event.exceptions?.firstOrNull()?.type?.startsWith("SIG") == true) { | ||
val myPid = Process.myPid().toString() | ||
val goErrorLog = StringBuilder() | ||
val process = Runtime.getRuntime().exec( | ||
"logcat -d -v brief" | ||
) | ||
BufferedReader(InputStreamReader(process.inputStream)).use { reader -> | ||
reader.forEachLine { line -> | ||
if (!line.contains(myPid) && line.startsWith("E/Go ")) { | ||
if (line.contains("panic: ")) { | ||
// this is the first line of the most recent panic, remove old rows | ||
// from what must be prior panics | ||
goErrorLog.clear() | ||
} | ||
goErrorLog.appendLine(line) | ||
} | ||
} | ||
} | ||
|
||
if (goErrorLog.isNotEmpty()) { | ||
Logger.debug(TAG, "Attaching latestgopanic to event") | ||
event.setExtra("latestgopanic", goErrorLog.toString()) | ||
} | ||
} | ||
|
||
event | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.