Skip to content

Commit 55a1ac4

Browse files
jmartinespElementBot
and
ElementBot
authored
Fix tracing configuration in debug and nightlies (#3019)
* Fix tracing configuration in debug and nightlies: - Debug will now write the logs to disk too. - Nightly will be able to customise tracing filters. - Improved the configure tracing and bug report screens. * Update screenshots * Add changelog --------- Co-authored-by: ElementBot <[email protected]>
1 parent 3e04870 commit 55a1ac4

File tree

9 files changed

+101
-36
lines changed

9 files changed

+101
-36
lines changed

app/src/main/kotlin/io/element/android/x/initializer/TracingInitializer.kt

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import androidx.preference.PreferenceManager
2222
import androidx.startup.Initializer
2323
import io.element.android.features.preferences.impl.developer.tracing.SharedPreferencesTracingConfigurationStore
2424
import io.element.android.features.preferences.impl.developer.tracing.TargetLogLevelMapBuilder
25+
import io.element.android.features.rageshake.api.reporter.BugReporter
2526
import io.element.android.libraries.architecture.bindings
27+
import io.element.android.libraries.core.meta.BuildType
2628
import io.element.android.libraries.matrix.api.tracing.TracingConfiguration
2729
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfigurations
2830
import io.element.android.libraries.matrix.api.tracing.WriteToFilesConfiguration
@@ -36,31 +38,27 @@ class TracingInitializer : Initializer<Unit> {
3638
val tracingService = appBindings.tracingService()
3739
val bugReporter = appBindings.bugReporter()
3840
Timber.plant(tracingService.createTimberTree())
39-
val tracingConfiguration = if (BuildConfig.DEBUG) {
40-
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
41-
val store = SharedPreferencesTracingConfigurationStore(prefs)
42-
val builder = TargetLogLevelMapBuilder(store)
41+
val tracingConfiguration = if (BuildConfig.BUILD_TYPE == BuildType.RELEASE.name) {
4342
TracingConfiguration(
44-
filterConfiguration = TracingFilterConfigurations.custom(builder.getCurrentMap()),
45-
writesToLogcat = true,
46-
writesToFilesConfiguration = WriteToFilesConfiguration.Disabled
43+
filterConfiguration = TracingFilterConfigurations.release,
44+
writesToLogcat = false,
45+
writesToFilesConfiguration = defaultWriteToDiskConfiguration(bugReporter),
4746
)
4847
} else {
49-
val config = if (BuildConfig.BUILD_TYPE == "nightly") {
50-
TracingFilterConfigurations.nightly
51-
} else {
52-
TracingFilterConfigurations.release
53-
}
48+
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
49+
val store = SharedPreferencesTracingConfigurationStore(prefs)
50+
val builder = TargetLogLevelMapBuilder(
51+
tracingConfigurationStore = store,
52+
defaultConfig = if (BuildConfig.BUILD_TYPE == BuildType.NIGHTLY.name) {
53+
TracingFilterConfigurations.nightly
54+
} else {
55+
TracingFilterConfigurations.debug
56+
}
57+
)
5458
TracingConfiguration(
55-
filterConfiguration = config,
56-
writesToLogcat = false,
57-
writesToFilesConfiguration = WriteToFilesConfiguration.Enabled(
58-
directory = bugReporter.logDirectory().absolutePath,
59-
filenamePrefix = "logs",
60-
filenameSuffix = null,
61-
// Keep a minimum of 1 week of log files.
62-
numberOfFiles = 7 * 24,
63-
)
59+
filterConfiguration = TracingFilterConfigurations.custom(builder.getCurrentMap()),
60+
writesToLogcat = BuildConfig.DEBUG,
61+
writesToFilesConfiguration = defaultWriteToDiskConfiguration(bugReporter),
6462
)
6563
}
6664
bugReporter.setCurrentTracingFilter(tracingConfiguration.filterConfiguration.filter)
@@ -69,5 +67,15 @@ class TracingInitializer : Initializer<Unit> {
6967
Os.setenv("RUST_BACKTRACE", "1", true)
7068
}
7169

70+
private fun defaultWriteToDiskConfiguration(bugReporter: BugReporter): WriteToFilesConfiguration.Enabled {
71+
return WriteToFilesConfiguration.Enabled(
72+
directory = bugReporter.logDirectory().absolutePath,
73+
filenamePrefix = "logs",
74+
filenameSuffix = null,
75+
// Keep a minimum of 1 week of log files.
76+
numberOfFiles = 7 * 24,
77+
)
78+
}
79+
7280
override fun dependencies(): List<Class<out Initializer<*>>> = mutableListOf()
7381
}

changelog.d/3016.bugfix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Fix tracing configuration in debug and nightlies:
2+
3+
- Debug will now write the logs to disk too.
4+
- Nightly will be able to customise tracing filters.
5+
- Improved the configure tracing and bug report screens.

features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/developer/tracing/ConfigureTracingView.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.element.android.features.preferences.impl.developer.tracing
1818

19+
import androidx.compose.foundation.clickable
1920
import androidx.compose.foundation.layout.Box
2021
import androidx.compose.foundation.layout.Column
2122
import androidx.compose.foundation.layout.WindowInsets
@@ -48,6 +49,7 @@ import io.element.android.libraries.designsystem.preview.PreviewsDayNight
4849
import io.element.android.libraries.designsystem.theme.aliasScreenTitle
4950
import io.element.android.libraries.designsystem.theme.components.DropdownMenu
5051
import io.element.android.libraries.designsystem.theme.components.DropdownMenuItem
52+
import io.element.android.libraries.designsystem.theme.components.HorizontalDivider
5153
import io.element.android.libraries.designsystem.theme.components.Icon
5254
import io.element.android.libraries.designsystem.theme.components.IconButton
5355
import io.element.android.libraries.designsystem.theme.components.ListItem
@@ -124,15 +126,17 @@ fun ConfigureTracingView(
124126
.consumeWindowInsets(it)
125127
.verticalScroll(state = rememberScrollState())
126128
) {
127-
CrateListContent(state)
128129
ListItem(
129130
headlineContent = {
130131
Text(
131-
text = "Kill and restart the app for the change to take effect.",
132+
modifier = Modifier.clickable { Runtime.getRuntime().exit(0) },
133+
text = "Tap here to kill the app and apply the changes. You'll have to re-open the app manually.",
132134
style = ElementTheme.typography.fontHeadingSmMedium,
133135
)
134136
},
135137
)
138+
HorizontalDivider()
139+
CrateListContent(state)
136140
}
137141
}
138142
)

features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/developer/tracing/TargetLogLevelMapBuilder.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ package io.element.android.features.preferences.impl.developer.tracing
1818

1919
import io.element.android.libraries.matrix.api.tracing.LogLevel
2020
import io.element.android.libraries.matrix.api.tracing.Target
21-
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfigurations
21+
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfiguration
2222
import javax.inject.Inject
2323

2424
class TargetLogLevelMapBuilder @Inject constructor(
2525
private val tracingConfigurationStore: TracingConfigurationStore,
26+
private val defaultConfig: TracingFilterConfiguration,
2627
) {
27-
private val defaultConfig = TracingFilterConfigurations.debug
28-
2928
fun getDefaultMap(): Map<Target, LogLevel> {
3029
return Target.entries.associateWith { target ->
3130
defaultConfig.getLogLevel(target)

features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/developer/tracing/ConfigureTracingPresenterTest.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import app.cash.turbine.test
2222
import com.google.common.truth.Truth.assertThat
2323
import io.element.android.libraries.matrix.api.tracing.LogLevel
2424
import io.element.android.libraries.matrix.api.tracing.Target
25+
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfigurations
2526
import io.element.android.tests.testutils.WarmUpRule
2627
import io.element.android.tests.testutils.waitForPredicate
2728
import kotlinx.coroutines.test.runTest
@@ -37,7 +38,7 @@ class ConfigureTracingPresenterTest {
3738
val store = InMemoryTracingConfigurationStore()
3839
val presenter = ConfigureTracingPresenter(
3940
store,
40-
TargetLogLevelMapBuilder(store),
41+
TargetLogLevelMapBuilder(store, TracingFilterConfigurations.debug),
4142
)
4243
moleculeFlow(RecompositionMode.Immediate) {
4344
presenter.present()
@@ -54,7 +55,7 @@ class ConfigureTracingPresenterTest {
5455
store.givenLogLevel(LogLevel.ERROR)
5556
val presenter = ConfigureTracingPresenter(
5657
store,
57-
TargetLogLevelMapBuilder(store),
58+
TargetLogLevelMapBuilder(store, TracingFilterConfigurations.debug),
5859
)
5960
moleculeFlow(RecompositionMode.Immediate) {
6061
presenter.present()
@@ -70,7 +71,7 @@ class ConfigureTracingPresenterTest {
7071
val store = InMemoryTracingConfigurationStore()
7172
val presenter = ConfigureTracingPresenter(
7273
store,
73-
TargetLogLevelMapBuilder(store),
74+
TargetLogLevelMapBuilder(store, TracingFilterConfigurations.debug),
7475
)
7576
moleculeFlow(RecompositionMode.Immediate) {
7677
presenter.present()
@@ -89,7 +90,7 @@ class ConfigureTracingPresenterTest {
8990
val store = InMemoryTracingConfigurationStore()
9091
val presenter = ConfigureTracingPresenter(
9192
store,
92-
TargetLogLevelMapBuilder(store),
93+
TargetLogLevelMapBuilder(store, TracingFilterConfigurations.debug),
9394
)
9495
moleculeFlow(RecompositionMode.Immediate) {
9596
presenter.present()

features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/bugreport/BugReportView.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ import androidx.compose.foundation.layout.Spacer
2121
import androidx.compose.foundation.layout.fillMaxWidth
2222
import androidx.compose.foundation.layout.height
2323
import androidx.compose.foundation.layout.padding
24+
import androidx.compose.foundation.text.KeyboardActions
2425
import androidx.compose.foundation.text.KeyboardOptions
2526
import androidx.compose.runtime.Composable
2627
import androidx.compose.runtime.getValue
2728
import androidx.compose.runtime.setValue
2829
import androidx.compose.ui.Alignment
2930
import androidx.compose.ui.Modifier
3031
import androidx.compose.ui.platform.LocalContext
32+
import androidx.compose.ui.platform.LocalFocusManager
33+
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
3134
import androidx.compose.ui.res.stringResource
3235
import androidx.compose.ui.text.input.ImeAction
3336
import androidx.compose.ui.text.input.KeyboardCapitalization
@@ -51,6 +54,7 @@ import io.element.android.libraries.designsystem.preview.debugPlaceholderBackgro
5154
import io.element.android.libraries.designsystem.theme.components.Button
5255
import io.element.android.libraries.designsystem.theme.components.OutlinedTextField
5356
import io.element.android.libraries.designsystem.theme.components.Text
57+
import io.element.android.libraries.designsystem.theme.components.onTabOrEnterKeyFocusNext
5458
import io.element.android.libraries.ui.strings.CommonStrings
5559

5660
@Composable
@@ -68,6 +72,7 @@ fun BugReportView(
6872
title = stringResource(id = CommonStrings.common_report_a_problem),
6973
onBackClick = onBackClick
7074
) {
75+
val keyboardController = LocalSoftwareKeyboardController.current
7176
val isFormEnabled = state.sending !is AsyncAction.Loading
7277
var descriptionFieldState by textFieldState(
7378
stateValue = state.formState.description
@@ -76,7 +81,8 @@ fun BugReportView(
7681
PreferenceRow {
7782
OutlinedTextField(
7883
value = descriptionFieldState,
79-
modifier = Modifier.fillMaxWidth(),
84+
modifier = Modifier.fillMaxWidth()
85+
.onTabOrEnterKeyFocusNext(LocalFocusManager.current),
8086
enabled = isFormEnabled,
8187
label = {
8288
Text(text = stringResource(id = R.string.screen_bug_report_editor_placeholder))
@@ -91,8 +97,11 @@ fun BugReportView(
9197
keyboardOptions = KeyboardOptions(
9298
capitalization = KeyboardCapitalization.Sentences,
9399
keyboardType = KeyboardType.Text,
94-
imeAction = ImeAction.Next
100+
imeAction = ImeAction.Next,
95101
),
102+
keyboardActions = KeyboardActions(onNext = {
103+
keyboardController?.hide()
104+
}),
96105
minLines = 3,
97106
isError = state.isDescriptionInError,
98107
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2024 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.element.android.libraries.matrix.impl.di
18+
19+
import com.squareup.anvil.annotations.ContributesTo
20+
import dagger.Module
21+
import dagger.Provides
22+
import io.element.android.libraries.core.meta.BuildMeta
23+
import io.element.android.libraries.core.meta.BuildType
24+
import io.element.android.libraries.di.AppScope
25+
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfiguration
26+
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfigurations
27+
28+
@Module
29+
@ContributesTo(AppScope::class)
30+
object TracingMatrixModule {
31+
@Provides
32+
fun providesTracingFilterConfiguration(buildMeta: BuildMeta): TracingFilterConfiguration {
33+
return when (buildMeta.buildType) {
34+
BuildType.DEBUG -> TracingFilterConfigurations.debug
35+
BuildType.NIGHTLY -> TracingFilterConfigurations.nightly
36+
BuildType.RELEASE -> TracingFilterConfigurations.release
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)