Merge pull request #1268 from vector-im/feature/bma/moreTrace

Add SDK trace item, set RUST_BACKTRACE and be able to configure trace before a session exists.
This commit is contained in:
Benoit Marty 2023-09-11 12:34:32 +02:00 committed by GitHub
commit 76d0130ead
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 148 additions and 18 deletions

View file

@ -17,6 +17,7 @@
package io.element.android.x.initializer
import android.content.Context
import android.system.Os
import androidx.preference.PreferenceManager
import androidx.startup.Initializer
import io.element.android.features.preferences.impl.developer.tracing.SharedPrefTracingConfigurationStore
@ -57,6 +58,8 @@ class TracingInitializer : Initializer<Unit> {
}
bugReporter.cleanLogDirectoryIfNeeded()
tracingService.setupTracing(tracingConfiguration)
// Also set env variable for rust back trace
Os.setenv("RUST_BACKTRACE", "1", true)
}
override fun dependencies(): List<Class<out Initializer<*>>> = mutableListOf()

View file

@ -32,6 +32,7 @@ import dagger.assisted.AssistedInject
import io.element.android.anvilannotations.ContributesNode
import io.element.android.features.login.api.LoginEntryPoint
import io.element.android.features.onboarding.api.OnBoardingEntryPoint
import io.element.android.features.preferences.api.ConfigureTracingEntryPoint
import io.element.android.libraries.architecture.BackstackNode
import io.element.android.libraries.architecture.animation.rememberDefaultTransitionHandler
import io.element.android.libraries.di.AppScope
@ -43,6 +44,7 @@ class NotLoggedInFlowNode @AssistedInject constructor(
@Assisted buildContext: BuildContext,
@Assisted plugins: List<Plugin>,
private val onBoardingEntryPoint: OnBoardingEntryPoint,
private val configureTracingEntryPoint: ConfigureTracingEntryPoint,
private val loginEntryPoint: LoginEntryPoint,
private val notLoggedInImageLoaderFactory: NotLoggedInImageLoaderFactory,
) : BackstackNode<NotLoggedInFlowNode.NavTarget>(
@ -70,6 +72,9 @@ class NotLoggedInFlowNode @AssistedInject constructor(
data class LoginFlow(
val isAccountCreation: Boolean,
) : NavTarget
@Parcelize
data object ConfigureTracing : NavTarget
}
override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node {
@ -83,6 +88,10 @@ class NotLoggedInFlowNode @AssistedInject constructor(
override fun onSignIn() {
backstack.push(NavTarget.LoginFlow(isAccountCreation = false))
}
override fun onOpenDeveloperSettings() {
backstack.push(NavTarget.ConfigureTracing)
}
}
onBoardingEntryPoint
.nodeBuilder(this, buildContext)
@ -94,6 +103,9 @@ class NotLoggedInFlowNode @AssistedInject constructor(
.params(LoginEntryPoint.Params(isAccountCreation = navTarget.isAccountCreation))
.build()
}
NavTarget.ConfigureTracing -> {
configureTracingEntryPoint.createNode(this, buildContext)
}
}
}

View file

@ -33,5 +33,6 @@ interface OnBoardingEntryPoint : FeatureEntryPoint {
interface Callback : Plugin {
fun onSignUp()
fun onSignIn()
fun onOpenDeveloperSettings()
}
}

View file

@ -46,6 +46,10 @@ class OnBoardingNode @AssistedInject constructor(
plugins<OnBoardingEntryPoint.Callback>().forEach { it.onSignUp() }
}
private fun onOpenDeveloperSettings() {
plugins<OnBoardingEntryPoint.Callback>().forEach { it.onOpenDeveloperSettings() }
}
@Composable
override fun View(modifier: Modifier) {
val state = presenter.present()
@ -54,6 +58,8 @@ class OnBoardingNode @AssistedInject constructor(
modifier = modifier,
onSignIn = ::onSignIn,
onCreateAccount = ::onSignUp,
onSignInWithQrCode = { /* Not supported yet */ },
onOpenDeveloperSettings = ::onOpenDeveloperSettings,
)
}
}

View file

@ -18,6 +18,8 @@ package io.element.android.features.onboarding.impl
import androidx.compose.runtime.Composable
import io.element.android.libraries.architecture.Presenter
import io.element.android.libraries.core.meta.BuildMeta
import io.element.android.libraries.core.meta.BuildType
import javax.inject.Inject
/**
@ -25,10 +27,12 @@ import javax.inject.Inject
* When this presenter get more code in it, please remove the ignore rule in the kover configuration.
*/
class OnBoardingPresenter @Inject constructor(
private val buildMeta: BuildMeta,
) : Presenter<OnBoardingState> {
@Composable
override fun present(): OnBoardingState {
return OnBoardingState(
isDebugBuild = buildMeta.buildType != BuildType.RELEASE,
canLoginWithQrCode = OnBoardingConfig.canLoginWithQrCode,
canCreateAccount = OnBoardingConfig.canCreateAccount,
)

View file

@ -17,6 +17,7 @@
package io.element.android.features.onboarding.impl
data class OnBoardingState(
val isDebugBuild: Boolean,
val canLoginWithQrCode: Boolean,
val canCreateAccount: Boolean,
)

View file

@ -25,13 +25,16 @@ open class OnBoardingStateProvider : PreviewParameterProvider<OnBoardingState> {
anOnBoardingState(canLoginWithQrCode = true),
anOnBoardingState(canCreateAccount = true),
anOnBoardingState(canLoginWithQrCode = true, canCreateAccount = true),
anOnBoardingState(isDebugBuild = true),
)
}
fun anOnBoardingState(
isDebugBuild: Boolean = false,
canLoginWithQrCode: Boolean = false,
canCreateAccount: Boolean = false
) = OnBoardingState(
isDebugBuild = isDebugBuild,
canLoginWithQrCode = canLoginWithQrCode,
canCreateAccount = canCreateAccount
)

View file

@ -25,7 +25,9 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.QrCode
import androidx.compose.material.icons.filled.Settings
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.BiasAlignment
import androidx.compose.ui.Modifier
@ -41,6 +43,8 @@ import io.element.android.libraries.designsystem.atomic.pages.OnBoardingPage
import io.element.android.libraries.designsystem.preview.DayNightPreviews
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.theme.components.Button
import io.element.android.libraries.designsystem.theme.components.Icon
import io.element.android.libraries.designsystem.theme.components.IconButton
import io.element.android.libraries.designsystem.theme.components.IconSource
import io.element.android.libraries.designsystem.theme.components.OutlinedButton
import io.element.android.libraries.designsystem.theme.components.Text
@ -57,15 +61,19 @@ import io.element.android.libraries.ui.strings.CommonStrings
@Composable
fun OnBoardingView(
state: OnBoardingState,
onSignInWithQrCode: () -> Unit,
onSignIn: () -> Unit,
onCreateAccount: () -> Unit,
onOpenDeveloperSettings: () -> Unit,
modifier: Modifier = Modifier,
onSignInWithQrCode: () -> Unit = {},
onSignIn: () -> Unit = {},
onCreateAccount: () -> Unit = {},
) {
OnBoardingPage(
modifier = modifier,
content = {
OnBoardingContent()
OnBoardingContent(
state = state,
onOpenDeveloperSettings = onOpenDeveloperSettings
)
},
footer = {
OnBoardingButtons(
@ -79,7 +87,11 @@ fun OnBoardingView(
}
@Composable
private fun OnBoardingContent(modifier: Modifier = Modifier) {
private fun OnBoardingContent(
state: OnBoardingState,
onOpenDeveloperSettings: () -> Unit,
modifier: Modifier = Modifier
) {
Box(
modifier = modifier.fillMaxSize(),
) {
@ -122,6 +134,17 @@ private fun OnBoardingContent(modifier: Modifier = Modifier) {
)
}
}
if (state.isDebugBuild) {
IconButton(
modifier = Modifier.align(Alignment.TopEnd),
onClick = onOpenDeveloperSettings,
) {
Icon(
imageVector = Icons.Filled.Settings,
contentDescription = stringResource(CommonStrings.common_settings)
)
}
}
}
}
@ -172,5 +195,11 @@ private fun OnBoardingButtons(
internal fun OnBoardingScreenPreview(
@PreviewParameter(OnBoardingStateProvider::class) state: OnBoardingState
) = ElementPreview {
OnBoardingView(state)
OnBoardingView(
state = state,
onSignInWithQrCode = {},
onSignIn = {},
onCreateAccount = {},
onOpenDeveloperSettings = {}
)
}

View file

@ -20,6 +20,8 @@ import app.cash.molecule.RecompositionMode
import app.cash.molecule.moleculeFlow
import app.cash.turbine.test
import com.google.common.truth.Truth.assertThat
import io.element.android.libraries.core.meta.BuildType
import io.element.android.libraries.matrix.test.core.aBuildMeta
import io.element.android.tests.testutils.WarmUpRule
import kotlinx.coroutines.test.runTest
import org.junit.Rule
@ -33,13 +35,25 @@ class OnBoardingPresenterTest {
@Test
fun `present - initial state`() = runTest {
val presenter = OnBoardingPresenter()
val presenter = OnBoardingPresenter(aBuildMeta())
moleculeFlow(RecompositionMode.Immediate) {
presenter.present()
}.test {
val initialState = awaitItem()
assertThat(initialState.isDebugBuild).isTrue()
assertThat(initialState.canLoginWithQrCode).isFalse()
assertThat(initialState.canCreateAccount).isFalse()
}
}
@Test
fun `present - initial state release`() = runTest {
val presenter = OnBoardingPresenter(aBuildMeta(buildType = BuildType.RELEASE))
moleculeFlow(RecompositionMode.Immediate) {
presenter.present()
}.test {
val initialState = awaitItem()
assertThat(initialState.isDebugBuild).isFalse()
}
}
}

View file

@ -0,0 +1,21 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.features.preferences.api
import io.element.android.libraries.architecture.SimpleFeatureEntryPoint
interface ConfigureTracingEntryPoint : SimpleFeatureEntryPoint

View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.features.preferences.impl
import com.bumble.appyx.core.modality.BuildContext
import com.bumble.appyx.core.node.Node
import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.features.preferences.api.ConfigureTracingEntryPoint
import io.element.android.features.preferences.impl.developer.tracing.ConfigureTracingNode
import io.element.android.libraries.architecture.createNode
import io.element.android.libraries.di.AppScope
import javax.inject.Inject
@ContributesBinding(AppScope::class)
class DefaultConfigureTracingEntryPoint @Inject constructor() : ConfigureTracingEntryPoint {
override fun createNode(parentNode: Node, buildContext: BuildContext): Node {
return parentNode.createNode<ConfigureTracingNode>(buildContext)
}
}

View file

@ -29,7 +29,6 @@ class TargetLogLevelMapBuilder @Inject constructor(
fun getDefaultMap(): Map<Target, LogLevel> {
return Target.entries.associateWith { target ->
defaultConfig.getLogLevel(target)
?: LogLevel.INFO
}
}
@ -37,7 +36,6 @@ class TargetLogLevelMapBuilder @Inject constructor(
return Target.entries.associateWith { target ->
tracingConfigurationStore.getLogLevel(target)
?: defaultConfig.getLogLevel(target)
?: LogLevel.INFO
}
}
}

View file

@ -19,27 +19,25 @@ package io.element.android.libraries.matrix.api.tracing
data class TracingFilterConfiguration(
val overrides: Map<Target, LogLevel> = emptyMap(),
) {
private val defaultLogLevel = LogLevel.INFO
// Order should matters
private val targetsToLogLevel: Map<Target, LogLevel> = mapOf(
Target.COMMON to LogLevel.INFO,
Target.HYPER to LogLevel.WARN,
Target.MATRIX_SDK_CRYPTO to LogLevel.DEBUG,
Target.MATRIX_SDK_HTTP_CLIENT to LogLevel.DEBUG,
Target.MATRIX_SDK_SLIDING_SYNC to LogLevel.TRACE,
Target.MATRIX_SDK_BASE_SLIDING_SYNC to LogLevel.TRACE,
Target.MATRIX_SDK_UI_TIMELINE to LogLevel.INFO,
)
fun getLogLevel(target: Target): LogLevel? {
return overrides[target] ?: targetsToLogLevel[target]
fun getLogLevel(target: Target): LogLevel {
return overrides[target] ?: targetsToLogLevel[target] ?: defaultLogLevel
}
val filter: String
get() {
val fullMap = targetsToLogLevel.toMutableMap()
overrides.forEach { (target, logLevel) ->
fullMap[target] = logLevel
val fullMap = Target.values().associateWith {
overrides[it] ?: targetsToLogLevel[it] ?: defaultLogLevel
}
return fullMap.map {
if (it.key.filter.isEmpty()) {
@ -58,7 +56,10 @@ enum class Target(open val filter: String) {
MATRIX_SDK_FFI("matrix_sdk_ffi"),
MATRIX_SDK_UNIFFI_API("matrix_sdk_ffi::uniffi_api"),
MATRIX_SDK_CRYPTO("matrix_sdk_crypto"),
MATRIX_SDK("matrix_sdk"),
MATRIX_SDK_HTTP_CLIENT("matrix_sdk::http_client"),
MATRIX_SDK_CLIENT("matrix_sdk::client"),
MATRIX_SDK_OIDC("matrix_sdk::oidc"),
MATRIX_SDK_SLIDING_SYNC("matrix_sdk::sliding_sync"),
MATRIX_SDK_BASE_SLIDING_SYNC("matrix_sdk_base::sliding_sync"),
MATRIX_SDK_UI_TIMELINE("matrix_sdk_ui::timeline"),
@ -75,13 +76,11 @@ enum class LogLevel(open val filter: String) {
object TracingFilterConfigurations {
val release = TracingFilterConfiguration(
overrides = mapOf(
Target.COMMON to LogLevel.INFO,
Target.ELEMENT to LogLevel.DEBUG
),
)
val debug = TracingFilterConfiguration(
overrides = mapOf(
Target.COMMON to LogLevel.INFO,
Target.ELEMENT to LogLevel.TRACE
)
)

View file

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c2c67243e8def6f8d188eb918b0dbd57dec3aae03fe8fca90ef5529658de537b
size 327304

View file

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:84e5641cce0113690d0d626bd3b17e8945728b3835a06b06a645418d12a05022
size 421112