1
0
Fork 0

Always initialize glean. Set upload flag after migration. (#7717)

master
Sebastian Kaspari 2020-01-16 00:31:51 +01:00 committed by liuche
parent 0777fb3bbe
commit 29d9ba472c
2 changed files with 29 additions and 10 deletions

View File

@ -20,6 +20,9 @@ import kotlinx.coroutines.runBlocking
import mozilla.appservices.Megazord
import mozilla.components.concept.push.PushProcessor
import mozilla.components.service.experiments.Experiments
import mozilla.components.service.glean.Glean
import mozilla.components.service.glean.config.Configuration
import mozilla.components.service.glean.net.ConceptFetchHttpUploader
import mozilla.components.support.base.log.Log
import mozilla.components.support.base.log.logger.Logger
import mozilla.components.support.base.log.sink.AndroidLogSink
@ -37,6 +40,7 @@ import org.mozilla.fenix.session.VisibilityLifecycleCallback
@SuppressLint("Registered")
@Suppress("TooManyFunctions")
open class FenixApplication : LocaleAwareApplication() {
private val logger = Logger("FenixApplication")
open val components by lazy { Components(this) }
@ -56,6 +60,27 @@ open class FenixApplication : LocaleAwareApplication() {
return
}
// We need to always initialize Glean and do it early here. Note that we are disabling it
// here too (uploadEnabled = false). If needed Glean will be enabled later by the migration
// code (if this user used to be a fennec user with the right flags enabled) or by
// GleanMetricsService if telemetry is enabled for this user.
// It is important that this initialization happens *here* before calling into
// setupInMainProcessOnly() which behaves differently for fenix and fennec builds.
// Glean needs to be disabled initially because otherwise we may already collect telemetry
// before we know whether we want that (which is *after* the migration).
// As a side effect this means pings submitted between the initialization here and until we
// potentially enable Glean would be lost. However such pings do not exist at this moment.
logger.debug("Initializing Glean (uploadEnabled=false)")
Glean.initialize(
applicationContext = this,
configuration = Configuration(
channel = BuildConfig.BUILD_TYPE,
httpClient = ConceptFetchHttpUploader(
lazy(LazyThreadSafetyMode.NONE) { components.core.client }
)),
uploadEnabled = false
)
setupInMainProcessOnly()
}

View File

@ -8,11 +8,9 @@ import android.content.Context
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.MainScope
import mozilla.components.service.glean.BuildConfig
import mozilla.components.service.glean.Glean
import mozilla.components.service.glean.config.Configuration
import mozilla.components.service.glean.net.ConceptFetchHttpUploader
import mozilla.components.service.glean.private.NoExtraKeys
import mozilla.components.support.base.log.logger.Logger
import org.mozilla.fenix.GleanMetrics.BookmarksManagement
import org.mozilla.fenix.GleanMetrics.Collections
import org.mozilla.fenix.GleanMetrics.ContextMenu
@ -474,6 +472,7 @@ private val Event.wrapper: EventWrapper<*>?
}
class GleanMetricsService(private val context: Context) : MetricsService {
private val logger = Logger("GleanMetricsService")
private var initialized = false
/*
* We need to keep an eye on when we are done starting so that we don't
@ -485,6 +484,8 @@ class GleanMetricsService(private val context: Context) : MetricsService {
private val activationPing = ActivationPing(context)
override fun start() {
logger.debug("Enabling Glean.")
// Initialization of Glean already happened in FenixApplication.
Glean.setUploadEnabled(true)
if (initialized) return
@ -497,13 +498,6 @@ class GleanMetricsService(private val context: Context) : MetricsService {
// can handle events being recorded before it's initialized.
gleanInitializer = MainScope().launch {
Glean.registerPings(Pings)
Glean.initialize(
applicationContext = context,
uploadEnabled = true,
configuration = Configuration(channel = BuildConfig.BUILD_TYPE,
httpClient = ConceptFetchHttpUploader(
lazy(LazyThreadSafetyMode.NONE) { context.components.core.client }
)))
}
// setStartupMetrics is not a fast function. It does not need to be done before we can consider
// ourselves initialized. So, let's do it, well, later.