Add AnalyticsUserData, with keys for several extras we want to upload to Sentry.
Add the `HOMESERVER` extra, with a hashed homeserver value. This is only so we can identify devices using a problematic HS (like matrix.org under heavy load).
This commit is contained in:
committed by
Jorge Martin Espinosa
parent
367bbc7e4b
commit
18482a99e3
@@ -14,10 +14,13 @@ import com.bumble.appyx.core.state.SavedStateMap
|
||||
import dev.zacsweers.metro.AppScope
|
||||
import dev.zacsweers.metro.ContributesBinding
|
||||
import dev.zacsweers.metro.SingleIn
|
||||
import io.element.android.libraries.androidutils.hash.hash
|
||||
import io.element.android.libraries.matrix.api.MatrixClient
|
||||
import io.element.android.libraries.matrix.api.MatrixClientProvider
|
||||
import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService
|
||||
import io.element.android.libraries.matrix.api.core.SessionId
|
||||
import io.element.android.services.analytics.api.AnalyticsService
|
||||
import io.element.android.services.analyticsproviders.api.AnalyticsUserData
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
@@ -36,6 +39,7 @@ private const val SAVE_INSTANCE_KEY = "io.element.android.x.di.MatrixClientsHold
|
||||
class MatrixSessionCache(
|
||||
private val authenticationService: MatrixAuthenticationService,
|
||||
private val syncOrchestratorFactory: SyncOrchestrator.Factory,
|
||||
private val analyticsService: AnalyticsService,
|
||||
) : MatrixClientProvider {
|
||||
private val sessionIdsToMatrixSession = ConcurrentHashMap<SessionId, InMemoryMatrixSession>()
|
||||
private val restoreMutex = Mutex()
|
||||
@@ -100,6 +104,11 @@ class MatrixSessionCache(
|
||||
Timber.d("Restore matrix session: $sessionId")
|
||||
return authenticationService.restoreSession(sessionId)
|
||||
.onSuccess { matrixClient ->
|
||||
// Add the current homeserver (hashed) to the extra info
|
||||
// This may not play well with multiple sessions, but it should work for now
|
||||
analyticsService.addUserData(AnalyticsUserData.HOMESERVER, matrixClient.userIdServerName().hash())
|
||||
|
||||
// Add the new client to the in-memory cache
|
||||
onNewMatrixClient(matrixClient)
|
||||
}
|
||||
.onFailure {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* 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 AnalyticsUserData {
|
||||
const val HOMESERVER = "homeserver"
|
||||
|
||||
const val STATE_STORE_SIZE = "state_store_size"
|
||||
const val EVENT_CACHE_SIZE = "event_cache_size"
|
||||
const val CRYPTO_STORE_SIZE = "crypto_store_size"
|
||||
const val MEDIA_STORE_SIZE = "media_store_size"
|
||||
}
|
||||
Reference in New Issue
Block a user