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

Added FXIOS-7559 [v121] health metrics telemetry (backport #17844) #17864

Merged
merged 2 commits into from
Jan 1, 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
11 changes: 9 additions & 2 deletions Client/Application/AppLaunchUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AppLaunchUtil {
}

TelemetryWrapper.shared.setup(profile: profile)
recordUserPrefsTelemetry()
recordStartUpTelemetry()

// Need to get "settings.sendUsageData" this way so that Sentry can be initialized before getting the Profile.
let sendUsageData = NSUserDefaultsPrefs(prefix: "profile").boolForKey(AppConstants.prefSendUsageData) ?? true
Expand Down Expand Up @@ -191,12 +191,19 @@ class AppLaunchUtil {
}
}

private func recordUserPrefsTelemetry() {
private func recordStartUpTelemetry() {
let isEnabled: Bool = (profile.prefs.boolForKey(PrefsKeys.UserFeatureFlagPrefs.SponsoredShortcuts) ?? true) &&
(profile.prefs.boolForKey(PrefsKeys.UserFeatureFlagPrefs.TopSiteSection) ?? true)
TelemetryWrapper.recordEvent(category: .information,
method: .view,
object: .sponsoredShortcuts,
extras: [TelemetryWrapper.EventExtraKey.preference.rawValue: isEnabled])

if logger.crashedLastLaunch {
TelemetryWrapper.recordEvent(category: .information,
method: .error,
object: .app,
value: .crashedLastLaunch)
}
}
}
26 changes: 26 additions & 0 deletions Client/Telemetry/MetricKit/MetricKitWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class MetricKitWrapper: NSObject, MXMetricManagerSubscriber {
payload.diskWriteExceptionDiagnostics?.forEach({ exception in
self.handleDiskWriteException(exception)
})
payload.cpuExceptionDiagnostics?.forEach({ exception in
self.handleCPUException(exception)
})
payload.hangDiagnostics?.forEach({ exception in
self.handleHangException(exception)
})
}
}

Expand All @@ -37,4 +43,24 @@ class MetricKitWrapper: NSObject, MXMetricManagerSubscriber {
value: .largeFileWrite,
extras: eventExtra)
}

private func handleCPUException(_ exception: MXCPUExceptionDiagnostic) {
let size = Int32(measurementFormatter.string(from: exception.totalCPUTime)) ?? -1
let eventExtra = [TelemetryWrapper.EventExtraKey.size.rawValue: size]
telemetryWrapper.recordEvent(category: .information,
method: .error,
object: .app,
value: .cpuException,
extras: eventExtra)
}

private func handleHangException(_ exception: MXHangDiagnostic) {
let size = Int32(measurementFormatter.string(from: exception.hangDuration)) ?? -1
let eventExtra = [TelemetryWrapper.EventExtraKey.size.rawValue: size]
telemetryWrapper.recordEvent(category: .information,
method: .error,
object: .app,
value: .hangException,
extras: eventExtra)
}
}
15 changes: 15 additions & 0 deletions Client/Telemetry/TelemetryWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ extension TelemetryWrapper {
case shoppingCFRsDisplayed = "shopping-cfrs-displayed"
case awesomebarShareTap = "awesomebar-share-tap"
case largeFileWrite = "large-file-write"
case crashedLastLaunch = "crashed_last_launch"
case cpuException = "cpu_exception"
case hangException = "hang-exception"
}

public enum EventExtraKey: String, CustomStringConvertible {
Expand Down Expand Up @@ -1807,6 +1810,18 @@ extension TelemetryWrapper {
let properties = GleanMetrics.AppErrors.LargeFileWriteExtra(size: quantity)
GleanMetrics.AppErrors.largeFileWrite.record(properties)
}
case(.information, .error, .app, .crashedLastLaunch, _):
GleanMetrics.AppErrors.crashedLastLaunch.record()
case(.information, .error, .app, .cpuException, let extras):
if let quantity = extras?[EventExtraKey.size.rawValue] as? Int32 {
let properties = GleanMetrics.AppErrors.CpuExceptionExtra(size: quantity)
GleanMetrics.AppErrors.cpuException.record(properties)
}
case(.information, .error, .app, .hangException, let extras):
if let quantity = extras?[EventExtraKey.size.rawValue] as? Int32 {
let properties = GleanMetrics.AppErrors.HangExceptionExtra(size: quantity)
GleanMetrics.AppErrors.hangException.record(properties)
}
default:
recordUninstrumentedMetrics(category: category, method: method, object: object, value: value, extras: extras)
}
Expand Down
43 changes: 43 additions & 0 deletions Client/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4689,3 +4689,46 @@ app_errors:
notification_emails:
- [email protected]
expires: never
crashed_last_launch:
type: event
description: |
Recorded when the previous session ended as a result of a crash
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/16827
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/17844
notification_emails:
- [email protected]
expires: never
cpu_exception:
type: event
description: |
Recorded when a cpu exception is triggered
extra_keys:
size:
description: |
Total CPU time consumed in the scope of the exception
type: quantity
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/16828
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/17844
notification_emails:
- [email protected]
expires: never
hang_exception:
type: event
description: |
Recorded when the main thread hangs
extra_keys:
size:
description: |
Total time the main thread was blocked
type: quantity
bugs:
- https://github.com/mozilla-mobile/firefox-ios/issues/16829
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/17844
notification_emails:
- [email protected]
expires: never
32 changes: 32 additions & 0 deletions firefox-ios/Tests/ClientTests/TelemetryWrapperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,38 @@ class TelemetryWrapperTests: XCTestCase {

testEventMetricRecordingSuccess(metric: GleanMetrics.AppErrors.largeFileWrite)
}

func test_error_crashedLastLaunchIsCalled() {
TelemetryWrapper.recordEvent(category: .information,
method: .error,
object: .app,
value: .crashedLastLaunch)

testEventMetricRecordingSuccess(metric: GleanMetrics.AppErrors.crashedLastLaunch)
}

func test_error_cpuExceptionIsCalled() {
let eventExtra = [TelemetryWrapper.EventExtraKey.size.rawValue: Int32(1000)]
TelemetryWrapper.recordEvent(category: .information,
method: .error,
object: .app,
value: .cpuException,
extras: eventExtra)

testEventMetricRecordingSuccess(metric: GleanMetrics.AppErrors.cpuException)
}

func test_error_hangExceptionIsCalled() {
let eventExtra = [TelemetryWrapper.EventExtraKey.size.rawValue: Int32(1000)]
TelemetryWrapper.recordEvent(category: .information,
method: .error,
object: .app,
value: .hangException,
extras: eventExtra)

testEventMetricRecordingSuccess(metric: GleanMetrics.AppErrors.hangException)
}

// MARK: - RecordSearch
func test_RecordSearch_GleanIsCalledSearchSuggestion() {
let extras = [TelemetryWrapper.EventExtraKey.recordSearchLocation.rawValue: "suggestion",
Expand Down