From 9448fcafc5c941f0ec734dfab0d9db393c55d581 Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Mon, 2 Mar 2020 15:04:33 +0000 Subject: [PATCH] Bug 1617133 - Report error names to Telemetry on Nightly r=glasserc Differential Revision: https://phabricator.services.mozilla.com/D64560 --HG-- extra : moz-landing-system : lando --- services/settings/RemoteSettingsClient.jsm | 32 ++++++++++++++++-- .../test/unit/test_remote_settings.js | 33 +++++++++++++++++++ toolkit/components/telemetry/Events.yaml | 2 ++ 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/services/settings/RemoteSettingsClient.jsm b/services/settings/RemoteSettingsClient.jsm index ad35b2fa5d5e..21561763d588 100644 --- a/services/settings/RemoteSettingsClient.jsm +++ b/services/settings/RemoteSettingsClient.jsm @@ -6,6 +6,9 @@ var EXPORTED_SYMBOLS = ["RemoteSettingsClient"]; +const { AppConstants } = ChromeUtils.import( + "resource://gre/modules/AppConstants.jsm" +); const { XPCOMUtils } = ChromeUtils.import( "resource://gre/modules/XPCOMUtils.jsm" ); @@ -429,6 +432,7 @@ class RemoteSettingsClient extends EventEmitter { let importedFromDump = []; const startedAt = new Date(); let reportStatus = null; + let thrownError = null; try { // If network is offline, we can't synchronize. if (Utils.isOffline) { @@ -626,6 +630,7 @@ class RemoteSettingsClient extends EventEmitter { ); } } catch (e) { + thrownError = e; // If no Telemetry status was determined yet (ie. outside sync step), // then introspect error, default status at this step is UNKNOWN. if (reportStatus == null) { @@ -641,11 +646,34 @@ class RemoteSettingsClient extends EventEmitter { reportStatus = UptakeTelemetry.STATUS.SUCCESS; } // Report success/error status to Telemetry. - await UptakeTelemetry.report(TELEMETRY_COMPONENT, reportStatus, { + let reportArgs = { source: this.identifier, trigger, duration: durationMilliseconds, - }); + }; + // In Bug 1617133, we will try to break down specific errors into + // more precise statuses by reporting the JavaScript error name + // ("TypeError", etc.) to Telemetry on Nightly. + if ( + thrownError !== null && + AppConstants.NIGHTLY_BUILD && + [ + UptakeTelemetry.STATUS.SYNC_ERROR, + UptakeTelemetry.STATUS.CUSTOM_1_ERROR, // IndexedDB. + UptakeTelemetry.STATUS.UNKNOWN_ERROR, + ].includes(reportStatus) + ) { + // List of possible error names for IndexedDB: + // https://searchfox.org/mozilla-central/rev/49ed791/dom/base/DOMException.cpp#28-53 + reportArgs = { ...reportArgs, errorName: thrownError.name }; + } + + await UptakeTelemetry.report( + TELEMETRY_COMPONENT, + reportStatus, + reportArgs + ); + console.debug(`${this.identifier} sync status is ${reportStatus}`); this._syncRunning = false; } diff --git a/services/settings/test/unit/test_remote_settings.js b/services/settings/test/unit/test_remote_settings.js index 849e88b81079..8b0a989942c7 100644 --- a/services/settings/test/unit/test_remote_settings.js +++ b/services/settings/test/unit/test_remote_settings.js @@ -729,6 +729,39 @@ add_task(async function test_telemetry_reports_indexeddb_as_custom_1() { }); add_task(clear_state); +add_task(async function test_telemetry_reports_error_name_as_event_nightly() { + const backup = client.openCollection; + client.openCollection = () => { + const e = new Error("Some unknown error"); + e.name = "ThrownError"; + throw e; + }; + + await withFakeChannel("nightly", async () => { + try { + await client.maybeSync(2000); + } catch (e) {} + + TelemetryTestUtils.assertEvents([ + [ + "uptake.remotecontent.result", + "uptake", + "remotesettings", + UptakeTelemetry.STATUS.UNKNOWN_ERROR, + { + source: client.identifier, + trigger: "manual", + duration: v => v >= 0, + errorName: "ThrownError", + }, + ], + ]); + }); + + client.openCollection = backup; +}); +add_task(clear_state); + add_task(async function test_bucketname_changes_when_bucket_pref_changes() { equal(client.bucketName, "main"); diff --git a/toolkit/components/telemetry/Events.yaml b/toolkit/components/telemetry/Events.yaml index b1a2227919f0..c0e80015a6c9 100644 --- a/toolkit/components/telemetry/Events.yaml +++ b/toolkit/components/telemetry/Events.yaml @@ -1692,6 +1692,8 @@ uptake.remotecontent.result: The duration of the synchronization process in milliseconds. timestamp: > The current timestamp, received during synchronization. + errorName: > + An optional string with the error name attribute in case of failure. bug_numbers: - 1517469 products: