Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send UTD occurences to Posthog #2575

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7080,7 +7080,7 @@
repositoryURL = "https://github.com/matrix-org/matrix-rust-components-swift";
requirement = {
kind = exactVersion;
version = 1.1.49;
version = 1.1.50;
};
};
821C67C9A7F8CC3FD41B28B4 /* XCRemoteSwiftPackageReference "emojibase-bindings" */ = {
Expand Down Expand Up @@ -7128,7 +7128,7 @@
repositoryURL = "https://github.com/matrix-org/matrix-analytics-events";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 0.13.0;
minimumVersion = 0.14.0;
};
};
C13F55E4518415CB4C278E73 /* XCRemoteSwiftPackageReference "DTCoreText" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-analytics-events",
"state" : {
"revision" : "ccc4af6aa00987abe7135fa0b7cea97c8cfb3d26",
"version" : "0.13.0"
"revision" : "f756bf0756b7349a1d3ccee0d038790d1ab2ec56",
"version" : "0.14.0"
}
},
{
"identity" : "matrix-rust-components-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-rust-components-swift",
"state" : {
"revision" : "0361eac2610f0007f2a6880a88c750a1bbb405b9",
"version" : "1.1.49"
"revision" : "e6b350d257aeb7395e003c3d0c26ae65c2e2e349",
"version" : "1.1.50"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,24 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
}
}
.store(in: &cancellables)

userSession.clientProxy.actionsPublisher
.receive(on: DispatchQueue.main)
.sink { action in
guard case let .receivedDecryptionError(info) = action else {
return
}

let timeToDecryptMs: Int
if let unsignedTimeToDecryptMs = info.timeToDecryptMs {
timeToDecryptMs = Int(unsignedTimeToDecryptMs)
} else {
timeToDecryptMs = -1
}

analytics.trackError(context: nil, domain: .E2EE, name: .OlmKeysNotSentError, timeToDecryptMillis: timeToDecryptMs)
}
.store(in: &cancellables)
}

func start() {
Expand Down
13 changes: 12 additions & 1 deletion ElementX/Sources/Services/Analytics/AnalyticsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,18 @@ extension AnalyticsService {
func trackInteraction(index: Int? = nil, name: AnalyticsEvent.Interaction.Name) {
capture(event: AnalyticsEvent.Interaction(index: index, interactionType: .Touch, name: name))
}


/// Track the presentation of a screen
/// - Parameter context: To provide additional context or description for the error
/// - Parameter domain: The domain to which the error belongs to.
/// - 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) {
// CryptoModule is deprecated
capture(event: AnalyticsEvent.Error(context: context, cryptoModule: nil, cryptoSDK: .Rust, domain: domain, name: name, timeToDecryptMillis: timeToDecryptMillis))
}

/// Track the creation of a room
/// - Parameter isDM: true if the created room is a direct message, false otherwise
func trackCreatedRoom(isDM: Bool) {
Expand Down
13 changes: 13 additions & 0 deletions ElementX/Sources/Services/Client/ClientProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ class ClientProxy: ClientProxyProtocol {
let syncService = try await client
.syncService()
.withCrossProcessLock(appIdentifier: "MainApp")
.withUtdHook(delegate: ClientDecryptionErrorDelegate(actionsSubject: actionsSubject))
.finish()
let roomListService = syncService.roomListService()

Expand Down Expand Up @@ -803,6 +804,18 @@ private class ClientDelegateWrapper: ClientDelegate {
}
}

private class ClientDecryptionErrorDelegate: UnableToDecryptDelegate {
private let actionsSubject: PassthroughSubject<ClientProxyAction, Never>

init(actionsSubject: PassthroughSubject<ClientProxyAction, Never>) {
self.actionsSubject = actionsSubject
}

func onUtd(info: UnableToDecryptInfo) {
actionsSubject.send(.receivedDecryptionError(info))
}
}

private class IgnoredUsersListenerProxy: IgnoredUsersListener {
private let onUpdateClosure: ([String]) -> Void

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import MatrixRustSDK
enum ClientProxyAction {
case receivedSyncUpdate
case receivedAuthError(isSoftLogout: Bool)
case receivedDecryptionError(UnableToDecryptInfo)

var isSyncUpdate: Bool {
if case .receivedSyncUpdate = self {
Expand Down
6 changes: 3 additions & 3 deletions UnitTests/Sources/LoggingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ class LoggingTests: XCTestCase {
formatted: FormattedBody(format: .html, body: "<b>\(emoteString)</b>"))

let pointer = Unmanaged.passRetained(NSURL(fileURLWithPath: "/tmp/file")).toOpaque()
let rustImageMessage = ImageMessageContent(body: "ImageString", source: MediaSource(unsafeFromRawPointer: pointer), info: nil)
let rustVideoMessage = VideoMessageContent(body: "VideoString", source: MediaSource(unsafeFromRawPointer: pointer), info: nil)
let rustFileMessage = FileMessageContent(body: "FileString", filename: "FileName", source: MediaSource(unsafeFromRawPointer: pointer), info: nil)
let rustImageMessage = ImageMessageContent(body: "ImageString", formatted: nil, filename: nil, source: MediaSource(unsafeFromRawPointer: pointer), info: nil)
let rustVideoMessage = VideoMessageContent(body: "VideoString", formatted: nil, filename: nil, source: MediaSource(unsafeFromRawPointer: pointer), info: nil)
let rustFileMessage = FileMessageContent(body: "FileString", formatted: nil, filename: "FileName", source: MediaSource(unsafeFromRawPointer: pointer), info: nil)

// When logging that value
MXLog.info(rustTextMessage)
Expand Down
4 changes: 2 additions & 2 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ packages:
# Element/Matrix dependencies
MatrixRustSDK:
url: https://github.com/matrix-org/matrix-rust-components-swift
exactVersion: 1.1.49
exactVersion: 1.1.50
# path: ../matrix-rust-sdk
Compound:
url: https://github.com/element-hq/compound-ios
revision: 19bc4c5cf9c69b7b7aeb9ac8c937c2c81a83e8b1
# path: ../compound-ios
AnalyticsEvents:
url: https://github.com/matrix-org/matrix-analytics-events
minorVersion: 0.13.0
minorVersion: 0.14.0
# path: ../matrix-analytics-events
Emojibase:
url: https://github.com/matrix-org/emojibase-bindings
Expand Down
Loading