Skip to content

Commit

Permalink
Merge pull request #5815 from vector-im/feature/aris/crypto_improve_U…
Browse files Browse the repository at this point in the history
…ISI_exceptions

Enhance crypto posthog errors with more details
  • Loading branch information
ariskotsomitopoulos authored Apr 27, 2022
2 parents 09e8c10 + 1f9b957 commit 3d190bb
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private data class DecryptionFailure(
val failedEventId: String,
val error: MXCryptoError.ErrorType
)
private typealias DetailedErrorName = Pair<String, Error.Name>

private const val GRACE_PERIOD_MILLIS = 4_000
private const val CHECK_INTERVAL = 2_000L
Expand Down Expand Up @@ -112,7 +113,7 @@ class DecryptionFailureTracker @Inject constructor(

private fun checkFailures() {
val now = clock.epochMillis()
val aggregatedErrors: Map<Error.Name, List<String>>
val aggregatedErrors: Map<DetailedErrorName, List<String>>
synchronized(failures) {
val toReport = mutableListOf<DecryptionFailure>()
failures.removeAll { failure ->
Expand All @@ -136,20 +137,21 @@ class DecryptionFailureTracker @Inject constructor(
// for now we ignore events already reported even if displayed again?
.filter { alreadyReported.contains(it).not() }
.forEach { failedEventId ->
analyticsTracker.capture(Error(failedEventId, Error.Domain.E2EE, aggregation.key))
analyticsTracker.capture(Error(aggregation.key.first, Error.Domain.E2EE, aggregation.key.second))
alreadyReported.add(failedEventId)
}
}
}

private fun MXCryptoError.ErrorType.toAnalyticsErrorName(): Error.Name {
return when (this) {
MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID -> Error.Name.OlmKeysNotSentError
MXCryptoError.ErrorType.OLM -> {
Error.Name.OlmUnspecifiedError
}
MXCryptoError.ErrorType.UNKNOWN_MESSAGE_INDEX -> Error.Name.OlmIndexError
else -> Error.Name.UnknownError
private fun MXCryptoError.ErrorType.toAnalyticsErrorName(): DetailedErrorName {
val detailed = "$name | mxc_crypto_error_type"
val errorName = when (this) {
MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID,
MXCryptoError.ErrorType.KEYS_WITHHELD -> Error.Name.OlmKeysNotSentError
MXCryptoError.ErrorType.OLM -> Error.Name.OlmUnspecifiedError
MXCryptoError.ErrorType.UNKNOWN_MESSAGE_INDEX -> Error.Name.OlmIndexError
else -> Error.Name.UnknownError
}
return DetailedErrorName(detailed, errorName)
}
}

0 comments on commit 3d190bb

Please sign in to comment.