Send as telemetry instead of storing in local database

This commit is contained in:
Fredrik Wollsén 2018-10-28 12:14:35 +02:00
Родитель 2b9d1889e6
Коммит 17f5b3b84d
4 изменённых файлов: 35 добавлений и 69 удалений

Просмотреть файл

@ -1,46 +1,57 @@
import { storeInDb } from "./db";
import { telemetrySender } from "./telemetrySender";
export const logInfo = async function(msg) {
const level = "info";
const logEntry = { level, msg };
await browser.study.logger.log(["dataReceiver - INFO: ", logEntry]);
await storeInDb("openwpmLog", logEntry);
await telemetrySender.submitTelemetryPayload("openwpmLog", logEntry);
};
export const logDebug = async function(msg) {
const level = "debug";
const logEntry = { level, msg };
await browser.study.logger.debug(["dataReceiver", logEntry]);
await storeInDb("openwpmLog", logEntry);
await telemetrySender.submitTelemetryPayload("openwpmLog", logEntry);
};
export const logWarn = async function(msg) {
const level = "warn";
const logEntry = { level, msg };
await browser.study.logger.warn(["dataReceiver", logEntry]);
await storeInDb("openwpmLog", logEntry);
await telemetrySender.submitTelemetryPayload("openwpmLog", logEntry);
};
export const logError = async function(msg) {
const level = "error";
const logEntry = { level, msg };
await browser.study.logger.error(["dataReceiver", logEntry]);
await storeInDb("openwpmLog", logEntry);
await telemetrySender.submitTelemetryPayload("openwpmLog", logEntry);
};
export const logCritical = async function(msg) {
const level = "error";
const logEntry = { level, msg };
await browser.study.logger.error(["dataReceiver", logEntry]);
await storeInDb("openwpmLog", logEntry);
await telemetrySender.submitTelemetryPayload("openwpmLog", logEntry);
};
export const saveRecord = async function(instrument, record) {
await browser.study.logger.error(["dataReceiver - saveRecord - instrument, record", instrument, record]);
await storeInDb(instrument, record);
await browser.study.logger.error([
"dataReceiver - saveRecord - instrument, record",
instrument,
record,
]);
await telemetrySender.submitTelemetryPayload(instrument, record);
};
export const saveContent = async function(content, contentHash) {
await browser.study.logger.error(["dataReceiver - saveContent - contentHash, content.length", contentHash, content.length]);
await storeInDb("savedContent", { content, contentHash });
await browser.study.logger.error([
"dataReceiver - saveContent - contentHash, content.length",
contentHash,
content.length,
]);
await telemetrySender.submitTelemetryPayload("savedContent", {
content,
contentHash,
});
};

Просмотреть файл

@ -1,45 +0,0 @@
import idb from "idb";
const dbName = "jestrPioneerShieldStudy";
let db;
export async function initDb() {
await idb.delete(dbName);
db = await idb.open(dbName, 1, upgradeDB => {
upgradeDB.createObjectStore("studyLog", {
autoIncrement: true,
});
upgradeDB.createObjectStore("navigations", {
autoIncrement: true,
});
});
}
async function getAllData(objectStoreName) {
let tx = db.transaction(objectStoreName, "readonly");
let store = tx.objectStore(objectStoreName);
let allSavedItems = await store.getAll();
return allSavedItems;
}
export async function storeInDb(objectStoreName, object) {
console.log("storeInDb", objectStoreName, object);
let tx = db.transaction(objectStoreName, "readwrite");
let store = tx.objectStore(objectStoreName);
await store.put(object);
await tx.complete;
}
export async function dumpDbContents() {
console.log("Dumping Database Contents");
console.log("=========================");
const studyLogDbContents = await getAllData("studyLog");
console.log("studyLogDbContents", studyLogDbContents);
const navigationsDbContents = await getAllData("navigations");
console.log("navigationsDbContents", navigationsDbContents);
console.log("=========================");
console.log("Dumping Database Contents - Done");
}

Просмотреть файл

@ -3,7 +3,6 @@
("use strict");
import { storeInDb, initDb } from "./db";
import * as dataReceiver from "./dataReceiver";
import { TabsMonitor } from "./TabsMonitor";
import {
@ -17,18 +16,10 @@ class Feature {
async configure(studyInfo) {
const feature = this;
const { variation, isFirstRun } = studyInfo;
// start local study logging
await initDb();
await storeInDb("studyLog", { variation: variation.name, event: "run" });
const { isFirstRun } = studyInfo;
// perform something only during first run
if (isFirstRun) {
await storeInDb("studyLog", {
variation: variation.name,
event: "firstRun",
});
}
// Start OpenWPM instrumentation
@ -40,10 +31,6 @@ class Feature {
this.tabsMonitor.configure(feature);
}
sendTelemetry(stringStringMap) {
browser.study.sendTelemetry(stringStringMap);
}
startOpenWPMInstrumentation(config) {
if (config["cookie_instrument"]) {
dataReceiver.logDebug("Cookie instrumentation enabled");

Просмотреть файл

@ -0,0 +1,13 @@
export class TelemetrySender {
async submitTelemetryPayload(interfaceName, payload) {
const stringStringMap = { ...payload };
return this.sendTelemetry(stringStringMap);
}
async sendTelemetry(stringStringMap) {
return browser.study.sendTelemetry(stringStringMap);
}
}
// export a singleton
export const telemetrySender = new TelemetrySender();