Skip to content

Commit

Permalink
feat(posthog): wire support for extra utd error properties
Browse files Browse the repository at this point in the history
  • Loading branch information
BillCarsonFr authored and stefanceriu committed Dec 13, 2024
1 parent 92ca7b5 commit 40714f3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
36 changes: 19 additions & 17 deletions ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Please see LICENSE in the repository root for full details.
//

import AnalyticsEvents
import AVKit
import Combine
import MatrixRustSDK
Expand Down Expand Up @@ -382,24 +383,25 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
timeToDecryptMs = -1
}

switch info.cause {
case .unknown:
analytics.trackError(context: nil, domain: .E2EE, name: .OlmKeysNotSentError, timeToDecryptMillis: timeToDecryptMs)
case .unknownDevice:
analytics.trackError(context: nil, domain: .E2EE, name: .ExpectedSentByInsecureDevice, timeToDecryptMillis: timeToDecryptMs)
case .unsignedDevice:
analytics.trackError(context: nil, domain: .E2EE, name: .ExpectedSentByInsecureDevice, timeToDecryptMillis: timeToDecryptMs)
case .verificationViolation:
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)
let errorName: AnalyticsEvent.Error.Name = switch info.cause {
case .unknown: .OlmKeysNotSentError
case .unknownDevice, .unsignedDevice: .ExpectedSentByInsecureDevice
case .verificationViolation: .ExpectedVerificationViolation
case .sentBeforeWeJoined: .ExpectedDueToMembership
case .historicalMessage: .HistoricalMessage
case .withheldForUnverifiedOrInsecureDevice: .RoomKeysWithheldForUnverifiedDevice
case .withheldBySender: .OlmKeysNotSentError
}

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)

Expand Down
19 changes: 13 additions & 6 deletions ElementX/Sources/Services/Analytics/AnalyticsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,26 @@ extension AnalyticsService {
/// - 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.
/// 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
capture(event: AnalyticsEvent.Error(context: context,
cryptoModule: .Rust,
cryptoSDK: .Rust,
domain: domain,
eventLocalAgeMillis: nil,
isFederated: nil,
isMatrixDotOrg: nil,
eventLocalAgeMillis: eventLocalAgeMillis,
isFederated: isFederated,
isMatrixDotOrg: isMatrixDotOrg,
name: name,
timeToDecryptMillis: timeToDecryptMillis,
userTrustsOwnIdentity: nil,
wasVisibleToUser: nil))
userTrustsOwnIdentity: userTrustsOwnIdentity,
wasVisibleToUser: wasVisibleToUser))
}

/// Track the creation of a room
Expand Down

0 comments on commit 40714f3

Please sign in to comment.