From 0fad2676dd1facf5fd0c985a49f73350b0fbeeca Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Fri, 24 Feb 2023 17:06:23 +0530 Subject: [PATCH 1/3] Revert "Revert "Issue 854: Integrate sentry"" This reverts commit 3ab57cf69e7f04e472f77d73cc22521366d9f980. --- .gitlab-ci.yml | 3 +++ app/build.gradle | 18 ++++++++++++++++++ app/src/main/AndroidManifest.xml | 1 + .../foundation/e/apps/AppLoungeApplication.kt | 6 ++++++ 4 files changed, 28 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a80c072e8..1ab615176 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,8 @@ image: registry.gitlab.e.foundation/e/os/docker-android-apps-cicd:55-workshop-auto-release +variables: + SENTRY_DSN: $SENTRY_DSN + stages: - debug - release diff --git a/app/build.gradle b/app/build.gradle index b37cd54b5..369f1e3b1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,6 +26,21 @@ def getDate = { -> return new Date().format('yyyyMMddHHmmss') } +def getSentryDsn = { -> + + def sentryDsnEnv = System.getenv("SENTRY_DSN") + if (sentryDsnEnv != null) { + return sentryDsnEnv + } + + Properties properties = new Properties() + def propertiesFile = project.rootProject.file('local.properties') + if (propertiesFile.exists()) { + properties.load(propertiesFile.newDataInputStream()) + } + return properties.getProperty('SENTRY_DSN') +} + android { compileSdk 31 @@ -37,6 +52,7 @@ android { versionName "${versionMajor}.${versionMinor}.${versionPatch}" buildConfigField "String", "BUILD_ID", "\"${getGitHash() + "." + getDate()}\"" + buildConfigField("String", "SENTRY_DSN", "\"${getSentryDsn()}\"") testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -133,6 +149,8 @@ dependencies { // TODO: Add splitinstall-lib to a repo https://gitlab.e.foundation/e/os/backlog/-/issues/628 api files('libs/splitinstall-lib.jar') + implementation 'foundation.e.lib:telemetry:0.0.4-alpha' + implementation 'foundation.e:gplayapi:3.0.1' implementation 'androidx.core:core-ktx:1.7.0' implementation 'androidx.appcompat:appcompat:1.4.1' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6cf905dd2..945d35eb9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -43,6 +43,7 @@ android:supportsRtl="true" android:theme="@style/Theme.Apps" android:usesCleartextTraffic="true"> + diff --git a/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt b/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt index 6b8450742..1ed3c1025 100644 --- a/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt +++ b/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt @@ -28,6 +28,7 @@ import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.manager.workmanager.InstallWorkManager import foundation.e.apps.setup.tos.TOS_VERSION import foundation.e.apps.utils.modules.DataStoreModule +import foundation.e.lib.telemetry.Telemetry import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.MainScope import kotlinx.coroutines.launch @@ -63,14 +64,19 @@ class AppLoungeApplication : Application(), Configuration.Provider { dataStoreModule.saveTOCStatus(false, "") } } + if (BuildConfig.DEBUG) { plant(Timber.DebugTree()) } else { + // Allow enabling telemetry only for release builds. + Telemetry.init(BuildConfig.SENTRY_DSN, this) plant(object : Timber.Tree() { override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { + Telemetry.reportMessage("$tag: $message") if (priority == Log.DEBUG || priority == Log.VERBOSE) { return } + Log.println(priority, tag, message) } }) -- GitLab From 50a80f65f6d27cff1c661cb6adddf8228e3a2ac6 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Fri, 24 Feb 2023 17:20:14 +0530 Subject: [PATCH 2/3] for release builds, log only if priority is >= Log.WARN --- app/src/main/java/foundation/e/apps/AppLoungeApplication.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt b/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt index 1ed3c1025..2ec767ad2 100644 --- a/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt +++ b/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt @@ -72,11 +72,10 @@ class AppLoungeApplication : Application(), Configuration.Provider { Telemetry.init(BuildConfig.SENTRY_DSN, this) plant(object : Timber.Tree() { override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { - Telemetry.reportMessage("$tag: $message") - if (priority == Log.DEBUG || priority == Log.VERBOSE) { + if (priority < Log.WARN) { return } - + Telemetry.reportMessage("$tag: $message") Log.println(priority, tag, message) } }) -- GitLab From 7ab783c45db8437ef29b399c38e3af17d85947f2 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Mon, 27 Feb 2023 19:22:10 +0530 Subject: [PATCH 3/3] Telemetry report only for Log.ERROR --- app/src/main/java/foundation/e/apps/AppLoungeApplication.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt b/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt index 2ec767ad2..08a583145 100644 --- a/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt +++ b/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt @@ -75,7 +75,9 @@ class AppLoungeApplication : Application(), Configuration.Provider { if (priority < Log.WARN) { return } - Telemetry.reportMessage("$tag: $message") + if (priority == Log.ERROR) { + Telemetry.reportMessage("$tag: $message") + } Log.println(priority, tag, message) } }) -- GitLab