Skip to content

Commit

Permalink
feat: Log migration
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeWeidmann committed Jan 17, 2024
1 parent 73749da commit 3f0ba54
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions MailCore/Cache/AccountManager/AccountManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public final class AccountManager: RefreshTokenDelegate, ObservableObject {
}

public func didUpdateToken(newToken: ApiToken, oldToken: ApiToken) {
SentryDebug.logTokenMigration(newToken: newToken, oldToken: oldToken)
tokenStore.addToken(newToken: newToken)
}

Expand Down
20 changes: 20 additions & 0 deletions MailCore/Utils/SentryDebug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import Foundation
import InfomaniakLogin
import RealmSwift
import Sentry

Expand Down Expand Up @@ -191,6 +192,25 @@ public enum SentryDebug {
}
}

static func logTokenMigration(newToken: ApiToken, oldToken: ApiToken) {
let newTokenIsInfinite = newToken.expirationDate == nil
let oldTokenIsInfinite = oldToken.expirationDate == nil

let additionalData = ["newTokenIsInfinite": newTokenIsInfinite, "oldTokenIsInfinite": oldTokenIsInfinite]
let breadcrumb = Breadcrumb(level: .info, category: "Token")
breadcrumb.message = "Token updated"
breadcrumb.data = additionalData
SentrySDK.addBreadcrumb(breadcrumb)

// Only track migration
guard newTokenIsInfinite else { return }

SentrySDK.capture(message: "Update token infinite token") { scope in
scope.setContext(value: additionalData,
key: "Migration context")
}
}

static func addBackoffBreadcrumb(folder: Folder, index: Int) {
let breadcrumb = Breadcrumb()
breadcrumb.message = "Backoff \(index) for folder \(folder.name) - \(folder.remoteId)"
Expand Down

0 comments on commit 3f0ba54

Please sign in to comment.