Bug 1463083 - Instrument inspection of inspector side panel switching with event telemetry r?yulia draft
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Thu, 24 May 2018 14:21:49 +0100
changeset 802111 50cde18b23b02f594422e89bdeda12e2806134e7
parent 802106 5c676b7331db3f8ece5961aa80347259f91a595f
child 802115 fee1f20bd9b306873a60085cf548154afc303c59
push id111821
push usermratcliffe@mozilla.com
push dateThu, 31 May 2018 11:30:56 +0000
reviewersyulia
bugs1463083
milestone62.0a1
Bug 1463083 - Instrument inspection of inspector side panel switching with event telemetry r?yulia MozReview-Commit-ID: ANPWNvYRfdH
devtools/client/inspector/toolsidebar.js
devtools/client/shared/test/browser_telemetry_sidebar.js
toolkit/components/telemetry/Events.yaml
--- a/devtools/client/inspector/toolsidebar.js
+++ b/devtools/client/inspector/toolsidebar.js
@@ -329,16 +329,23 @@ ToolSidebar.prototype = {
   updateTelemetryOnChange: function(currentToolId, previousToolId) {
     if (currentToolId === previousToolId || !this._telemetry) {
       // Skip telemetry if the tool id did not change or telemetry is unavailable.
       return;
     }
 
     if (previousToolId) {
       this._telemetry.toolClosed(previousToolId);
+
+      this._telemetry.recordEvent("devtools.main", "sidepanel_changed", "inspector", null,
+        {
+          oldpanel: previousToolId,
+          newpanel: currentToolId
+        }
+      );
     }
     this._telemetry.toolOpened(currentToolId);
   },
 
   /**
    * Show the sidebar.
    *
    * @param  {String} id
--- a/devtools/client/shared/test/browser_telemetry_sidebar.js
+++ b/devtools/client/shared/test/browser_telemetry_sidebar.js
@@ -1,30 +1,108 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 /* eslint-disable mozilla/no-arbitrary-setTimeout */
 
 "use strict";
 
 const TEST_URI = "data:text/html;charset=utf-8,<p>browser_telemetry_sidebar.js</p>";
+const OPTOUT = Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTOUT;
 
 // Because we need to gather stats for the period of time that a tool has been
 // opened we make use of setTimeout() to create tool active times.
 const TOOL_DELAY = 200;
 
+const DATA = [
+  {
+    timestamp: null,
+    category: "devtools.main",
+    method: "sidepanel_changed",
+    object: "inspector",
+    value: null,
+    extra: {
+      oldpanel: "computedview",
+      newpanel: "fontinspector"
+    }
+  },
+  {
+    timestamp: null,
+    category: "devtools.main",
+    method: "sidepanel_changed",
+    object: "inspector",
+    value: null,
+    extra: {
+      oldpanel: "fontinspector",
+      newpanel: "layoutview"
+    }
+  },
+  {
+    timestamp: null,
+    category: "devtools.main",
+    method: "sidepanel_changed",
+    object: "inspector",
+    value: null,
+    extra: {
+      oldpanel: "layoutview",
+      newpanel: "computedview"
+    }
+  },
+  {
+    timestamp: null,
+    category: "devtools.main",
+    method: "sidepanel_changed",
+    object: "inspector",
+    value: null,
+    extra: {
+      oldpanel: "computedview",
+      newpanel: "fontinspector"
+    }
+  },
+  {
+    timestamp: null,
+    category: "devtools.main",
+    method: "sidepanel_changed",
+    object: "inspector",
+    value: null,
+    extra: {
+      oldpanel: "fontinspector",
+      newpanel: "layoutview"
+    }
+  },
+  {
+    timestamp: null,
+    category: "devtools.main",
+    method: "sidepanel_changed",
+    object: "inspector",
+    value: null,
+    extra: {
+      oldpanel: "layoutview",
+      newpanel: "computedview"
+    }
+  }
+];
+
 add_task(async function() {
+  // Let's reset the counts.
+  Services.telemetry.clearEvents();
+
+  // Ensure no events have been logged
+  const snapshot = Services.telemetry.snapshotEvents(OPTOUT, true);
+  ok(!snapshot.parent, "No events have been logged for the main process");
+
   await addTab(TEST_URI);
   startTelemetry();
 
   let target = TargetFactory.forTab(gBrowser.selectedTab);
   let toolbox = await gDevTools.showToolbox(target, "inspector");
   info("inspector opened");
 
   await testSidebar(toolbox);
   checkResults();
+  checkEventTelemetry();
 
   await gDevTools.closeToolbox(target);
   gBrowser.removeCurrentTab();
 });
 
 function testSidebar(toolbox) {
   info("Testing sidebar");
 
@@ -58,8 +136,32 @@ function checkResults() {
   checkTelemetry("DEVTOOLS_RULEVIEW_OPENED_COUNT", "", [1, 0, 0], "array");
   checkTelemetry("DEVTOOLS_COMPUTEDVIEW_OPENED_COUNT", "", [3, 0, 0], "array");
   checkTelemetry("DEVTOOLS_LAYOUTVIEW_OPENED_COUNT", "", [2, 0, 0], "array");
   checkTelemetry("DEVTOOLS_FONTINSPECTOR_OPENED_COUNT", "", [2, 0, 0], "array");
   checkTelemetry("DEVTOOLS_COMPUTEDVIEW_TIME_ACTIVE_SECONDS", "", null, "hasentries");
   checkTelemetry("DEVTOOLS_LAYOUTVIEW_TIME_ACTIVE_SECONDS", "", null, "hasentries");
   checkTelemetry("DEVTOOLS_FONTINSPECTOR_TIME_ACTIVE_SECONDS", "", null, "hasentries");
 }
+
+function checkEventTelemetry() {
+  const snapshot = Services.telemetry.snapshotEvents(OPTOUT, true);
+  const events = snapshot.parent.filter(event => event[1] === "devtools.main" &&
+                                                  event[2] === "sidepanel_changed" &&
+                                                  event[3] === "inspector" &&
+                                                  event[4] === null
+  );
+
+  for (let i in DATA) {
+    const [ timestamp, category, method, object, value, extra ] = events[i];
+    const expected = DATA[i];
+
+    // ignore timestamp
+    ok(timestamp > 0, "timestamp is greater than 0");
+    is(category, expected.category, "category is correct");
+    is(method, expected.method, "method is correct");
+    is(object, expected.object, "object is correct");
+    is(value, expected.value, "value is correct");
+
+    is(extra.oldpanel, expected.extra.oldpanel, "oldpanel is correct");
+    is(extra.newpanel, expected.extra.newpanel, "newpanel is correct");
+  }
+}
--- a/toolkit/components/telemetry/Events.yaml
+++ b/toolkit/components/telemetry/Events.yaml
@@ -285,8 +285,19 @@ devtools.main:
   edit_rule:
     objects: ["ruleview"]
     bug_numbers: [1463081]
     notification_emails: ["dev-developer-tools@lists.mozilla.org", "hkirschner@mozilla.com"]
     record_in_processes: ["main"]
     description: User is editing a CSS rule by clicking on or next to a CSS property, enabling / disabling a rule or creating a new property.
     release_channel_collection: opt-out
     expiry_version: never
+  sidepanel_changed:
+    objects: ["inspector"]
+    bug_numbers: [1463083]
+    notification_emails: ["dev-developer-tools@lists.mozilla.org", "hkirschner@mozilla.com"]
+    record_in_processes: ["main"]
+    description: User has switched sidepanel tabs.
+    release_channel_collection: opt-out
+    expiry_version: never
+    extra_keys:
+      oldpanel: The panel the user is switching from
+      newpanel: The panel the user is switching to