Bug 1531395 - Add telemetry to track persist option usage in the Console panel. r=nchevobbe
authorlloan <lloanalas@outlook.com>
Tue, 16 Apr 2019 16:49:19 +0000
changeset 469712 c503fc359408
parent 469711 11ec88883d98
child 469713 cf3fbdaa46b9
push id35879
push usernerli@mozilla.com
push dateTue, 16 Apr 2019 22:01:48 +0000
treeherdermozilla-central@12a60898fdc1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnchevobbe
bugs1531395
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1531395 - Add telemetry to track persist option usage in the Console panel. r=nchevobbe Differential Revision: https://phabricator.services.mozilla.com/D26046
devtools/client/webconsole/middleware/event-telemetry.js
devtools/client/webconsole/test/mochitest/browser.ini
devtools/client/webconsole/test/mochitest/browser_webconsole_telemetry_persist_toggle_changed.js
toolkit/components/telemetry/Events.yaml
--- a/devtools/client/webconsole/middleware/event-telemetry.js
+++ b/devtools/client/webconsole/middleware/event-telemetry.js
@@ -4,16 +4,17 @@
 
 "use strict";
 
 const {
   FILTER_TEXT_SET,
   FILTER_TOGGLE,
   DEFAULT_FILTERS_RESET,
   MESSAGES_ADD,
+  PERSIST_TOGGLE,
 } = require("devtools/client/webconsole/constants");
 
 /**
  * Event telemetry middleware is responsible for logging specific events to telemetry.
  */
 function eventTelemetryMiddleware(telemetry, sessionId, store) {
   return next => action => {
     const oldState = store.getState();
@@ -35,16 +36,21 @@ function eventTelemetryMiddleware(teleme
         action,
         state,
         oldState,
         telemetry,
         sessionId,
       });
     } else if (action.type === MESSAGES_ADD) {
       messagesAdd({ action, telemetry });
+    } else if (action.type === PERSIST_TOGGLE) {
+      telemetry.recordEvent("persist_changed", "webconsole", String(state.ui.persistLogs),
+        {
+        "session_id": sessionId,
+        });
     }
 
     return res;
   };
 }
 
 function filterChange({action, state, oldState, telemetry, sessionId}) {
   const oldFilterState = oldState.filters;
--- a/devtools/client/webconsole/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/test/mochitest/browser.ini
@@ -389,16 +389,17 @@ skip-if = verify
 [browser_webconsole_split_focus.js]
 [browser_webconsole_split_persist.js]
 [browser_webconsole_stacktrace_location_debugger_link.js]
 [browser_webconsole_stacktrace_location_scratchpad_link.js]
 [browser_webconsole_strict_mode_errors.js]
 [browser_webconsole_string.js]
 [browser_webconsole_telemetry_js_errors.js]
 [browser_webconsole_telemetry_filters_changed.js]
+[browser_webconsole_telemetry_persist_toggle_changed.js]
 [browser_webconsole_telemetry_jump_to_definition.js]
 [browser_webconsole_telemetry_object_expanded.js]
 [browser_webconsole_time_methods.js]
 [browser_webconsole_timestamps.js]
 [browser_webconsole_trackingprotection_errors.js]
 tags = trackingprotection
 [browser_webconsole_view_source.js]
 [browser_webconsole_visibility_messages.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/mochitest/browser_webconsole_telemetry_persist_toggle_changed.js
@@ -0,0 +1,60 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Tests the log persistence telemetry event
+
+"use strict";
+
+const { TelemetryTestUtils } = ChromeUtils.import("resource://testing-common/TelemetryTestUtils.jsm");
+
+const TEST_URI = `data:text/html,<meta charset=utf8><script>
+  console.log("test message");
+</script>`;
+
+add_task(async function() {
+  // Let's reset the counts.
+  Services.telemetry.clearEvents();
+
+  // Ensure no events have been logged
+  TelemetryTestUtils.assertNumberOfEvents(0);
+
+  const hud = await openNewTabAndConsole(TEST_URI);
+
+  // Get log persistence toggle button
+  const logPersistToggle = await waitFor(() =>
+    hud.ui.window.document.querySelector(".filter-checkbox"));
+
+  // Click on the toggle - "true"
+  logPersistToggle.click();
+  await waitUntil(() => hud.ui.wrapper.getStore().getState().ui.persistLogs === true);
+
+  // Click a second time - "false"
+  logPersistToggle.click();
+  await waitUntil(() => hud.ui.wrapper.getStore().getState().ui.persistLogs === false);
+
+  const expectedEvents = [
+    {
+      category: "devtools.main",
+      method: "persist_changed",
+      object: "webconsole",
+      value: "true",
+    },
+    {
+      category: "devtools.main",
+      method: "persist_changed",
+      object: "webconsole",
+      value: "false",
+    },
+  ];
+
+  const filter = {
+    category: "devtools.main",
+    method: "persist_changed",
+    object: "webconsole",
+  };
+
+  // Will compare filtered events to event list above
+  await TelemetryTestUtils.assertEvents(expectedEvents, filter);
+});
--- a/toolkit/components/telemetry/Events.yaml
+++ b/toolkit/components/telemetry/Events.yaml
@@ -752,16 +752,26 @@ devtools.main:
     record_in_processes: ["main"]
     description: Debugger has paused in a script due to a breakpoint or exception.
     release_channel_collection: opt-out
     expiry_version: never
     extra_keys:
       reason: caught-exception, uncaught-exception, pausing, debugger-statement or breakpoint.
       lib_stacks: Number of collapsed callstacks in the call tree. These are call stacks that are part of external libraries e.g. react, which are collapsed  by default.
       session_id: The start time of the session in milliseconds since epoch (Unix Timestamp) e.g. 1396381378123.
+  persist_changed:
+    objects: ["netmonitor", "webconsole"]
+    bug_numbers: [1531395]
+    notification_emails: ["dev-developer-tools@lists.mozilla.org", "hkirschner@mozilla.com"]
+    record_in_processes: ["main"]
+    description: User has changed log persist status.
+    release_channel_collection: opt-out
+    expiry_version: never
+    extra_keys:
+      session_id: The start time of the session in milliseconds since epoch (Unix Timestamp) e.g. 1396381378123.   
   pretty_print:
     objects: ["debugger"]
     bug_numbers: [1463125]
     notification_emails: ["dev-developer-tools@lists.mozilla.org", "hkirschner@mozilla.com"]
     record_in_processes: ["main"]
     description: User clicked the pretty print button to pretty print a script.
     release_channel_collection: opt-out
     expiry_version: never