Adjust metrics to the new specifications (#5937)

* Add `AnalyticsTransactions` with a set of `TransactionDefinition` items matching those in the user story

* Use that for `AnalyticsLongRunningTransactions`, make sure we send the right fields (name, operation, description)

* Add `AnalyticsSendMessageWatcher` to track how long it takes for an event to be sent and for us to get a call back for that from sync

* Add `Noop` implementation for enterprise
This commit is contained in:
Jorge Martin Espinosa
2026-01-05 16:23:26 +01:00
committed by GitHub
parent bc62d4c8ba
commit 71031008dd
33 changed files with 443 additions and 48 deletions

View File

@@ -21,5 +21,5 @@ interface AnalyticsProvider : AnalyticsTracker, ErrorTracker {
fun stop()
fun startTransaction(name: String, operation: String? = null): AnalyticsTransaction?
fun startTransaction(name: String, operation: String? = null, description: String? = null): AnalyticsTransaction?
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 2025 Element Creations 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.services.analyticsproviders.api
object AnalyticsTransactions {
val coldStart = TransactionDefinition(
name = "Cold start",
operation = "ux",
description = "Cold start until the cached room list is displayed",
)
val catchUp = TransactionDefinition(
name = "Catch-up",
operation = "ux",
description = "The app syncs and the room list becomes up-to-date",
)
val notificationToMessage = TransactionDefinition(
name = "Notification to message",
operation = "ux",
description = "A notification was tapped and it opened a timeline",
)
val openRoom = TransactionDefinition(
name = "Open a room",
operation = "ux",
description = "Open a room and see loaded items in the timeline",
)
val sendMessage = TransactionDefinition(
name = "Send a message",
operation = "ux",
description = "Send to sent state in timeline",
)
}
data class TransactionDefinition(
val name: String,
val operation: String? = null,
val description: String?,
)

View File

@@ -124,7 +124,7 @@ class PosthogAnalyticsProvider(
return withSuperProperties.takeIf { it.isEmpty().not() }
}
override fun startTransaction(name: String, operation: String?): AnalyticsTransaction? = null
override fun startTransaction(name: String, operation: String?, description: String?): AnalyticsTransaction? = null
}
private fun Map<String, Any?>.keepOnlyNonNullValues(): Map<String, Any> {

View File

@@ -112,8 +112,8 @@ class SentryAnalyticsProvider(
Sentry.captureException(throwable)
}
override fun startTransaction(name: String, operation: String?): AnalyticsTransaction? {
return SentryAnalyticsTransaction(name, operation)
override fun startTransaction(name: String, operation: String?, description: String?): AnalyticsTransaction? {
return SentryAnalyticsTransaction(name, operation, description)
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)

View File

@@ -14,7 +14,9 @@ import io.sentry.Sentry
import timber.log.Timber
class SentryAnalyticsTransaction private constructor(span: ISpan) : AnalyticsTransaction {
constructor(name: String, operation: String?) : this(Sentry.startTransaction(name, operation.orEmpty()))
constructor(name: String, operation: String?, description: String? = null) : this(
Sentry.startTransaction(name, operation.orEmpty()).also { it.description = description }
)
private val inner = span
override fun startChild(operation: String, description: String?): AnalyticsTransaction = SentryAnalyticsTransaction(
@@ -30,7 +32,7 @@ class SentryAnalyticsTransaction private constructor(span: ISpan) : AnalyticsTra
}
override fun finish() {
val name = if (inner is ITransaction) inner.name else inner.operation
Timber.d("Finishing transaction: $name")
Timber.d("Finishing transaction: '$name'")
inner.finish()
}
}

View File

@@ -33,5 +33,5 @@ class FakeAnalyticsProvider(
override fun updateUserProperties(userProperties: UserProperties) = updateUserPropertiesLambda(userProperties)
override fun trackError(throwable: Throwable) = trackErrorLambda(throwable)
override fun updateSuperProperties(updatedProperties: SuperProperties) = updateSuperPropertiesLambda(updatedProperties)
override fun startTransaction(name: String, operation: String?): AnalyticsTransaction? = null
override fun startTransaction(name: String, operation: String?, description: String?): AnalyticsTransaction? = null
}