Distinguish between indexable and non-indexable extra data
This commit is contained in:
committed by
Jorge Martin Espinosa
parent
5c6fee08fd
commit
7fe3b18699
@@ -11,7 +11,8 @@ import io.element.android.services.analyticsproviders.api.AnalyticsTransaction
|
||||
|
||||
object NoopAnalyticsTransaction : AnalyticsTransaction {
|
||||
override fun startChild(operation: String, description: String?): AnalyticsTransaction = NoopAnalyticsTransaction
|
||||
override fun setData(key: String, value: Any) {}
|
||||
override fun putExtraData(key: String, value: String) {}
|
||||
override fun putIndexableData(key: String, value: String) {}
|
||||
override fun isFinished(): Boolean = true
|
||||
override fun traceId(): String? = null
|
||||
override fun attachError(throwable: Throwable) {}
|
||||
|
||||
@@ -149,9 +149,15 @@ class DefaultAnalyticsService(
|
||||
}
|
||||
}
|
||||
|
||||
override fun addUserData(key: String, value: String) {
|
||||
override fun addExtraData(key: String, value: String) {
|
||||
if (userConsent.get()) {
|
||||
analyticsProviders.onEach { it.addUserData(key, value) }
|
||||
analyticsProviders.onEach { it.addExtraData(key, value) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun addIndexableData(key: String, value: String) {
|
||||
if (userConsent.get()) {
|
||||
analyticsProviders.onEach { it.addIndexableData(key, value) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,14 +8,47 @@
|
||||
package io.element.android.services.analyticsproviders.api
|
||||
|
||||
interface AnalyticsTransaction {
|
||||
/**
|
||||
* Start a child span from this transaction.
|
||||
*/
|
||||
fun startChild(operation: String, description: String? = null): AnalyticsTransaction
|
||||
fun setData(key: String, value: Any)
|
||||
|
||||
/**
|
||||
* Adds extra data to the transaction. This data is not indexed, it's just listed.
|
||||
*/
|
||||
fun putExtraData(key: String, value: String)
|
||||
|
||||
/**
|
||||
* Similar to [putExtraData], adds extra data that *will be indexed* and can be used for filtering in the analytics portal.
|
||||
*
|
||||
* **Do not add numerical values using this function, use [putExtraData] instead.**
|
||||
*/
|
||||
fun putIndexableData(key: String, value: String)
|
||||
|
||||
/**
|
||||
* Whether the transaction has finished.
|
||||
*/
|
||||
fun isFinished(): Boolean
|
||||
|
||||
/**
|
||||
* The optional trace id which can be used for distributed tracing.
|
||||
*/
|
||||
fun traceId(): String?
|
||||
|
||||
/**
|
||||
* Attach a throwable to the transaction, so we can know it failed.
|
||||
*/
|
||||
fun attachError(throwable: Throwable)
|
||||
|
||||
/**
|
||||
* Finish the transaction. This will schedule an upload of the data.
|
||||
*/
|
||||
fun finish()
|
||||
}
|
||||
|
||||
/**
|
||||
* Records a child span from this transaction.
|
||||
*/
|
||||
inline fun <T> AnalyticsTransaction.recordChildTransaction(operation: String, description: String? = null, block: (AnalyticsTransaction) -> T): T {
|
||||
val child = startChild(operation, description)
|
||||
try {
|
||||
|
||||
@@ -14,4 +14,7 @@ object AnalyticsUserData {
|
||||
const val EVENT_CACHE_SIZE = "event_cache_size"
|
||||
const val CRYPTO_STORE_SIZE = "crypto_store_size"
|
||||
const val MEDIA_STORE_SIZE = "media_store_size"
|
||||
|
||||
const val FIRST_SYNC_STATE = "first_sync_state"
|
||||
const val TIMELINE_ITEM_COUNT = "timeline_item_count"
|
||||
}
|
||||
|
||||
@@ -37,9 +37,16 @@ interface AnalyticsTracker {
|
||||
fun updateSuperProperties(updatedProperties: SuperProperties)
|
||||
|
||||
/**
|
||||
* Adds user data that will be sent with every event.
|
||||
* Adds extra data that will be sent with every event.
|
||||
*/
|
||||
fun addUserData(key: String, value: String) {}
|
||||
fun addExtraData(key: String, value: String) {}
|
||||
|
||||
/**
|
||||
* Similar to [addExtraData], adds data that will be indexed in the analytics portal.
|
||||
*
|
||||
* **Do not add numerical values using this, use [addExtraData] instead.**
|
||||
*/
|
||||
fun addIndexableData(key: String, value: String) {}
|
||||
}
|
||||
|
||||
fun AnalyticsTracker.captureInteraction(name: Interaction.Name, type: Interaction.InteractionType? = null) {
|
||||
|
||||
@@ -113,10 +113,14 @@ class SentryAnalyticsProvider(
|
||||
override fun updateSuperProperties(updatedProperties: SuperProperties) {
|
||||
}
|
||||
|
||||
override fun addUserData(key: String, value: String) {
|
||||
override fun addExtraData(key: String, value: String) {
|
||||
Sentry.setExtra(key, value)
|
||||
}
|
||||
|
||||
override fun addIndexableData(key: String, value: String) {
|
||||
Sentry.setTag(key, value)
|
||||
}
|
||||
|
||||
override fun trackError(throwable: Throwable) {
|
||||
Sentry.captureException(throwable)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@ class SentryAnalyticsTransaction private constructor(span: ISpan) : AnalyticsTra
|
||||
override fun startChild(operation: String, description: String?): AnalyticsTransaction = SentryAnalyticsTransaction(
|
||||
inner.startChild(operation, description)
|
||||
)
|
||||
override fun setData(key: String, value: Any) = inner.setData(key, value)
|
||||
|
||||
override fun putIndexableData(key: String, value: String) = inner.setTag(key, value)
|
||||
override fun putExtraData(key: String, value: String) = inner.setData(key, value)
|
||||
override fun traceId(): String? = inner.toSentryTrace().value
|
||||
override fun isFinished(): Boolean = inner.isFinished
|
||||
override fun attachError(throwable: Throwable) {
|
||||
|
||||
Reference in New Issue
Block a user