Include information about selected device, app and plugin into analytics events and error reports
Summary: This diff generalises computation of the currently selected plugin, app, device etc. and adds this information to all the analytics events and error reports. Slicing of events by os, device, app or selected plugin can be very useful. This is especially true for errors which often affects only certain types of devices, e.g. android only or physical devices only. Having such information can help to narrow down such issues. Reviewed By: passy Differential Revision: D28511441 fbshipit-source-id: ed9dc57927c70ed8cc6fe093e21604eae54c2f60
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b378d8b946
commit
25ae4a0535
110
desktop/app/src/utils/__tests__/info.node.tsx
Normal file
110
desktop/app/src/utils/__tests__/info.node.tsx
Normal file
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {Store} from '../../reducers/index';
|
||||
import {createStore} from 'redux';
|
||||
import {rootReducer} from '../../store';
|
||||
import initialize, {getInfo} from '../info';
|
||||
import {registerLoadedPlugins} from '../../reducers/plugins';
|
||||
import {TestUtils} from 'flipper-plugin';
|
||||
import {getInstance} from '../../fb-stubs/Logger';
|
||||
import {selectPlugin} from '../../reducers/connections';
|
||||
import {renderMockFlipperWithPlugin} from '../../test-utils/createMockFlipperWithPlugin';
|
||||
|
||||
const networkPluginDetails = TestUtils.createMockPluginDetails({
|
||||
id: 'Network',
|
||||
name: 'flipper-plugin-network',
|
||||
version: '0.78.0',
|
||||
dir: '/plugins/public/network',
|
||||
pluginType: 'client',
|
||||
});
|
||||
|
||||
const inspectorPluginDetails = TestUtils.createMockPluginDetails({
|
||||
id: 'Inspector',
|
||||
name: 'flipper-plugin-inspector',
|
||||
version: '0.59.0',
|
||||
dir: '/plugins/public/flipper-plugin-inspector',
|
||||
pluginType: 'client',
|
||||
});
|
||||
|
||||
describe('info', () => {
|
||||
let mockStore: Store;
|
||||
|
||||
beforeEach(() => {
|
||||
mockStore = createStore(rootReducer);
|
||||
mockStore.dispatch({type: 'INIT'});
|
||||
});
|
||||
|
||||
test('retrieve selection info', async () => {
|
||||
const networkPlugin = TestUtils.createTestPlugin(
|
||||
{
|
||||
plugin() {
|
||||
return {};
|
||||
},
|
||||
},
|
||||
networkPluginDetails,
|
||||
);
|
||||
const inspectorPlugin = TestUtils.createTestPlugin(
|
||||
{
|
||||
plugin() {
|
||||
return {};
|
||||
},
|
||||
},
|
||||
inspectorPluginDetails,
|
||||
);
|
||||
const {client, device, store} = await renderMockFlipperWithPlugin(
|
||||
networkPlugin,
|
||||
{
|
||||
additionalPlugins: [inspectorPlugin],
|
||||
},
|
||||
);
|
||||
initialize(store, getInstance());
|
||||
store.dispatch(
|
||||
registerLoadedPlugins([networkPluginDetails, inspectorPluginDetails]),
|
||||
);
|
||||
const networkPluginSelectionInfo = getInfo();
|
||||
store.dispatch(
|
||||
selectPlugin({
|
||||
selectedPlugin: inspectorPlugin.id,
|
||||
selectedApp: client.query.app,
|
||||
selectedDevice: device,
|
||||
deepLinkPayload: null,
|
||||
}),
|
||||
);
|
||||
const inspectorPluginSelectionInfo = getInfo();
|
||||
expect(networkPluginSelectionInfo.selection).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"app": "TestApp",
|
||||
"archived": false,
|
||||
"device": "MockAndroidDevice",
|
||||
"deviceName": "MockAndroidDevice",
|
||||
"deviceSerial": "serial",
|
||||
"deviceType": "physical",
|
||||
"os": "Android",
|
||||
"plugin": "Network",
|
||||
"pluginName": "flipper-plugin-network",
|
||||
"pluginVersion": "0.78.0",
|
||||
}
|
||||
`);
|
||||
expect(inspectorPluginSelectionInfo.selection).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"app": "TestApp",
|
||||
"archived": false,
|
||||
"device": "MockAndroidDevice",
|
||||
"deviceName": "MockAndroidDevice",
|
||||
"deviceSerial": "serial",
|
||||
"deviceType": "physical",
|
||||
"os": "Android",
|
||||
"plugin": "Inspector",
|
||||
"pluginName": "flipper-plugin-inspector",
|
||||
"pluginVersion": "0.59.0",
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
@@ -10,10 +10,13 @@
|
||||
import os from 'os';
|
||||
import isProduction, {isTest} from './isProduction';
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import {getStaticPath} from './pathUtils';
|
||||
import type {State, Store} from '../reducers/index';
|
||||
import {deconstructClientId} from './clientUtils';
|
||||
import {sideEffect} from './sideEffect';
|
||||
import {Logger} from '../fb-interfaces/Logger';
|
||||
|
||||
export type Info = {
|
||||
type PlatformInfo = {
|
||||
arch: string;
|
||||
platform: string;
|
||||
unixname: string;
|
||||
@@ -22,20 +25,77 @@ export type Info = {
|
||||
};
|
||||
};
|
||||
|
||||
export type SelectionInfo = {
|
||||
plugin: string | null;
|
||||
pluginName: string | null;
|
||||
pluginVersion: string | null;
|
||||
app: string | null;
|
||||
os: string | null;
|
||||
device: string | null;
|
||||
deviceName: string | null;
|
||||
deviceSerial: string | null;
|
||||
deviceType: string | null;
|
||||
archived: boolean | null;
|
||||
};
|
||||
|
||||
export type Info = PlatformInfo & {
|
||||
selection: SelectionInfo;
|
||||
};
|
||||
|
||||
let platformInfo: PlatformInfo | undefined;
|
||||
let selection: SelectionInfo = {
|
||||
plugin: null,
|
||||
pluginName: null,
|
||||
pluginVersion: null,
|
||||
app: null,
|
||||
os: null,
|
||||
device: null,
|
||||
deviceName: null,
|
||||
deviceSerial: null,
|
||||
deviceType: null,
|
||||
archived: null,
|
||||
};
|
||||
|
||||
export default (store: Store, _logger: Logger) => {
|
||||
return sideEffect(
|
||||
store,
|
||||
{
|
||||
name: 'recomputeSelectionInfo',
|
||||
throttleMs: 0,
|
||||
noTimeBudgetWarns: true,
|
||||
runSynchronously: true,
|
||||
fireImmediately: true,
|
||||
},
|
||||
(state) => ({
|
||||
connections: state.connections,
|
||||
loadedPlugins: state.plugins.loadedPlugins,
|
||||
}),
|
||||
(state, _store) => {
|
||||
selection = getSelectionInfo(state.connections, state.loadedPlugins);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* This method builds up some metadata about the users environment that we send
|
||||
* on bug reports, analytic events, errors etc.
|
||||
*/
|
||||
export function getInfo(): Info {
|
||||
if (!platformInfo) {
|
||||
platformInfo = {
|
||||
arch: process.arch,
|
||||
platform: process.platform,
|
||||
unixname: os.userInfo().username,
|
||||
versions: {
|
||||
electron: process.versions.electron,
|
||||
node: process.versions.node,
|
||||
platform: os.release(),
|
||||
},
|
||||
};
|
||||
}
|
||||
return {
|
||||
arch: process.arch,
|
||||
platform: process.platform,
|
||||
unixname: os.userInfo().username,
|
||||
versions: {
|
||||
electron: process.versions.electron,
|
||||
node: process.versions.node,
|
||||
platform: os.release(),
|
||||
},
|
||||
...platformInfo,
|
||||
selection,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -66,3 +126,26 @@ export function stringifyInfo(info: Info): string {
|
||||
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
export function getSelectionInfo(
|
||||
connections: State['connections'],
|
||||
loadedPlugins: State['plugins']['loadedPlugins'],
|
||||
): SelectionInfo {
|
||||
const selectedApp = connections.selectedApp;
|
||||
const clientIdParts = selectedApp ? deconstructClientId(selectedApp) : null;
|
||||
const loadedPlugin = connections.selectedPlugin
|
||||
? loadedPlugins.get(connections.selectedPlugin)
|
||||
: null;
|
||||
return {
|
||||
plugin: connections.selectedPlugin || null,
|
||||
pluginName: loadedPlugin?.name || null,
|
||||
pluginVersion: loadedPlugin?.version || null,
|
||||
app: clientIdParts?.app || null,
|
||||
device: connections.selectedDevice?.title || null,
|
||||
deviceName: clientIdParts?.device || null,
|
||||
deviceSerial: connections.selectedDevice?.serial || null,
|
||||
deviceType: connections.selectedDevice?.deviceType || null,
|
||||
os: connections.selectedDevice?.os || null,
|
||||
archived: connections.selectedDevice?.isArchived || false,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user