diff --git a/devtools/client/netmonitor/src/connector/firefox-connector.js b/devtools/client/netmonitor/src/connector/firefox-connector.js index 4d3b14ef89be..bf4193189d25 100644 --- a/devtools/client/netmonitor/src/connector/firefox-connector.js +++ b/devtools/client/netmonitor/src/connector/firefox-connector.js @@ -442,6 +442,8 @@ class FirefoxConnector { latency, }); } + + this.emit(EVENTS.THROTTLING_CHANGED, { profile }); } /** diff --git a/devtools/client/netmonitor/src/constants.js b/devtools/client/netmonitor/src/constants.js index 5a711496fb1a..54772fea700d 100644 --- a/devtools/client/netmonitor/src/constants.js +++ b/devtools/client/netmonitor/src/constants.js @@ -105,6 +105,9 @@ const EVENTS = { // When request payload (HTTP details data) are fetched from the backend. PAYLOAD_READY: "NetMonitor:PayloadReady", + + // When throttling is set on the backend. + THROTTLING_CHANGED: "NetMonitor:ThrottlingChanged", }; const UPDATE_PROPS = [ diff --git a/devtools/client/netmonitor/src/middleware/event-telemetry.js b/devtools/client/netmonitor/src/middleware/event-telemetry.js index ff3ca9a451f8..ae7bcdbe0002 100644 --- a/devtools/client/netmonitor/src/middleware/event-telemetry.js +++ b/devtools/client/netmonitor/src/middleware/event-telemetry.js @@ -14,6 +14,10 @@ const { SEND_CUSTOM_REQUEST, } = require("../constants"); +const { + CHANGE_NETWORK_THROTTLING, +} = require("devtools/client/shared/components/throttling/actions"); + /** * Event telemetry middleware is responsible for logging * various events to telemetry. This helps to track Network @@ -66,6 +70,15 @@ function eventTelemetryMiddleware(connector, telemetry) { }); } + // Record telemetry event when throttling is changed. + if (action.type == CHANGE_NETWORK_THROTTLING) { + throttlingChange({ + action, + telemetry, + sessionId, + }); + } + return res; }; } @@ -132,4 +145,15 @@ function sendCustomRequest({telemetry, sessionId}) { }); } +/** + * This helper function is executed when network throttling is changed. + * It's responsible for recording "throttle_changed" telemetry event. + */ +function throttlingChange({action, telemetry, sessionId}) { + telemetry.recordEvent("devtools.main", "throttle_changed", "netmonitor", null, { + "mode": action.profile, + "session_id": sessionId, + }); +} + module.exports = eventTelemetryMiddleware; diff --git a/devtools/client/netmonitor/test/browser.ini b/devtools/client/netmonitor/test/browser.ini index 91c4c40cd90d..c1185798e71f 100644 --- a/devtools/client/netmonitor/test/browser.ini +++ b/devtools/client/netmonitor/test/browser.ini @@ -188,6 +188,7 @@ skip-if = true # Bug 1373558 [browser_net_telemetry_edit_resend.js] [browser_net_telemetry_filters_changed.js] [browser_net_telemetry_sidepanel_changed.js] +[browser_net_telemetry_throttle_changed.js] [browser_net_throttle.js] [browser_net_timeline_ticks.js] skip-if = true # TODO: fix the test diff --git a/devtools/client/netmonitor/test/browser_net_telemetry_throttle_changed.js b/devtools/client/netmonitor/test/browser_net_telemetry_throttle_changed.js new file mode 100644 index 000000000000..eb05476592e5 --- /dev/null +++ b/devtools/client/netmonitor/test/browser_net_telemetry_throttle_changed.js @@ -0,0 +1,40 @@ +/* -*- 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/ */ + +"use strict"; + +const OPTOUT = Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTOUT; + +/** + * Test the throttle_change telemetry event. + */ +add_task(async function() { + const { monitor } = await initNetMonitor(SIMPLE_URL); + info("Starting test... "); + + const { document, store, windowRequire } = monitor.panelWin; + const Actions = windowRequire("devtools/client/netmonitor/src/actions/index"); + store.dispatch(Actions.batchEnable(false)); + + // Remove all telemetry events. + 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"); + + document.querySelector("#global-network-throttling-selector").click(); + monitor.panelWin.parent.document.querySelector("menuitem[label='GPRS']").click(); + await waitFor(monitor.panelWin.api, EVENTS.THROTTLING_CHANGED); + + // Verify existence of the telemetry event. + checkTelemetryEvent({ + mode: "GPRS", + }, { + method: "throttle_changed", + }); + + return teardown(monitor); +}); diff --git a/toolkit/components/telemetry/Events.yaml b/toolkit/components/telemetry/Events.yaml index f091694ad16a..ac293e7b3e59 100644 --- a/toolkit/components/telemetry/Events.yaml +++ b/toolkit/components/telemetry/Events.yaml @@ -549,6 +549,17 @@ devtools.main: expiry_version: never extra_keys: session_id: The toolbox session start time e.g. 13963. + throttle_changed: + objects: ["netmonitor"] + bug_numbers: [1463147] + notification_emails: ["dev-developer-tools@lists.mozilla.org", "hkirschner@mozilla.com"] + record_in_processes: ["main"] + description: User has changed the throttle setting in the netmonitor. + release_channel_collection: opt-out + expiry_version: never + extra_keys: + mode: No throttling, GPRS, Regular 2G, Good 2G, Regular 3G, Good 3G, Regular 4G / LTE, DSL or WI-FI. + session_id: The toolbox session start time e.g. 13963. execute_js: objects: ["webconsole"] bug_numbers: [1463083]