feat(posthog): wire support for extra utd error properties

This commit is contained in:
Valere
2024-12-12 18:50:54 +01:00
committed by Stefan Ceriu
parent 92ca7b5f3c
commit 40714f32fd
2 changed files with 32 additions and 23 deletions
@@ -5,6 +5,7 @@
// Please see LICENSE in the repository root for full details. // Please see LICENSE in the repository root for full details.
// //
import AnalyticsEvents
import AVKit import AVKit
import Combine import Combine
import MatrixRustSDK import MatrixRustSDK
@@ -382,24 +383,25 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
timeToDecryptMs = -1 timeToDecryptMs = -1
} }
switch info.cause { let errorName: AnalyticsEvent.Error.Name = switch info.cause {
case .unknown: case .unknown: .OlmKeysNotSentError
analytics.trackError(context: nil, domain: .E2EE, name: .OlmKeysNotSentError, timeToDecryptMillis: timeToDecryptMs) case .unknownDevice, .unsignedDevice: .ExpectedSentByInsecureDevice
case .unknownDevice: case .verificationViolation: .ExpectedVerificationViolation
analytics.trackError(context: nil, domain: .E2EE, name: .ExpectedSentByInsecureDevice, timeToDecryptMillis: timeToDecryptMs) case .sentBeforeWeJoined: .ExpectedDueToMembership
case .unsignedDevice: case .historicalMessage: .HistoricalMessage
analytics.trackError(context: nil, domain: .E2EE, name: .ExpectedSentByInsecureDevice, timeToDecryptMillis: timeToDecryptMs) case .withheldForUnverifiedOrInsecureDevice: .RoomKeysWithheldForUnverifiedDevice
case .verificationViolation: case .withheldBySender: .OlmKeysNotSentError
analytics.trackError(context: nil, domain: .E2EE, name: .ExpectedVerificationViolation, timeToDecryptMillis: timeToDecryptMs)
case .sentBeforeWeJoined:
analytics.trackError(context: nil, domain: .E2EE, name: .ExpectedDueToMembership, timeToDecryptMillis: timeToDecryptMs)
case .historicalMessage:
analytics.trackError(context: nil, domain: .E2EE, name: .HistoricalMessage, timeToDecryptMillis: timeToDecryptMs)
case .withheldForUnverifiedOrInsecureDevice:
analytics.trackError(context: nil, domain: .E2EE, name: .RoomKeysWithheldForUnverifiedDevice, timeToDecryptMillis: timeToDecryptMs)
case .withheldBySender:
analytics.trackError(context: nil, domain: .E2EE, name: .OlmKeysNotSentError, timeToDecryptMillis: timeToDecryptMs)
} }
analytics.trackError(context: nil,
domain: .E2EE,
name: errorName,
timeToDecryptMillis: timeToDecryptMs,
eventLocalAgeMillis: Int(truncatingIfNeeded: info.eventLocalAgeMillis),
isFederated: info.ownHomeserver != info.senderHomeserver,
isMatrixDotOrg: info.ownHomeserver == "matrix.org",
userTrustsOwnIdentity: info.userTrustsOwnIdentity,
wasVisibleToUser: nil)
} }
.store(in: &cancellables) .store(in: &cancellables)
@@ -122,19 +122,26 @@ extension AnalyticsService {
/// - Parameter name: The name of the error /// - Parameter name: The name of the error
/// - Parameter timeToDecryptMillis: The time it took to decrypt the event in milliseconds, needs to be used only to track UTD errors, otherwise if the error is nort related to UTD it should be nil. /// - Parameter timeToDecryptMillis: The time it took to decrypt the event in milliseconds, needs to be used only to track UTD errors, otherwise if the error is nort related to UTD it should be nil.
/// Can be found in `UnableToDecryptInfo`. In case the `UnableToDecryptInfo` contains the value as nil, pass it as `-1` /// Can be found in `UnableToDecryptInfo`. In case the `UnableToDecryptInfo` contains the value as nil, pass it as `-1`
func trackError(context: String?, domain: AnalyticsEvent.Error.Domain, name: AnalyticsEvent.Error.Name, timeToDecryptMillis: Int? = nil) { func trackError(context: String?, domain: AnalyticsEvent.Error.Domain,
name: AnalyticsEvent.Error.Name,
timeToDecryptMillis: Int? = nil,
eventLocalAgeMillis: Int? = nil,
isFederated: Bool? = nil,
isMatrixDotOrg: Bool? = nil,
userTrustsOwnIdentity: Bool? = nil,
wasVisibleToUser: Bool? = nil) {
// CryptoModule is deprecated // CryptoModule is deprecated
capture(event: AnalyticsEvent.Error(context: context, capture(event: AnalyticsEvent.Error(context: context,
cryptoModule: .Rust, cryptoModule: .Rust,
cryptoSDK: .Rust, cryptoSDK: .Rust,
domain: domain, domain: domain,
eventLocalAgeMillis: nil, eventLocalAgeMillis: eventLocalAgeMillis,
isFederated: nil, isFederated: isFederated,
isMatrixDotOrg: nil, isMatrixDotOrg: isMatrixDotOrg,
name: name, name: name,
timeToDecryptMillis: timeToDecryptMillis, timeToDecryptMillis: timeToDecryptMillis,
userTrustsOwnIdentity: nil, userTrustsOwnIdentity: userTrustsOwnIdentity,
wasVisibleToUser: nil)) wasVisibleToUser: wasVisibleToUser))
} }
/// Track the creation of a room /// Track the creation of a room