Update rust sdk to 0.1.42 (changes in tracing and sync apis) (#1055)

* Update rust sdk to 0.1.42 (changes in tracing and sync apis)

* Fix sample compilation

---------

Co-authored-by: ganfra <francoisg@element.io>
This commit is contained in:
ganfra 2023-08-11 23:32:31 +02:00 committed by GitHub
parent 08a0f710d7
commit a911134636
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 42 additions and 19 deletions

View file

@ -41,9 +41,9 @@ class RustSyncService(
Timber.d("Start sync failed: $it")
}
override fun stopSync() = runCatching {
override suspend fun stopSync() = runCatching {
Timber.i("Stop sync")
innerSyncService.pause()
innerSyncService.stop()
}.onFailure {
Timber.d("Stop sync failed: $it")
}

View file

@ -22,8 +22,7 @@ package io.element.android.libraries.matrix.impl.tracing
*/
data class LogEventLocation(
val file: String,
val line: UInt,
val column: UInt,
val line: UInt?,
) {
companion object {
@ -32,9 +31,8 @@ data class LogEventLocation(
*/
fun from(stackTraceElement: StackTraceElement): LogEventLocation {
return LogEventLocation(
file = stackTraceElement.fileName,
line = stackTraceElement.lineNumber.toUInt(),
column = 0u,
file = stackTraceElement.fileName ?: "",
line = stackTraceElement.lineNumber.takeIf { it >= 0 }?.toUInt()
)
}
}

View file

@ -17,6 +17,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.TracingConfiguration
import io.element.android.libraries.matrix.api.tracing.TracingService
@ -26,13 +27,13 @@ import timber.log.Timber
import javax.inject.Inject
@ContributesBinding(AppScope::class)
class RustTracingService @Inject constructor() : TracingService {
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,
writeToStdoutOrSystem = tracingConfiguration.writesToLogcat,
writeToFiles = when (val writeToFilesConfiguration = tracingConfiguration.writesToFilesConfiguration) {
is WriteToFilesConfiguration.Disabled -> null
is WriteToFilesConfiguration.Enabled -> TracingFileConfiguration(
@ -46,6 +47,6 @@ class RustTracingService @Inject constructor() : TracingService {
}
override fun createTimberTree(): Timber.Tree {
return RustTracingTree()
return RustTracingTree(retrieveFromStackTrace = buildMeta.isDebuggable)
}
}

View file

@ -35,15 +35,18 @@ private val fqcnIgnore = listOf(
/**
* A Timber tree that passes logs to the Rust SDK.
*/
internal class RustTracingTree : Timber.Tree() {
internal class RustTracingTree(private val retrieveFromStackTrace: Boolean) : Timber.Tree() {
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
val location = getLogEventLocationFromStackTrace()
val location = if (retrieveFromStackTrace) {
getLogEventLocationFromStackTrace()
} else {
LogEventLocation("", null)
}
val logLevel = priority.toLogLevel()
logEvent(
file = location.file,
line = location.line,
column = location.column,
level = logLevel,
target = Target.ELEMENT.filter,
message = message,