Use secret Sentry DSN value (#4210)

* Use secret Sentry DSN value.

We realised our DSN entry has been shipped along with the code and it was being used in several forks as is, resulting in wrong bug reports coming into our Sentry dashboard and making it very hard to debug actual issues in the app.
This commit is contained in:
Jorge Martin Espinosa 2025-01-29 13:47:06 +01:00 committed by GitHub
parent 2150eaa504
commit c935783a78
11 changed files with 52 additions and 14 deletions

View file

@ -1,3 +1,4 @@
import extension.readLocalProperty
import extension.setupAnvil
/*
@ -12,6 +13,21 @@ plugins {
android {
namespace = "io.element.android.services.analyticsproviders.sentry"
buildFeatures {
buildConfig = true
}
defaultConfig {
buildConfigField(
type = "String",
name = "SENTRY_DSN",
value = (System.getenv("ELEMENT_ANDROID_SENTRY_DSN")
?: readLocalProperty("services.analyticsproviders.sentry.dsn")
?: ""
).let { "\"$it\"" }
)
}
}
setupAnvil()

View file

@ -20,6 +20,7 @@ import io.element.android.libraries.di.ApplicationContext
import io.element.android.services.analyticsproviders.api.AnalyticsProvider
import io.element.android.services.analyticsproviders.sentry.log.analyticsTag
import io.sentry.Sentry
import io.sentry.SentryLevel
import io.sentry.SentryOptions
import io.sentry.android.core.SentryAndroid
import timber.log.Timber
@ -35,13 +36,20 @@ class SentryAnalyticsProvider @Inject constructor(
override fun init() {
Timber.tag(analyticsTag.value).d("Initializing Sentry")
if (Sentry.isEnabled()) return
val dsn = if (SentryConfig.DSN.isNotBlank()) {
SentryConfig.DSN
} else {
Timber.w("No Sentry DSN provided, Sentry will not be initialized")
return
}
SentryAndroid.init(context) { options ->
options.dsn = SentryConfig.DNS
options.dsn = dsn
options.beforeSend = SentryOptions.BeforeSendCallback { event, _ -> event }
options.tracesSampleRate = 1.0
options.isEnableUserInteractionTracing = true
options.environment = buildMeta.buildType.toSentryEnv()
options.diagnosticLevel
}
}
@ -51,9 +59,11 @@ class SentryAnalyticsProvider @Inject constructor(
}
override fun capture(event: VectorAnalyticsEvent) {
Sentry.captureMessage("Event: ${event.getName()}", SentryLevel.INFO)
}
override fun screen(screen: VectorAnalyticsScreen) {
Sentry.captureMessage("Screen: ${screen.getName()}", SentryLevel.INFO)
}
override fun updateUserProperties(userProperties: UserProperties) {

View file

@ -9,7 +9,7 @@ package io.element.android.services.analyticsproviders.sentry
object SentryConfig {
const val NAME = "Sentry"
const val DNS = "https://32f7ff6a6e724f90838b7654042b2e81@sentry.tools.element.io/59"
const val DSN = BuildConfig.SENTRY_DSN
const val ENV_DEBUG = "DEBUG"
const val ENV_RELEASE = "RELEASE"
}