Permalink
Browse files

A custom ping, making use of the new multi-store feature

See blog post on https://fnordig.de/
  • Loading branch information...
badboy committed Jan 21, 2019
1 parent ec14417 commit a872a3fa06be30667c0ac5fc47007780e8a9f6b0
@@ -66,6 +66,9 @@ browser.engagement:
release_channel_collection: opt-out
record_in_processes:
- 'main'
record_into_store:
- "main"
- "custom-store"

max_concurrent_window_count:
bug_numbers:
@@ -175,6 +178,20 @@ browser.engagement:
record_in_processes:
- 'main'

tick_times_rand:
bug_numbers:
- 0
description: "A random value at every tick"
expires: '71'
kind: uint
notification_emails:
- janerik@fnordig.de
release_channel_collection: opt-out
record_in_processes:
- "main"
record_into_store:
- "custom-store"

# The following section contains the browser engagement scalars.
browser.engagement.navigation:
urlbar:
@@ -62,6 +62,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
TelemetryReportingPolicy: "resource://gre/modules/TelemetryReportingPolicy.jsm",
TelemetryModules: "resource://gre/modules/ModulesPing.jsm",
TelemetryUntrustedModulesPing: "resource://gre/modules/UntrustedModulesPing.jsm",
TelemetryCustomPing: "resource://gre/modules/CustomPing.jsm",
UpdatePing: "resource://gre/modules/UpdatePing.jsm",
TelemetryHealthPing: "resource://gre/modules/HealthPing.jsm",
TelemetryEventPing: "resource://gre/modules/EventPing.jsm",
@@ -720,6 +721,9 @@ var Impl = {
if (AppConstants.NIGHTLY_BUILD && AppConstants.platform == "win") {
TelemetryUntrustedModulesPing.start();
}

// Start the custom ping, which reports minimal information (for documentation purposes only).
TelemetryCustomPing.start();
}

TelemetryEventPing.startup();
@@ -46,6 +46,7 @@ var TelemetryUtils = {
TelemetryEnabled: "toolkit.telemetry.enabled",
Unified: "toolkit.telemetry.unified",
UntrustedModulesPingFrequency: "toolkit.telemetry.untrustedModulesPing.frequency",
CustomPingFrequency: "toolkit.telemetry.untrustedModulesPing.frequency",
UpdatePing: "toolkit.telemetry.updatePing.enabled",
NewProfilePingEnabled: "toolkit.telemetry.newProfilePing.enabled",
NewProfilePingDelay: "toolkit.telemetry.newProfilePing.delay",
@@ -110,6 +110,7 @@ EXTRA_JS_MODULES += [
'other/GCTelemetry.jsm',
'other/UITelemetry.jsm',
'pings/CoveragePing.jsm',
'pings/CustomPing.jsm',
'pings/EventPing.jsm',
'pings/HealthPing.jsm',
'pings/ModulesPing.jsm',
@@ -0,0 +1,68 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*
* This module periodically sends a custom Telemetry ping containing minimal information from its own custom store.
* It's only for documentation purposes and not included in Firefox.
*/

"use strict";

var EXPORTED_SYMBOLS = [
"TelemetryCustomPing",
];

ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", this);

XPCOMUtils.defineLazyModuleGetters(this, {
Services: "resource://gre/modules/Services.jsm",
TelemetryController: "resource://gre/modules/TelemetryController.jsm",
TelemetryUtils: "resource://gre/modules/TelemetryUtils.jsm",
});

XPCOMUtils.defineLazyServiceGetters(this, {
UpdateTimerManager: ["@mozilla.org/updates/timer-manager;1", "nsIUpdateTimerManager"],
});

const DEFAULT_INTERVAL_SECONDS = 24 * 60 * 60; // 1 day

const TIMER_NAME = "telemetry_custom_ping";
const PING_SUBMISSION_NAME = "custom";
const STORE_NAME = "custom-store";

var TelemetryCustomPing = Object.freeze({
start() {
UpdateTimerManager.registerTimer(
TIMER_NAME,
this,
Services.prefs.getIntPref(TelemetryUtils.Preferences.CustomPingFrequency,
DEFAULT_INTERVAL_SECONDS)
);

this.sendPing();
},

notify() {
this.sendPing();
},

sendPing() {
// Let's record just one more value, so _something_ is included.
let randValue = Math.floor(Math.random() * Math.floor(100));
Services.telemetry.scalarSet("browser.engagement.tick_times_rand", randValue);

// We only include scalars, as that's all we are recording for this ping.
let payload = {
custom: "This is custom data",
scalars: Services.telemetry.getSnapshotForScalars(STORE_NAME, /* clear */ true),
};

TelemetryController.submitExternalPing(PING_SUBMISSION_NAME, payload,
{
addClientId: false,
addEnvironment: true,
}
);
}
});

0 comments on commit a872a3f

Please sign in to comment.