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

Refactor FXIOS-10711 Log event for tab loss bugs (backport #24328) #24370

Open
wants to merge 1 commit into
base: release/v135
Choose a base branch
from
Open
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
12 changes: 9 additions & 3 deletions firefox-ios/Client/Telemetry/TabErrorTelemetryHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ final class TabErrorTelemetryHelper {
private let telemetryWrapper: TelemetryWrapperProtocol
private let defaults: UserDefaultsInterface
private let windowManager: WindowManager
private let logger: Logger

private init(telemetryWrapper: TelemetryWrapperProtocol = TelemetryWrapper.shared,
private init(logger: Logger = DefaultLogger.shared,
telemetryWrapper: TelemetryWrapperProtocol = TelemetryWrapper.shared,
windowManager: WindowManager = AppContainer.shared.resolve(),
defaults: UserDefaultsInterface = UserDefaults.standard) {
self.telemetryWrapper = telemetryWrapper
self.defaults = defaults
self.windowManager = windowManager
self.logger = logger
}

// MARK: - Public API
Expand Down Expand Up @@ -55,7 +58,7 @@ final class TabErrorTelemetryHelper {

if expectedTabCount > 1 && (expectedTabCount - currentTabCount) > 1 {
// Potential tab loss bug detected. Log a MetricKit error.
sendTelemetryTabLossDetectedEvent()
sendTelemetryTabLossDetectedEvent(expected: expectedTabCount, actual: currentTabCount)
}

// After validating the tab count, we make sure to remove the count
Expand Down Expand Up @@ -86,7 +89,10 @@ final class TabErrorTelemetryHelper {
return windowManager.tabManager(for: window).normalTabs.count
}

private func sendTelemetryTabLossDetectedEvent() {
private func sendTelemetryTabLossDetectedEvent(expected: Int, actual: Int) {
logger.log("Tab loss detected. Expected: \(expected). Actual: \(actual). Windows: \(windowManager.windows.count)",
level: .fatal,
category: .tabs)
telemetryWrapper.recordEvent(category: .information,
method: .error,
object: .app,
Expand Down