From 71e2dc85acc04ad3d2344f484950c7b7dc2832df Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 31 Jan 2023 11:41:40 +0100 Subject: [PATCH 1/5] setup sentry for eDrive --- .gitlab-ci.yml | 3 +++ app/build.gradle | 25 +++++++++++++------ .../foundation/e/drive/EdriveApplication.java | 2 ++ .../foundation/e/drive/utils/ReleaseTree.java | 3 +++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cdb53b00..830ab5d9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,8 @@ image: "registry.gitlab.e.foundation/e/os/docker-android-apps-cicd:latest" +variables: + SENTRY_DSN: "${SENTRY_DSN}" + stages: - test - build diff --git a/app/build.gradle b/app/build.gradle index eefe18c4..b12f98e6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,6 @@ def versionMajor = 1 def versionMinor = 3 def versionPatch = 2 - - def getTestProp(String propName) { def result = "" if (project.hasProperty(propName)) { @@ -21,6 +19,20 @@ def getTestProp(String propName) { return result } +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 @@ -32,6 +44,8 @@ android { versionName "${versionMajor}.${versionMinor}.${versionPatch}" setProperty("archivesBaseName", "eDrive-$versionName") testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + buildConfigField("String", "SENTRY_DSN", "\"${getSentryDsn()}\"") } signingConfigs { @@ -54,7 +68,6 @@ android { } } - testOptions { unitTests { returnDefaultValues = true @@ -73,10 +86,8 @@ android { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 } - } - dependencies { implementation 'com.github.nextcloud:android-library:2.13.0' implementation "commons-httpclient:commons-httpclient:3.1@jar" @@ -93,6 +104,7 @@ dependencies { implementation 'androidx.test:core:1.4.0' implementation 'com.jakewharton.timber:timber:5.0.1' implementation 'foundation.e:elib:0.0.1-alpha11' + implementation 'foundation.e.lib:telemetry:0.0.4-alpha' androidTestImplementation 'androidx.test:runner:1.4.0' androidTestImplementation 'androidx.test:rules:1.4.0' @@ -106,6 +118,5 @@ dependencies { testImplementation 'junit:junit:4.13.2' testImplementation 'org.robolectric:robolectric:4.4' testImplementation 'org.mockito:mockito-core:3.4.0' - //testImplementation 'org.mockito:mockito-inline:3.4.0' testImplementation 'androidx.work:work-testing:2.7.1' -} +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/EdriveApplication.java b/app/src/main/java/foundation/e/drive/EdriveApplication.java index 5f1ac3c3..2c5ae3bf 100644 --- a/app/src/main/java/foundation/e/drive/EdriveApplication.java +++ b/app/src/main/java/foundation/e/drive/EdriveApplication.java @@ -23,6 +23,7 @@ import foundation.e.drive.services.SynchronizationService; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; import foundation.e.drive.utils.ReleaseTree; +import foundation.e.lib.telemetry.Telemetry; import timber.log.Timber; import static timber.log.Timber.DebugTree; @@ -44,6 +45,7 @@ public class EdriveApplication extends Application { Timber.plant(new DebugTree()); } else { //Not handled yet + Telemetry.init(BuildConfig.SENTRY_DSN, this); Timber.plant(new ReleaseTree()); } Timber.tag("EdriveApplication"); diff --git a/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java b/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java index e8d64cf9..7eded70b 100644 --- a/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java +++ b/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java @@ -12,6 +12,7 @@ import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import foundation.e.lib.telemetry.Telemetry; import timber.log.Timber; /** @@ -26,6 +27,8 @@ public class ReleaseTree extends Timber.DebugTree{ @Override protected void log(int priority, @Nullable String tag, @NonNull String message, @Nullable Throwable throwable) { + Telemetry.reportMessage(tag + " " + message); + if (!debugEnable && priority < Log.INFO ) { return; } -- GitLab From 9d7ef9e3ea4d6f4e30e9dd8f8eb1e0127c29358e Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 31 Jan 2023 15:32:41 +0100 Subject: [PATCH 2/5] fix build issue --- app/src/main/java/foundation/e/drive/EdriveApplication.java | 2 +- app/src/main/java/foundation/e/drive/utils/ReleaseTree.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/EdriveApplication.java b/app/src/main/java/foundation/e/drive/EdriveApplication.java index 2c5ae3bf..76a53519 100644 --- a/app/src/main/java/foundation/e/drive/EdriveApplication.java +++ b/app/src/main/java/foundation/e/drive/EdriveApplication.java @@ -45,7 +45,7 @@ public class EdriveApplication extends Application { Timber.plant(new DebugTree()); } else { //Not handled yet - Telemetry.init(BuildConfig.SENTRY_DSN, this); + Telemetry.INSTANCE.init(BuildConfig.SENTRY_DSN, this); Timber.plant(new ReleaseTree()); } Timber.tag("EdriveApplication"); diff --git a/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java b/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java index 7eded70b..d2cfdd31 100644 --- a/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java +++ b/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java @@ -27,8 +27,7 @@ public class ReleaseTree extends Timber.DebugTree{ @Override protected void log(int priority, @Nullable String tag, @NonNull String message, @Nullable Throwable throwable) { - Telemetry.reportMessage(tag + " " + message); - + Telemetry.INSTANCE.reportMessage(tag + " " + message); if (!debugEnable && priority < Log.INFO ) { return; } -- GitLab From 51cf55afae8fab9d9ab2426fe0a58d99e12ef3fc Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 1 Feb 2023 10:03:17 +0100 Subject: [PATCH 3/5] - only add real DSN for release build - Only log warn & error to sentry - remove useless comment --- app/build.gradle | 4 ++-- app/src/main/java/foundation/e/drive/EdriveApplication.java | 1 - app/src/main/java/foundation/e/drive/utils/ReleaseTree.java | 4 +++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b12f98e6..349e0fe2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -44,8 +44,6 @@ android { versionName "${versionMajor}.${versionMinor}.${versionPatch}" setProperty("archivesBaseName", "eDrive-$versionName") testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - - buildConfigField("String", "SENTRY_DSN", "\"${getSentryDsn()}\"") } signingConfigs { @@ -61,10 +59,12 @@ android { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + buildConfigField("String", "SENTRY_DSN", "\"${getSentryDsn()}\"") } debug { signingConfig signingConfigs.debugConfig + buildConfigField("String", "SENTRY_DSN", "") } } diff --git a/app/src/main/java/foundation/e/drive/EdriveApplication.java b/app/src/main/java/foundation/e/drive/EdriveApplication.java index 76a53519..0ba43320 100644 --- a/app/src/main/java/foundation/e/drive/EdriveApplication.java +++ b/app/src/main/java/foundation/e/drive/EdriveApplication.java @@ -44,7 +44,6 @@ public class EdriveApplication extends Application { if (BuildConfig.DEBUG) { Timber.plant(new DebugTree()); } else { - //Not handled yet Telemetry.INSTANCE.init(BuildConfig.SENTRY_DSN, this); Timber.plant(new ReleaseTree()); } diff --git a/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java b/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java index d2cfdd31..ef2afe69 100644 --- a/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java +++ b/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java @@ -27,10 +27,12 @@ public class ReleaseTree extends Timber.DebugTree{ @Override protected void log(int priority, @Nullable String tag, @NonNull String message, @Nullable Throwable throwable) { - Telemetry.INSTANCE.reportMessage(tag + " " + message); if (!debugEnable && priority < Log.INFO ) { return; } + if (priority >= Log.WARN) { + Telemetry.INSTANCE.reportMessage(tag + " " + message); + } super.log(priority, tag, message, throwable); } } -- GitLab From 4f091f942bb89a4cc12aef2f0f256beebf7afd27 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Wed, 1 Feb 2023 16:00:34 +0100 Subject: [PATCH 4/5] fix pipeline error --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 349e0fe2..94555cb9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -64,7 +64,7 @@ android { debug { signingConfig signingConfigs.debugConfig - buildConfigField("String", "SENTRY_DSN", "") + buildConfigField("String", "SENTRY_DSN", "\"dummy\"") } } -- GitLab From 0a6a2d8365f67c94bac34df8e3e098775d99ce85 Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Thu, 2 Feb 2023 10:57:55 +0000 Subject: [PATCH 5/5] add empty line to let the code breathes --- app/src/main/java/foundation/e/drive/utils/ReleaseTree.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java b/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java index ef2afe69..dbc19e12 100644 --- a/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java +++ b/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java @@ -30,9 +30,11 @@ public class ReleaseTree extends Timber.DebugTree{ if (!debugEnable && priority < Log.INFO ) { return; } + if (priority >= Log.WARN) { Telemetry.INSTANCE.reportMessage(tag + " " + message); } + super.log(priority, tag, message, throwable); } } -- GitLab