Always initialize glean. Set upload flag after migration. (#7717)
parent
0777fb3bbe
commit
29d9ba472c
|
@ -20,6 +20,9 @@ import kotlinx.coroutines.runBlocking
|
||||||
import mozilla.appservices.Megazord
|
import mozilla.appservices.Megazord
|
||||||
import mozilla.components.concept.push.PushProcessor
|
import mozilla.components.concept.push.PushProcessor
|
||||||
import mozilla.components.service.experiments.Experiments
|
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.Log
|
||||||
import mozilla.components.support.base.log.logger.Logger
|
import mozilla.components.support.base.log.logger.Logger
|
||||||
import mozilla.components.support.base.log.sink.AndroidLogSink
|
import mozilla.components.support.base.log.sink.AndroidLogSink
|
||||||
|
@ -37,6 +40,7 @@ import org.mozilla.fenix.session.VisibilityLifecycleCallback
|
||||||
@SuppressLint("Registered")
|
@SuppressLint("Registered")
|
||||||
@Suppress("TooManyFunctions")
|
@Suppress("TooManyFunctions")
|
||||||
open class FenixApplication : LocaleAwareApplication() {
|
open class FenixApplication : LocaleAwareApplication() {
|
||||||
|
private val logger = Logger("FenixApplication")
|
||||||
|
|
||||||
open val components by lazy { Components(this) }
|
open val components by lazy { Components(this) }
|
||||||
|
|
||||||
|
@ -56,6 +60,27 @@ open class FenixApplication : LocaleAwareApplication() {
|
||||||
return
|
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()
|
setupInMainProcessOnly()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,9 @@ import android.content.Context
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.MainScope
|
import kotlinx.coroutines.MainScope
|
||||||
import mozilla.components.service.glean.BuildConfig
|
|
||||||
import mozilla.components.service.glean.Glean
|
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.service.glean.private.NoExtraKeys
|
||||||
|
import mozilla.components.support.base.log.logger.Logger
|
||||||
import org.mozilla.fenix.GleanMetrics.BookmarksManagement
|
import org.mozilla.fenix.GleanMetrics.BookmarksManagement
|
||||||
import org.mozilla.fenix.GleanMetrics.Collections
|
import org.mozilla.fenix.GleanMetrics.Collections
|
||||||
import org.mozilla.fenix.GleanMetrics.ContextMenu
|
import org.mozilla.fenix.GleanMetrics.ContextMenu
|
||||||
|
@ -474,6 +472,7 @@ private val Event.wrapper: EventWrapper<*>?
|
||||||
}
|
}
|
||||||
|
|
||||||
class GleanMetricsService(private val context: Context) : MetricsService {
|
class GleanMetricsService(private val context: Context) : MetricsService {
|
||||||
|
private val logger = Logger("GleanMetricsService")
|
||||||
private var initialized = false
|
private var initialized = false
|
||||||
/*
|
/*
|
||||||
* We need to keep an eye on when we are done starting so that we don't
|
* 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)
|
private val activationPing = ActivationPing(context)
|
||||||
|
|
||||||
override fun start() {
|
override fun start() {
|
||||||
|
logger.debug("Enabling Glean.")
|
||||||
|
// Initialization of Glean already happened in FenixApplication.
|
||||||
Glean.setUploadEnabled(true)
|
Glean.setUploadEnabled(true)
|
||||||
|
|
||||||
if (initialized) return
|
if (initialized) return
|
||||||
|
@ -497,13 +498,6 @@ class GleanMetricsService(private val context: Context) : MetricsService {
|
||||||
// can handle events being recorded before it's initialized.
|
// can handle events being recorded before it's initialized.
|
||||||
gleanInitializer = MainScope().launch {
|
gleanInitializer = MainScope().launch {
|
||||||
Glean.registerPings(Pings)
|
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
|
// 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.
|
// ourselves initialized. So, let's do it, well, later.
|
||||||
|
|
Loading…
Reference in New Issue