Bug 1456984 - Instrument inspection of shortcut combination used for toolbox opening with event telemetry r=yulia
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Wed, 23 May 2018 13:14:25 +0100
changeset 801205 10244430b1013f34609078289e88ae6558ae6778
parent 801204 e29c63f108aaeb3898e4acb0ff51b2dec2593d0c
child 801206 d2e3e0b253d2ea32bedebd41944e99d81c6cd370
push id111603
push usermozilla@kaply.com
push dateTue, 29 May 2018 22:12:07 +0000
reviewersyulia
bugs1456984
milestone62.0a1
Bug 1456984 - Instrument inspection of shortcut combination used for toolbox opening with event telemetry r=yulia MozReview-Commit-ID: HA6Tasq2iZu
devtools/client/framework/toolbox.js
devtools/startup/devtools-startup.js
toolkit/components/telemetry/Events.yaml
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -711,23 +711,21 @@ Toolbox.prototype = {
 
   _pingTelemetry: function() {
     this.telemetry.toolOpened("toolbox");
 
     this.telemetry.getHistogramById(HOST_HISTOGRAM).add(this._getTelemetryHostId());
 
     // Log current theme. The question we want to answer is:
     // "What proportion of users use which themes?"
-    let currentTheme = Services.prefs.getCharPref("devtools.theme");
+    const currentTheme = Services.prefs.getCharPref("devtools.theme");
     this.telemetry.keyedScalarAdd(CURRENT_THEME_SCALAR, currentTheme, 1);
 
-    this.telemetry.preparePendingEvent(
-      "devtools.main", "open", "tools", null,
-      ["entrypoint", "first_panel", "host", "splitconsole", "width"]
-    );
+    this.telemetry.preparePendingEvent("devtools.main", "open", "tools", null,
+      ["entrypoint", "first_panel", "host", "shortcut", "splitconsole", "width"]);
     this.telemetry.addEventProperty(
       "devtools.main", "open", "tools", null, "host", this._getTelemetryHostString()
     );
   },
 
   /**
    * Create a simple object to store the state of a toolbox button. The checked state of
    * a button can be updated arbitrarily outside of the scope of the toolbar and its
--- a/devtools/startup/devtools-startup.js
+++ b/devtools/startup/devtools-startup.js
@@ -586,17 +586,17 @@ DevToolsStartup.prototype = {
     if (!Services.prefs.getBoolPref(DEVTOOLS_ENABLED_PREF)) {
       let id = key.toolId || key.id;
       this.openInstallPage("KeyShortcut", id);
     } else {
       // Record the timing at which this event started in order to compute later in
       // gDevTools.showToolbox, the complete time it takes to open the toolbox.
       // i.e. especially take `initDevTools` into account.
       let startTime = Cu.now();
-      let require = this.initDevTools("KeyShortcut");
+      let require = this.initDevTools("KeyShortcut", key);
       let { gDevToolsBrowser } = require("devtools/client/framework/devtools-browser");
       gDevToolsBrowser.onKeyShortcut(window, key, startTime);
     }
   },
 
   // Create a <xul:key> DOM Element
   createKey(doc, { id, toolId, shortcut, modifiers: mod }, oncommand) {
     let k = doc.createElement("key");
@@ -614,24 +614,24 @@ DevToolsStartup.prototype = {
 
     // Bug 371900: command event is fired only if "oncommand" attribute is set.
     k.setAttribute("oncommand", ";");
     k.addEventListener("command", oncommand);
 
     return k;
   },
 
-  initDevTools: function(reason) {
+  initDevTools: function(reason, key = "") {
     // If an entry point is fired and tools are not enabled open the installation page
     if (!Services.prefs.getBoolPref(DEVTOOLS_ENABLED_PREF)) {
       this.openInstallPage(reason);
       return null;
     }
 
-    this.sendEntryPointTelemetry(reason);
+    this.sendEntryPointTelemetry(reason, key);
 
     this.initialized = true;
     let { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
     // Ensure loading main devtools module that hooks up into browser UI
     // and initialize all devtools machinery.
     require("devtools/client/framework/devtools-browser");
     return require;
   },
@@ -834,21 +834,39 @@ DevToolsStartup.prototype = {
       dump("Unable to start debugger server on " + portOrPath + ": " + e);
     }
 
     if (cmdLine.state == Ci.nsICommandLine.STATE_REMOTE_AUTO) {
       cmdLine.preventDefault = true;
     }
   },
 
-  sendEntryPointTelemetry(reason) {
+  sendEntryPointTelemetry(reason, key = "") {
     if (!reason) {
       return;
     }
 
+    let keys = "";
+
+    if (reason === "KeyShortcut") {
+      let { modifiers, shortcut } = key;
+
+      modifiers = modifiers.replace(",", "+");
+
+      if (shortcut.startsWith("VK_")) {
+        shortcut = shortcut.substr(3);
+      }
+
+      keys = `${modifiers}+${shortcut}`;
+    }
+
+    this.telemetry.addEventProperty(
+      "devtools.main", "open", "tools", null, "shortcut", keys
+    );
+
     this.telemetry.addEventProperty(
       "devtools.main", "open", "tools", null, "entrypoint", reason
     );
 
     if (this.recorded) {
       return;
     }
 
--- a/toolkit/components/telemetry/Events.yaml
+++ b/toolkit/components/telemetry/Events.yaml
@@ -191,28 +191,29 @@ telemetry.test.second:
     description: This is a test entry for Telemetry.
     expiry_version: never
     extra_keys:
       key1: This is just a test description.
 
 devtools.main:
   open:
     objects: ["tools"]
-    bug_numbers: [1416024]
+    bug_numbers: [1416024, 1456984]
     notification_emails: ["dev-developer-tools@lists.mozilla.org", "hkirschner@mozilla.com"]
     record_in_processes: ["main"]
     description: User opens devtools toolbox.
     release_channel_collection: opt-out
     expiry_version: never
     extra_keys:
       entrypoint: How was the toolbox opened? CommandLine, ContextMenu, DeveloperToolbar, HamburgerMenu, KeyShortcut, SessionRestore or SystemMenu
       first_panel: The name of the first panel opened.
       host: "Toolbox host (positioning): bottom, side, window or other."
       splitconsole: Indicates whether the split console was open.
       width: Toolbox width rounded up to the nearest 50px.
+      shortcut: The key combination pressed. Used only in the case that entrypoint === KeyShortcut.
   close:
     objects: ["tools"]
     bug_numbers: [1453312]
     notification_emails: ["dev-developer-tools@lists.mozilla.org", "hkirschner@mozilla.com"]
     record_in_processes: ["main"]
     description: User closes devtools toolbox.
     release_channel_collection: opt-out
     expiry_version: never