Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Implement telemetry in cli #1226

Merged
merged 50 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
ce97c77
Normalize network id to camelcase
jbcarpanelli Sep 10, 2019
113dd8d
Add env-paths library
jbcarpanelli Sep 10, 2019
c06b9d7
Scaffold telemetry functions
jbcarpanelli Sep 10, 2019
bda3bf4
Add telemetryOptIn field to ProjectFile
jbcarpanelli Sep 10, 2019
ef90d3d
Check telemetry opt in on local and global files
jbcarpanelli Sep 10, 2019
3540a4e
Add telemetry function call in `create` command
jbcarpanelli Sep 10, 2019
024c18c
Install uuid and firebase libraries
jbcarpanelli Sep 12, 2019
2d24bcb
First attempt to send command options to firebase
jbcarpanelli Sep 12, 2019
300e452
Install lodash.mapvalues
jbcarpanelli Sep 13, 2019
63f81b5
Create user document if it does not exist
jbcarpanelli Sep 13, 2019
0168eb7
Conceal command data before sending it to firebase
jbcarpanelli Sep 13, 2019
986d0ec
Close firebase connections
jbcarpanelli Sep 13, 2019
97fd12f
Handle undefined fields properly on conceal
jbcarpanelli Sep 13, 2019
6ea7fac
Avoid telemetry reports on implicit command calls
jbcarpanelli Sep 13, 2019
a28123e
Add telemetry to update command
jbcarpanelli Sep 16, 2019
525c78e
Avoid concealing network name if present
jbcarpanelli Sep 16, 2019
0682e49
Send interactive flag value to telemetry#report fn
jbcarpanelli Sep 16, 2019
dc32f7c
Rename GlobalTelemetry interface
jbcarpanelli Sep 16, 2019
344d45c
Check global opt-in value before reporting
jbcarpanelli Sep 16, 2019
a84b589
Disable interactivity if flag is provided
jbcarpanelli Sep 16, 2019
57ad0c7
Stub report function on commands tests
jbcarpanelli Sep 16, 2019
937d61d
Wrap telemetry function in an object
jbcarpanelli Sep 16, 2019
27ded8a
Test telemetry
jbcarpanelli Sep 16, 2019
ec02718
Add more tests to telemetry and fix command stub
jbcarpanelli Sep 17, 2019
2a8e319
Lint telemetry tests
jbcarpanelli Sep 17, 2019
c1d0a5e
refactor and add types to concealData
frangio Sep 19, 2019
054b293
add full types to telemetry module
frangio Sep 19, 2019
83f7ec8
fix types and a bug when adding network
frangio Sep 19, 2019
71225cb
make telemetry reporting non-blocking
frangio Oct 9, 2019
34e7bcd
update telemetry opt-in message
frangio Oct 9, 2019
16e0c04
match path basename against string
frangio Oct 9, 2019
3274d6b
lint
frangio Oct 9, 2019
e791e33
fix failing test
frangio Oct 9, 2019
ac8f657
add missing assertion for prompt
frangio Oct 9, 2019
53ddc60
enable interactivity for telemetry tests
frangio Oct 10, 2019
e6f08d4
add telemetry to all missing commands
frangio Oct 10, 2019
24454e9
fix compile stack too deep error
frangio Oct 10, 2019
add2d46
ensure that firebase connections are closed
frangio Oct 11, 2019
f058ea4
fix balance command tests
frangio Oct 11, 2019
a3d8a21
remove unused import
frangio Oct 17, 2019
25986c2
move firebase request off the cli process
frangio Oct 17, 2019
9cb1ffc
move reference to dom types and add an explanation
frangio Oct 18, 2019
a847d7b
silence any potential child process output
frangio Oct 18, 2019
94a1fb9
add comment explaining why we export an object
frangio Oct 18, 2019
fb6fa2b
rename variables for clarity
frangio Oct 18, 2019
be28984
remove mutation of object argument
frangio Oct 18, 2019
cc1500a
do not write project file in telemetry check if it doesn't exist yet
frangio Oct 18, 2019
49ec734
add FAQ entry for telemetry
frangio Oct 18, 2019
da9d46c
remove only from tests
frangio Oct 18, 2019
63e9640
install yargs explicitly as dev dependency
frangio Oct 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,525 changes: 1,345 additions & 3,180 deletions packages/cli/package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@
"chalk": "^2.4.1",
"cheerio": "^1.0.0-rc.2",
"commander": "^2.15.1",
"env-paths": "^2.2.0",
"ethereumjs-util": "^6.1.0",
"find-up": "^3.0.0",
"firebase": "^6.6.0",
"fs-extra": "^7.0.1",
"inquirer": "^6.4.1",
"is-url": "^1.2.4",
Expand All @@ -95,6 +97,7 @@
"lodash.isstring": "^4.0.1",
"lodash.isundefined": "^3.0.1",
"lodash.map": "^4.6.0",
"lodash.mapvalues": "^4.6.0",
"lodash.max": "^4.0.1",
"lodash.maxby": "^4.6.0",
"lodash.merge": "^4.6.1",
Expand All @@ -118,6 +121,7 @@
"spinnies": "^0.3.0",
"truffle-config": "1.1.16",
"underscore": "^1.9.1",
"uuid": "^3.3.3",
"web3": "1.2.1",
"web3-utils": "1.2.0"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/commands/accounts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import accounts from '../scripts/accounts';
import { networksList, promptForNetwork, InquirerQuestions } from '../prompts/prompt';
import ConfigManager from '../models/config/ConfigManager';
import Telemetry from '../telemetry';

const name = 'accounts';
const signature: string = name;
Expand All @@ -17,6 +18,8 @@ const register: (program: any) => any = program =>
async function action(options: any): Promise<void> {
const networkOpts = await promptForNetwork(options, () => getCommandProps());
const { network } = await ConfigManager.initNetworkConfiguration({ ...options, ...networkOpts });

await Telemetry.report('accounts', { network }, options.interactive);
await accounts({ network });

if (!options.dontExitProcess && process.env.NODE_ENV !== 'test') process.exit(0);
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import add from '../scripts/add';
import addAll from '../scripts/add-all';
import ConfigManager from '../models/config/ConfigManager';
import { compile } from '../models/compiler/Compiler';

import { promptIfNeeded, contractsList, InquirerQuestions } from '../prompts/prompt';
import { fromContractFullName } from '../utils/naming';
import ProjectFile from '../models/files/ProjectFile';
import Telemetry from '../telemetry';

const name = 'add';
const signature = `${name} [contractNames...]`;
Expand Down Expand Up @@ -38,6 +38,7 @@ async function action(contractNames: string[], options: any): Promise<void> {
? contractNames.map(splitContractName)
: prompted.contractNames.map(contractName => ({ name: contractName }));

if (!options.skipTelemetry) await Telemetry.report('add', { contractsData }, interactive);
add({ contractsData });
}
await push.runActionIfRequested(options);
Expand All @@ -47,6 +48,7 @@ async function runActionIfNeeded(contractName?: string, options?: any): Promise<
const { interactive } = options;
const { contract: contractAlias, package: packageName } = fromContractFullName(contractName);
const projectFile = new ProjectFile();
options = { ...options, skipTelemetry: true };

if (interactive) {
if (!packageName && contractAlias && !projectFile.hasContract(contractAlias)) {
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/commands/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import balance from '../scripts/balance';
import { promptIfNeeded, networksList, InquirerQuestions } from '../prompts/prompt';
import ConfigManager from '../models/config/ConfigManager';
import Session from '../models/network/Session';
import Telemetry from '../telemetry';

const name = 'balance';
const signature = `${name} [address]`;
Expand All @@ -28,14 +29,13 @@ async function action(accountAddress: string, options: any): Promise<void> {
const defaults = { network: networkInSession };
const promptedConfig = await promptIfNeeded({ args, opts, props, defaults }, interactive);

await ConfigManager.initNetworkConfiguration({
const { network } = await ConfigManager.initNetworkConfiguration({
...options,
...promptedConfig,
});
await balance({
accountAddress: promptedConfig.accountAddress,
contractAddress,
});

await Telemetry.report('balance', { ...promptedConfig, contractAddress, network }, interactive);
await balance({ accountAddress: promptedConfig.accountAddress, contractAddress });

if (!options.dontExitProcess && process.env.NODE_ENV !== 'test') process.exit(0);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/bump.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import push from './push';
import bump from '../scripts/bump';
import Telemetry from '../telemetry';

const name = 'bump';
const signature = `${name} <version>`;
Expand All @@ -14,6 +15,7 @@ const register: (program: any) => any = program =>
.action(action);

async function action(version: string, options: any): Promise<void> {
await Telemetry.report('bump', { version }, options.interactive);
await bump({ version });
await push.runActionIfRequested(options);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import ConfigManager from '../models/config/ConfigManager';
import { SendTxPropsParams, SendTxSelectionParams } from './interfaces';
import promptForMethodParams from '../prompts/method-params';
import Telemetry from '../telemetry';

const name = 'call';
const signature: string = name;
Expand Down Expand Up @@ -43,6 +44,7 @@ async function action(options: any): Promise<void> {
const { contractFullName, proxyReference } = await promptForProxy(proxyAddress, network, options);
const methodParams = await promptForMethodParams(contractFullName, options, {}, Mutability.Constant);
const args = pickBy({ ...methodParams, proxyAddress: proxyReference });
await Telemetry.report('call', { ...args, network, txParams }, interactive);
await call({ ...args, network, txParams });

if (!options.dontExitProcess && process.env.NODE_ENV !== 'test') process.exit(0);
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/check.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import check from '../scripts/check';
import { compile } from '../models/compiler/Compiler';
import ConfigManager from '../models/config/ConfigManager';
import Telemetry from '../telemetry';

const name = 'check';
const signature = `${name} [contract]`;
Expand All @@ -17,6 +18,7 @@ const register: (program: any) => any = program =>
async function action(contractAlias: string, options: any): Promise<void> {
ConfigManager.initStaticConfiguration();
if (!options.skipCompile) await compile();
await Telemetry.report('check', { contractAlias }, options.interactive);
check({ contractAlias });
}

Expand Down
15 changes: 9 additions & 6 deletions packages/cli/src/commands/compile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { compile } from '../models/compiler/Compiler';
import { CompileParams } from '../scripts/interfaces';
import { ProjectCompilerOptions } from '../models/compiler/solidity/SolidityProjectCompiler';
import Telemetry from '../telemetry';

const name = 'compile';
const signature = `${name}`;
Expand All @@ -25,14 +27,10 @@ const register: (program: any) => any = program =>
'--evm-version [evm]',
`choose target evm version (value is written to configuration file for future runs, defaults depends on compiler: byzantium prior to 0.5.5, petersburg from 0.5.5)`,
)
.withNonInteractiveOption()
.action(action);

async function action(options: {
evmVersion: string;
solcVersion: string;
optimizer: string | boolean;
optimizerRuns: string;
}): Promise<void> {
async function action(options: CompileParams & { interactive: boolean }): Promise<void> {
const { evmVersion, solcVersion: version, optimizer, optimizerRuns } = options;

// Handle optimizer option:
Expand All @@ -59,6 +57,11 @@ async function action(options: {
},
};

await Telemetry.report(
'compile',
{ evmVersion, solcVersion: version, optimizer, optimizerRuns },
options.interactive,
);
await compile(compilerOptions);
}

Expand Down
8 changes: 5 additions & 3 deletions packages/cli/src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ConfigManager from '../models/config/ConfigManager';
import { promptIfNeeded, networksList, contractsList, methodsList, InquirerQuestions } from '../prompts/prompt';
import promptForMethodParams from '../prompts/method-params';
import { ProxyType } from '../scripts/interfaces';
import Telemetry from '../telemetry';

interface PropsParams {
contractFullName?: string;
Expand Down Expand Up @@ -47,20 +48,20 @@ async function commandActions(contractFullName: string, options: any): Promise<v
const { skipCompile } = options;
if (!skipCompile) await compile();

const { network: promptedNewtork, contractFullName: promptedContractFullName } = await promptForCreate(
const { network: promptedNetwork, contractFullName: promptedContractFullName } = await promptForCreate(
contractFullName,
options,
);
const { network, txParams } = await ConfigManager.initNetworkConfiguration({
...options,
network: promptedNewtork,
network: promptedNetwork,
});

await link.runActionIfNeeded(promptedContractFullName, options);
await add.runActionIfNeeded(promptedContractFullName, options);
await push.runActionIfNeeded(promptedContractFullName, network, {
...options,
network: promptedNewtork,
network: promptedNetwork,
force: true,
});

Expand Down Expand Up @@ -90,6 +91,7 @@ async function action(contractFullName: string, options: any): Promise<void> {

if (!(await hasToMigrateProject(network))) process.exit(0);

await Telemetry.report('create', { ...args, network, txParams }, options.interactive);
await create({ ...args, network, txParams });
Session.setDefaultNetworkIfNeeded(network);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/commands/create2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { parseMethodParams } from '../utils/input';
import { fromContractFullName } from '../utils/naming';
import { hasToMigrateProject } from '../prompts/migrations';
import ConfigManager from '../models/config/ConfigManager';
import Telemetry from '../telemetry';

const name = 'create2';
const signature = `${name} [alias]`;
Expand Down Expand Up @@ -54,6 +55,8 @@ async function action(contractFullName: string, options: any): Promise<void> {
packageName,
};

await Telemetry.report('create2', { ...opts, network, txParams }, options.interactive);

if (options.query && options.signature) await runSignatureQuery(opts, network, txParams);
else if (options.query) await runQuery(opts, network, txParams);
else await runCreate(opts, network, txParams);
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/freeze.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import freeze from '../scripts/freeze';
import ConfigManager from '../models/config/ConfigManager';
import Telemetry from '../telemetry';

const name = 'freeze';
const signature: string = name;
Expand All @@ -15,6 +16,7 @@ const register: (program: any) => any = program =>

async function action(options: any): Promise<void> {
const { network, txParams } = await ConfigManager.initNetworkConfiguration(options);
await Telemetry.report('freeze', { network, txParams }, options.interactive);
await freeze({ network, txParams });
if (!options.dontExitProcess && process.env.NODE_ENV !== 'test') process.exit(0);
}
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { promptIfNeeded, InquirerQuestions } from '../prompts/prompt';
import { FileSystem } from '@openzeppelin/upgrades';
import ProjectFile from '../models/files/ProjectFile';
import { notEmpty } from '../prompts/validators';
import Telemetry from '../telemetry';

const name = 'init';
const signature = `${name} [project-name] [version]`;
Expand Down Expand Up @@ -33,8 +34,10 @@ async function action(projectName: string, version: string, options: any): Promi

const dependencies = link ? link.split(',') : [];
const flags = { dependencies, installDependencies, force, publish };
const initArguments = { ...prompted, ...flags };

await init({ ...prompted, ...flags });
await Telemetry.report('init', initArguments, interactive);
frangio marked this conversation as resolved.
Show resolved Hide resolved
await init(initArguments);
await push.runActionIfRequested(options);
}

Expand Down
7 changes: 5 additions & 2 deletions packages/cli/src/commands/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Dependency from '../models/dependency/Dependency';
import ProjectFile from '../models/files/ProjectFile';
import { promptIfNeeded, InquirerQuestions } from '../prompts/prompt';
import { fromContractFullName } from '../utils/naming';
import Telemetry from '../telemetry';

const name = 'link';
const signature = `${name} [dependencies...]`;
Expand All @@ -28,8 +29,10 @@ async function action(dependencies: string[], options: any): Promise<void> {
dependencies: [await Dependency.fetchVersionFromNpm('@openzeppelin/contracts-ethereum-package')],
};
const prompted = await promptIfNeeded({ args, props, defaults }, interactive);
const linkArguments = { ...prompted, installDependencies };

await link({ ...prompted, installDependencies });
if (!options.skipTelemetry) await Telemetry.report('push', linkArguments, interactive);
await link(linkArguments);
await push.runActionIfRequested(options);
}

Expand All @@ -38,7 +41,7 @@ async function runActionIfNeeded(contractFullName: string, options: any): Promis
const projectFile = new ProjectFile();
const { contract: contractAlias, package: packageName } = fromContractFullName(contractFullName);
if (interactive && packageName && !projectFile.hasDependency(packageName)) {
await action([packageName], { ...options, forceInstall: true });
await action([packageName], { ...options, forceInstall: true, skipTelemetry: true });
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ConfigManager from '../models/config/ConfigManager';
import { hasToMigrateProject } from '../prompts/migrations';
import { promptIfNeeded, networksList, InquirerQuestions } from '../prompts/prompt';
import Session from '../models/network/Session';
import Telemetry from '../telemetry';

const name = 'publish';
const signature = `${name}`;
Expand All @@ -28,6 +29,7 @@ async function action(options: any): Promise<void> {
const { network, txParams } = await ConfigManager.initNetworkConfiguration(promptedOpts);
if (!(await hasToMigrateProject(network))) process.exit(0);

await Telemetry.report('publish', { network, txParams }, interactive);
await publish({ network, txParams });
if (!options.dontExitProcess && process.env.NODE_ENV !== 'test') process.exit(0);
}
Expand Down
10 changes: 7 additions & 3 deletions packages/cli/src/commands/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ProjectFile from '../models/files/ProjectFile';
import ConfigManager from '../models/config/ConfigManager';
import { promptIfNeeded, networksList, InquirerQuestions } from '../prompts/prompt';
import NetworkFile from '../models/files/NetworkFile';
import Telemetry from '../telemetry';

const name = 'push';
const signature: string = name;
Expand Down Expand Up @@ -69,15 +70,18 @@ async function action(options: any): Promise<void> {
});
const promptDeployDependencies = await promptForDeployDependencies(deployDependencies, network, interactive);

await push({
const pushArguments = {
deployProxyAdmin,
deployProxyFactory,
force,
reupload,
network,
txParams,
...promptDeployDependencies,
});
};

if (!options.skipTelemetry) await Telemetry.report('push', pushArguments, interactive);
await push(pushArguments);
if (!options.dontExitProcess && process.env.NODE_ENV !== 'test') process.exit(0);
}

Expand All @@ -101,7 +105,7 @@ async function runActionIfNeeded(contractName: string, network: string, options:
(!packageName && !networkFile.hasContract(contractAlias)) ||
(packageName && !networkFile.hasDependency(packageName))
) {
await action({ ...options, dontExitProcess: true });
await action({ ...options, dontExitProcess: true, skipTelemetry: true });
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/remove.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import remove from '../scripts/remove';
import push from './push';
import { promptIfNeeded, contractsList, InquirerQuestions } from '../prompts/prompt';
import Telemetry from '../telemetry';

const name = 'remove';
const signature = `${name} [contracts...]`;
Expand All @@ -23,6 +24,7 @@ async function action(contracts: string[], options: any): Promise<void> {
const props = getCommandProps();
const prompted = await promptIfNeeded({ args, props }, interactive);

await Telemetry.report('remove', prompted, interactive);
remove(prompted);
await push.runActionIfRequested(options);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/commands/send-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '../prompts/prompt';
import { SendTxPropsParams, SendTxSelectionParams } from './interfaces';
import promptForMethodParams from '../prompts/method-params';
import Telemetry from '../telemetry';

const name = 'send-tx';
const signature: string = name;
Expand Down Expand Up @@ -52,6 +53,8 @@ async function action(options: any): Promise<void> {
value,
gas,
});

await Telemetry.report('send-tx', { ...args, network, txParams }, interactive);
await sendTx({ ...args, network, txParams });

if (!options.dontExitProcess && process.env.NODE_ENV !== 'test') process.exit(0);
Expand Down
Loading