Skip to content

Commit b755cfd

Browse files
authored
ADFA-4397: Migrate crash and log reporting from Sentry to GlitchTip (#1490)
1 parent 232cec2 commit b755cfd

7 files changed

Lines changed: 46 additions & 41 deletions

File tree

‎.github/workflows/analyze.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
# Firebase config). Scoped to this step so SonarCloud and other
8080
# third-party actions never see them.
8181
FIREBASE_CONSOLE_URL: ${{ secrets.FIREBASE_CONSOLE_URL }}
82-
SENTRY_DSN_DEBUG: ${{ secrets.SENTRY_DSN_DEBUG }}
82+
GLITCHTIP_DSN: ${{ secrets.GLITCHTIP_DSN }}
8383
run: |
8484
echo "gradle_time_start=$(date +%s)" >> $GITHUB_ENV
8585
flox activate -d flox/base -- ./gradlew :app:assembleV8Debug --no-daemon
@@ -104,7 +104,7 @@ jobs:
104104
# The Gradle build also drives Sentry/Firebase configuration during
105105
# the unit-test compile path.
106106
FIREBASE_CONSOLE_URL: ${{ secrets.FIREBASE_CONSOLE_URL }}
107-
SENTRY_DSN_DEBUG: ${{ secrets.SENTRY_DSN_DEBUG }}
107+
GLITCHTIP_DSN: ${{ secrets.GLITCHTIP_DSN }}
108108
run: flox activate -d flox/base -- ./gradlew :testing:tooling:assemble :testing:common:assemble sonarqube --info --no-build-cache -x lint --continue
109109

110110
- name: Upload JaCoCo report

‎.github/workflows/debug.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ env:
2828
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.MVN_SIGNING_KEY_ID }}
2929
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.MVN_SIGNING_KEY_PASSWORD }}
3030
FIREBASE_CONSOLE_URL: ${{ secrets.FIREBASE_CONSOLE_URL }}
31-
SENTRY_DSN_DEBUG: ${{ secrets.SENTRY_DSN_DEBUG }}
31+
GLITCHTIP_DSN: ${{ secrets.GLITCHTIP_DSN }}
3232

3333
jobs:
3434
check_changes:

‎.github/workflows/release.yml‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ env:
2525
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.MVN_SIGNING_KEY_ID }}
2626
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.MVN_SIGNING_KEY_PASSWORD }}
2727
FIREBASE_CONSOLE_URL: ${{ secrets.FIREBASE_CONSOLE_URL }}
28-
SENTRY_DSN_RELEASE: ${{ secrets.SENTRY_DSN_RELEASE }}
29-
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
30-
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
31-
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
28+
GLITCHTIP_DSN: ${{ secrets.GLITCHTIP_DSN }}
3229

3330
jobs:
3431
merge_stage_to_main:

‎app/build.gradle.kts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ val props =
4848
if (file.exists()) load(file.inputStream())
4949
}
5050

51+
val glitchtipDsn = props.getProperty("glitchtipDsn") ?: propOrEnv("GLITCHTIP_DSN")
52+
5153
apply {
5254
plugin(AndroidIDEAssetsPlugin::class.java)
5355
}
@@ -79,12 +81,10 @@ android {
7981
buildTypes {
8082
debug {
8183
signingConfig = signingConfigs.getByName("debug")
82-
manifestPlaceholders["sentryDsn"] =
83-
props.getProperty("sentryDsnDebug") ?: propOrEnv("SENTRY_DSN_DEBUG")
84+
manifestPlaceholders["sentryDsn"] = glitchtipDsn
8485
}
8586
release {
86-
manifestPlaceholders["sentryDsn"] =
87-
props.getProperty("sentryDsnRelease") ?: propOrEnv("SENTRY_DSN_RELEASE")
87+
manifestPlaceholders["sentryDsn"] = glitchtipDsn
8888
}
8989
}
9090

@@ -324,7 +324,7 @@ dependencies {
324324
// Sentry Android SDK (core + replay for quality configuration)
325325
implementation(libs.sentry.core)
326326
implementation(libs.sentry.android.core)
327-
implementation(libs.sentry.android.replay)
327+
implementation(libs.sentry.logback)
328328

329329
// Firebase Analytics
330330
implementation(platform(libs.firebase.bom))

‎app/src/main/AndroidManifest.xml‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,30 +143,14 @@
143143
<!-- enable the performance API by setting a sample-rate, adjust in production env -->
144144
<meta-data
145145
android:name="io.sentry.traces.sample-rate"
146-
android:value="1.0" />
147-
<!-- enable profiling when starting transactions, adjust in production env -->
148-
<meta-data
149-
android:name="io.sentry.traces.profiling.sample-rate"
150-
android:value="1.0" />
146+
android:value="0.0" />
151147
<meta-data
152148
android:name="io.sentry.send-default-pii"
153149
android:value="true" />
154-
<!-- Enable profiling on app start -->
155-
<meta-data
156-
android:name="io.sentry.traces.profiling.start-on-app-start"
157-
android:value="true" />
158150
<!-- Enable logs to be sent to Sentry -->
159151
<meta-data
160152
android:name="io.sentry.logs.enabled"
161153
android:value="true" />
162-
<!-- Record session replays for 100% of errors and 10% of sessions -->
163-
<meta-data
164-
android:name="io.sentry.session-replay.on-error-sample-rate"
165-
android:value="1.0" />
166-
<meta-data
167-
android:name="io.sentry.session-replay.session-sample-rate"
168-
android:value="0.1" />
169-
170154
<provider
171155
android:name=".provider.IDEDocumentsProvider"
172156
android:authorities="com.itsaky.androidide.documents"

‎app/src/main/java/com/itsaky/androidide/app/DeviceProtectedApplicationLoader.kt‎

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import com.itsaky.androidide.utils.FeatureFlags
2121
import com.termux.shared.reflection.ReflectionUtils
2222
import io.github.rosemoe.sora.widget.schemes.EditorColorScheme
2323
import io.sentry.Sentry
24-
import io.sentry.SentryReplayOptions.SentryReplayQuality
2524
import io.sentry.android.core.SentryAndroid
2625
import kotlinx.coroutines.Dispatchers
2726
import kotlinx.coroutines.launch
@@ -32,6 +31,13 @@ import org.koin.core.component.KoinComponent
3231
import org.koin.core.component.inject
3332
import org.slf4j.LoggerFactory
3433
import kotlin.system.exitProcess
34+
import ch.qos.logback.classic.Level
35+
import ch.qos.logback.classic.Logger
36+
import ch.qos.logback.classic.LoggerContext
37+
import io.sentry.logback.SentryAppender
38+
import io.sentry.protocol.User
39+
import android.os.Build
40+
import android.provider.Settings
3541

3642
/**
3743
* @author Akash Yadav
@@ -67,16 +73,34 @@ internal object DeviceProtectedApplicationLoader :
6773
),
6874
)
6975

70-
SentryAndroid.init(app) { options ->
71-
// Reduce replay quality to LOW to prevent OOM
72-
// This reduces screenshot compression to 10 and bitrate to 50kbps
73-
// (defaults to MEDIUM quality)
74-
options.sessionReplay.quality = SentryReplayQuality.LOW
75-
options.environment =
76-
if (BuildConfig.DEBUG) IDEApplication.SENTRY_ENV_DEV else IDEApplication.SENTRY_ENV_PROD
77-
78-
// Enrich every Sentry event with app-specific diagnostic context.
79-
SentryDiagnosticsContext.install(options)
76+
runCatching {
77+
SentryAndroid.init(app) { options ->
78+
options.environment =
79+
if (BuildConfig.DEBUG) IDEApplication.SENTRY_ENV_DEV else IDEApplication.SENTRY_ENV_PROD
80+
81+
// Enrich every Sentry event with app-specific diagnostic context.
82+
SentryDiagnosticsContext.install(options)
83+
}
84+
85+
val loggerContext = LoggerFactory.getILoggerFactory() as LoggerContext
86+
val sentryLogAppender =
87+
SentryAppender().apply {
88+
context = loggerContext
89+
setMinimumEventLevel(Level.OFF)
90+
setMinimumBreadcrumbLevel(Level.INFO)
91+
setMinimumLevel(Level.WARN)
92+
start()
93+
}
94+
loggerContext.getLogger(Logger.ROOT_LOGGER_NAME).addAppender(sentryLogAppender)
95+
96+
Sentry.setUser(
97+
User().apply {
98+
id = Settings.Secure.getString(app.contentResolver, Settings.Secure.ANDROID_ID)
99+
username = "${Build.MANUFACTURER} ${Build.MODEL}"
100+
},
101+
)
102+
}.onFailure {
103+
logger.error("Failed to initialize crash and log reporting", it)
80104
}
81105

82106
ShizukuSettings.initialize()

‎gradle/libs.versions.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ firebase-analytics = { module = "com.google.firebase:firebase-analytics-ktx" }
147147
# Sentry
148148
sentry-core = { module = "io.sentry:sentry", version.ref = "sentry" }
149149
sentry-android-core = { module = "io.sentry:sentry-android-core", version.ref = "sentry" }
150-
sentry-android-replay = { module = "io.sentry:sentry-android-replay", version.ref = "sentry" }
150+
sentry-logback = { module = "io.sentry:sentry-logback", version.ref = "sentry" }
151151

152152
# AndroidIDE
153153
androidide-ts = { module = "com.itsaky.androidide.treesitter:android-tree-sitter", version.ref = "tree-sitter" }

0 commit comments

Comments
 (0)