Added telemetry for import and export

Summary: Adding telemetry for import and export feature

Reviewed By: jknoxville

Differential Revision: D14267533

fbshipit-source-id: 1a5e041d0dc8c59c325e7d80dc83f6135f479161
This commit is contained in:
Pritesh Nandgaonkar
2019-03-04 05:04:40 -08:00
committed by Facebook Github Bot
parent 7d39c33fc4
commit c098269533
4 changed files with 51 additions and 6 deletions

View File

@@ -6,7 +6,12 @@
*/
import type {FlipperPlugin, FlipperDevicePlugin} from './plugin.js';
import {exportStoreToFile, importFileToStore} from './utils/exportData.js';
import {
exportStoreToFile,
importFileToStore,
IMPORT_FLIPPER_TRACE_EVENT,
EXPORT_FLIPPER_TRACE_EVENT,
} from './utils/exportData.js';
import type {Store} from './reducers/';
import electron from 'electron';
import {GK} from 'flipper';
@@ -14,7 +19,10 @@ import {remote} from 'electron';
const {dialog} = remote;
import os from 'os';
import path from 'path';
import {
reportPlatformFailures,
tryCatchReportPlatformFailures,
} from './utils/metrics';
export type DefaultKeyboardAction = 'clear' | 'goToBottom' | 'createPaste';
export type TopLevelMenu = 'Edit' | 'View' | 'Window' | 'Help';
@@ -328,7 +336,10 @@ function getTemplate(
defaultPath: path.join(os.homedir(), 'FlipperExport.flipper'),
},
file => {
exportStoreToFile(file, store);
reportPlatformFailures(
exportStoreToFile(file, store),
`${EXPORT_FLIPPER_TRACE_EVENT}:UI`,
);
},
);
},
@@ -343,7 +354,9 @@ function getTemplate(
},
(files: Array<string>) => {
if (files !== undefined && files.length > 0) {
importFileToStore(files[0], store);
tryCatchReportPlatformFailures(() => {
importFileToStore(files[0], store);
}, `${IMPORT_FLIPPER_TRACE_EVENT}:UI`);
}
},
);

View File

@@ -10,7 +10,13 @@ import type {Store} from '../reducers/index.js';
import type {Logger} from '../fb-interfaces/Logger.js';
import {toggleAction} from '../reducers/application';
import {parseFlipperPorts} from '../utils/environmentVariables';
import {importDataToStore, importFileToStore} from '../utils/exportData';
import {
importDataToStore,
importFileToStore,
IMPORT_FLIPPER_TRACE_EVENT,
} from '../utils/exportData';
import {tryCatchReportPlatformFailures} from '../utils/metrics';
import {selectPlugin} from '../reducers/connections';
import qs from 'query-string';
@@ -78,7 +84,9 @@ export default (store: Store, logger: Logger) => {
});
ipcRenderer.on('open-flipper-file', (event, url) => {
importFileToStore(url, store);
tryCatchReportPlatformFailures(() => {
return importFileToStore(url, store);
}, `${IMPORT_FLIPPER_TRACE_EVENT}:Deeplink`);
});
if (process.env.FLIPPER_PORTS) {

View File

@@ -4,6 +4,7 @@
* LICENSE file in the root directory of this source tree.
* @format
*/
import {getInstance as getLogger} from '../fb-stubs/Logger';
import type {Store} from '../reducers';
import type {DeviceExport} from '../devices/BaseDevice';
import type {State as PluginStates} from '../reducers/pluginStates';
@@ -21,6 +22,9 @@ import uuid from 'uuid';
import {remote} from 'electron';
import {serialize, deserialize} from './serialization';
export const IMPORT_FLIPPER_TRACE_EVENT = 'import-flipper-trace';
export const EXPORT_FLIPPER_TRACE_EVENT = 'export-flipper-trace';
export type ExportType = {|
fileVersion: string,
clients: Array<ClientExport>,
@@ -226,6 +230,7 @@ export async function serializeStore(store: Store): Promise<?ExportType> {
}
export function exportStore(store: Store): Promise<string> {
getLogger().track('usage', EXPORT_FLIPPER_TRACE_EVENT);
return new Promise(async (resolve, reject) => {
const json = await serializeStore(store);
if (!json) {
@@ -255,6 +260,7 @@ export const exportStoreToFile = (
};
export function importDataToStore(data: string, store: Store) {
getLogger().track('usage', IMPORT_FLIPPER_TRACE_EVENT);
const json = deserialize(data);
const {device, clients} = json;
const {serial, deviceType, title, os, logs} = device;

View File

@@ -53,3 +53,21 @@ export function reportPluginFailures<T>(
},
);
}
/*
* Wraps a closure, preserving it's functionality but logging the success or
failure state of it.
*/
export function tryCatchReportPlatformFailures<T>(
closure: () => T,
name: string,
): T {
try {
const result = closure();
getInstance().track('success-rate', name, 1);
return result;
} catch (e) {
getInstance().track('success-rate', name, 0);
throw e;
}
}