change(tracing) : change how tracing is configured (ui and logic)
This commit is contained in:
parent
fd3b99765d
commit
7d27e6581b
38 changed files with 220 additions and 886 deletions
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Copyright 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.impl.di
|
||||
|
||||
import com.squareup.anvil.annotations.ContributesTo
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import io.element.android.libraries.core.meta.BuildMeta
|
||||
import io.element.android.libraries.core.meta.BuildType
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfiguration
|
||||
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfigurations
|
||||
|
||||
@Module
|
||||
@ContributesTo(AppScope::class)
|
||||
object TracingMatrixModule {
|
||||
@Provides
|
||||
fun providesTracingFilterConfiguration(buildMeta: BuildMeta): TracingFilterConfiguration {
|
||||
return when (buildMeta.buildType) {
|
||||
BuildType.DEBUG -> TracingFilterConfigurations.debug
|
||||
BuildType.NIGHTLY -> TracingFilterConfigurations.nightly
|
||||
BuildType.RELEASE -> TracingFilterConfigurations.release
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ package io.element.android.libraries.matrix.impl.tracing
|
|||
import com.squareup.anvil.annotations.ContributesBinding
|
||||
import io.element.android.libraries.core.meta.BuildMeta
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.matrix.api.tracing.LogLevel
|
||||
import io.element.android.libraries.matrix.api.tracing.TracingConfiguration
|
||||
import io.element.android.libraries.matrix.api.tracing.TracingService
|
||||
import io.element.android.libraries.matrix.api.tracing.WriteToFilesConfiguration
|
||||
|
|
@ -20,21 +21,28 @@ import javax.inject.Inject
|
|||
@ContributesBinding(AppScope::class)
|
||||
class RustTracingService @Inject constructor(private val buildMeta: BuildMeta) : TracingService {
|
||||
override fun setupTracing(tracingConfiguration: TracingConfiguration) {
|
||||
/*
|
||||
val filter = tracingConfiguration.filterConfiguration
|
||||
val rustTracingConfiguration = org.matrix.rustcomponents.sdk.TracingConfiguration(
|
||||
filter = tracingConfiguration.filterConfiguration.filter,
|
||||
writeToStdoutOrSystem = tracingConfiguration.writesToLogcat,
|
||||
logLevel = tracingConfiguration.logLevel.toRustLogLevel(),
|
||||
extraTargets = tracingConfiguration.extraTargets,
|
||||
writeToFiles = tracingConfiguration.writesToFilesConfiguration.toTracingFileConfiguration(),
|
||||
)
|
||||
org.matrix.rustcomponents.sdk.setupTracing(rustTracingConfiguration)
|
||||
Timber.v("Tracing config filter = $filter: ${filter.filter}")
|
||||
|
||||
*/
|
||||
Timber.d("setupTracing: $rustTracingConfiguration")
|
||||
}
|
||||
|
||||
override fun createTimberTree(): Timber.Tree {
|
||||
return RustTracingTree(retrieveFromStackTrace = buildMeta.isDebuggable)
|
||||
override fun createTimberTree(target: String): Timber.Tree {
|
||||
return RustTracingTree(target = target, retrieveFromStackTrace = buildMeta.isDebuggable)
|
||||
}
|
||||
}
|
||||
|
||||
private fun LogLevel.toRustLogLevel(): org.matrix.rustcomponents.sdk.LogLevel {
|
||||
return when (this) {
|
||||
LogLevel.ERROR -> org.matrix.rustcomponents.sdk.LogLevel.ERROR
|
||||
LogLevel.WARN -> org.matrix.rustcomponents.sdk.LogLevel.WARN
|
||||
LogLevel.INFO -> org.matrix.rustcomponents.sdk.LogLevel.INFO
|
||||
LogLevel.DEBUG -> org.matrix.rustcomponents.sdk.LogLevel.DEBUG
|
||||
LogLevel.TRACE -> org.matrix.rustcomponents.sdk.LogLevel.TRACE
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
package io.element.android.libraries.matrix.impl.tracing
|
||||
|
||||
import android.util.Log
|
||||
import io.element.android.libraries.matrix.api.tracing.Target
|
||||
import org.matrix.rustcomponents.sdk.LogLevel
|
||||
import org.matrix.rustcomponents.sdk.logEvent
|
||||
import timber.log.Timber
|
||||
|
|
@ -26,7 +25,10 @@ private val fqcnIgnore = listOf(
|
|||
/**
|
||||
* A Timber tree that passes logs to the Rust SDK.
|
||||
*/
|
||||
internal class RustTracingTree(private val retrieveFromStackTrace: Boolean) : Timber.Tree() {
|
||||
internal class RustTracingTree(
|
||||
private val target: String,
|
||||
private val retrieveFromStackTrace: Boolean,
|
||||
) : Timber.Tree() {
|
||||
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
|
||||
val location = if (retrieveFromStackTrace) {
|
||||
getLogEventLocationFromStackTrace()
|
||||
|
|
@ -38,7 +40,7 @@ internal class RustTracingTree(private val retrieveFromStackTrace: Boolean) : Ti
|
|||
file = location.file,
|
||||
line = location.line,
|
||||
level = logLevel,
|
||||
target = Target.ELEMENT.filter,
|
||||
target = target,
|
||||
message = if (tag != null) "[$tag] $message" else message,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Copyright 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.impl.di
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.core.meta.BuildType
|
||||
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfigurations
|
||||
import io.element.android.libraries.matrix.test.core.aBuildMeta
|
||||
import org.junit.Test
|
||||
|
||||
class TracingMatrixModuleTest {
|
||||
@Test
|
||||
fun `providesTracingFilterConfiguration returns debug config for debug build`() {
|
||||
assertThat(TracingMatrixModule.providesTracingFilterConfiguration(aBuildMeta(BuildType.DEBUG)))
|
||||
.isEqualTo(TracingFilterConfigurations.debug)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `providesTracingFilterConfiguration returns nightly config for nightly build`() {
|
||||
assertThat(TracingMatrixModule.providesTracingFilterConfiguration(aBuildMeta(BuildType.NIGHTLY)))
|
||||
.isEqualTo(TracingFilterConfigurations.nightly)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `providesTracingFilterConfiguration returns release config for release build`() {
|
||||
assertThat(TracingMatrixModule.providesTracingFilterConfiguration(aBuildMeta(BuildType.RELEASE)))
|
||||
.isEqualTo(TracingFilterConfigurations.release)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue