Skip to content

Commit

Permalink
Add back Sentry for crash reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
atavism committed Oct 6, 2023
1 parent e9c3983 commit 3a1631d
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 51 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/browerstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ $(MOBILE_DEBUG_APK): $(MOBILE_SOURCES) $(GO_SOURCES)
make do-android-debug && \
cp $(MOBILE_ANDROID_DEBUG) $(MOBILE_DEBUG_APK)

$(MOBILE_RELEASE_APK): $(MOBILE_SOURCES) $(GO_SOURCES) $(MOBILE_ANDROID_LIB)
$(MOBILE_RELEASE_APK): $(MOBILE_SOURCES) $(GO_SOURCES) $(MOBILE_ANDROID_LIB) require-sentry
echo $(MOBILE_ANDROID_LIB) && \
mkdir -p ~/.gradle && \
ln -fs $(MOBILE_DIR)/gradle.properties . && \
Expand All @@ -322,11 +322,12 @@ $(MOBILE_RELEASE_APK): $(MOBILE_SOURCES) $(GO_SOURCES) $(MOBILE_ANDROID_LIB)
-PandroidArchJava="$(ANDROID_ARCH_JAVA)" -PproServerUrl=$(PRO_SERVER_URL) -PpaymentProvider=$(PAYMENT_PROVIDER) \
-Pcountry=$(COUNTRY) -PplayVersion=$(FORCE_PLAY_VERSION) -PuseStaging=$(STAGING) -PstickyConfig=$(STICKY_CONFIG) \
-PversionCode=$(VERSION_CODE) -PdevelopmentMode=$(DEVELOPMENT_MODE) -b $(MOBILE_DIR)/app/build.gradle assembleProdSideload && \
sentry-cli upload-dif --wait -o getlantern -p android build/app/intermediates/merged_native_libs/prodSideload/out/lib && \
cp $(MOBILE_ANDROID_RELEASE) $(MOBILE_RELEASE_APK) && \
cat $(MOBILE_RELEASE_APK) | bzip2 > lantern_update_android_arm.bz2


$(MOBILE_BUNDLE): $(MOBILE_SOURCES) $(GO_SOURCES) $(MOBILE_ANDROID_LIB)
$(MOBILE_BUNDLE): $(MOBILE_SOURCES) $(GO_SOURCES) $(MOBILE_ANDROID_LIB) require-sentry
@mkdir -p ~/.gradle && \
ln -fs $(MOBILE_DIR)/gradle.properties . && \
COUNTRY="$$COUNTRY" && \
Expand All @@ -336,6 +337,7 @@ $(MOBILE_BUNDLE): $(MOBILE_SOURCES) $(GO_SOURCES) $(MOBILE_ANDROID_LIB)
$(GRADLE) -PlanternVersion=$$VERSION -PlanternRevisionDate=$(REVISION_DATE) -PandroidArch=$(ANDROID_ARCH) -PandroidArchJava="$(ANDROID_ARCH_JAVA)" \
-PddClientToken=$(DD_CLIENT_TOKEN) -PddApplicationID=$(DD_APPLICATION_ID) -PproServerUrl=$(PRO_SERVER_URL) -PpaymentProvider=$(PAYMENT_PROVIDER) \
-Pcountry=$(COUNTRY) -PplayVersion=true -PuseStaging=$(STAGING) -PstickyConfig=$(STICKY_CONFIG) -b $(MOBILE_DIR)/app/build.gradle bundlePlay && \
sentry-cli upload-dif --wait -o getlantern -p android build/app/intermediates/merged_native_libs/prodPlay/out/lib && \
cp $(MOBILE_ANDROID_BUNDLE) $(MOBILE_BUNDLE)

android-debug: $(MOBILE_DEBUG_APK)
Expand Down
33 changes: 30 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
id 'kotlin-parcelize'
id 'kotlin-kapt'
id 'com.google.protobuf'
id("com.datadoghq.dd-sdk-android-gradle-plugin") version "1.10.0"
id "io.sentry.android.gradle" version "3.13.0"
}

def localProperties = new Properties()
Expand Down Expand Up @@ -180,8 +180,6 @@ android {
buildConfigField "boolean", "STICKY_CONFIG", getBoolean("stickyConfig")
buildConfigField "boolean", "STAGING", getBoolean("useStaging")
buildConfigField "boolean", "PLAY_VERSION", getBoolean("playVersion")
buildConfigField "String", "DD_CLIENT_TOKEN", ddClientToken()
buildConfigField "String", "DD_APPLICATION_ID", ddApplicationID()
buildConfigField "String", "COUNTRY", userCountry()
buildConfigField "String", "PAYMENT_PROVIDER", paymentProvider()
buildConfigField "String", "PRO_SERVER_URL", proServerUrl()
Expand Down Expand Up @@ -473,3 +471,32 @@ dependencies {
}

apply plugin: 'com.google.gms.google-services'

sentry {

// Disables or enables the handling of Proguard mapping for Sentry.
// If enabled the plugin will generate a UUID and will take care of
// uploading the mapping to Sentry. If disabled, all the logic
// related to proguard mapping will be excluded.
// Default is enabled.
includeProguardMapping = true


// Whether the plugin should attempt to auto-upload the mapping file to Sentry or not.
// If disabled the plugin will run a dry-run and just generate a UUID.
// The mapping file has to be uploaded manually via sentry-cli in this case.
// Default is enabled.
autoUploadProguardMapping = true

// Disables or enables the automatic configuration of Native Symbols
// for Sentry. This executes sentry-cli automatically so
// you don't need to do it manually.
// Default is disabled.
uploadNativeSymbols = true

// Does or doesn't include the source code of native code for Sentry.
// This executes sentry-cli with the --include-sources param. automatically so
// you don't need to do it manually.
// Default is disabled.
includeNativeSources = false
}
4 changes: 2 additions & 2 deletions android/app/libs/liblantern-all.aar
Git LFS file not shown
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package org.getlantern.lantern
import android.app.Application
import android.content.Context
import android.os.StrictMode
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import androidx.multidex.MultiDex
import org.getlantern.lantern.model.InAppBilling
import org.getlantern.lantern.model.LanternHttpClient
import org.getlantern.lantern.model.LanternSessionManager
import org.getlantern.lantern.util.debugOnly
import org.getlantern.lantern.util.LanternProxySelector
import org.getlantern.mobilesdk.Logger
import org.getlantern.lantern.util.SentryUtil
import org.getlantern.mobilesdk.util.HttpClient

open class LanternApp : Application() {
Expand Down Expand Up @@ -40,13 +39,14 @@ open class LanternApp : Application() {

override fun onCreate() {
super.onCreate()
SentryUtil.enableGoPanicEnrichment(this)

// Necessary to locate a back arrow resource we use from the
// support library. See http://stackoverflow.com/questions/37615470/support-library-vectordrawable-resourcesnotfoundexception
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
appContext = applicationContext
session = LanternSessionManager(this)

LanternProxySelector(session)

if (session.isPlayVersion) inAppBilling = InAppBilling(this)
Expand Down
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
}
}
}
}
10 changes: 5 additions & 5 deletions lib/catcher_setup.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:catcher/catcher.dart';
import 'package:catcher_2/catcher_2.dart';
import 'package:flutter/material.dart';
import 'package:sentry/sentry.dart';

final debugOption = CatcherOptions(
final debugOption = Catcher2Options(
SilentReportMode(),
[
ConsoleHandler(
Expand All @@ -14,7 +14,7 @@ final debugOption = CatcherOptions(
],
);

final releaseOption = CatcherOptions(
final releaseOption = Catcher2Options(
SilentReportMode(),
[
ConsoleHandler(
Expand All @@ -35,8 +35,8 @@ final releaseOption = CatcherOptions(
],
);

Catcher setupCatcherAndRun(StatelessWidget root) {
return Catcher(
Catcher2 setupCatcherAndRun(StatelessWidget root) {
return Catcher2(
rootWidget: root,
debugConfig: debugOption,
releaseConfig: releaseOption,
Expand Down
Loading

0 comments on commit 3a1631d

Please sign in to comment.