Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce telemetry #33

Merged
merged 12 commits into from
Aug 22, 2023
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ And then using _Install from VSIX_ option in VSC.

Releasing requires [`@vscode/vsce`](https://www.npmjs.com/package/@vscode/vsce) package installed.

**IMPORTANT**: To keep telemetry working, before running any `vsce` command, please update `SEGMENT_API_KEY` in `src/config.ts` to correct value for a time of building the extension (DO NOT COMMIT THOUGH!).

After that, run:

```bash
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ This extension contributes the following settings:
* `monokle.configurationPath` - Set path to validation configuration file.
* `monokle.verbose` - Log runtime info to VSC Developer Console.
* `monokle.overwriteRemotePolicyUrl` - Overwrite default Monokle Cloud URL to fetch policies from.
* `monokle.telemetryEnabled` - Enable anonymous telemetry.

## Dependencies

Expand Down
117 changes: 116 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
"default": null,
"description": "Overwrite Monokle Cloud URL which is used to authenticate and fetch policies from. Useful when running on-premise Monokle Cloud."
},
"monokle.telemetryEnabled": {
"type": "boolean",
"default": true,
"description": "Whenever anonymous telemetry is enabled. It will be also disabled automatically when VSC telemetry is disabled globally."
},
"monokle.enabled": {
"type": "boolean",
"default": true,
Expand All @@ -123,7 +128,7 @@
"test": "concurrently -s command-1 -k \"npm run test:server\" \"node ./out/test/run-test.js\"",
"test:cc": "concurrently -s command-1 -k \"npm run test:server\" \"c8 node ./out/test/run-test.js\"",
"test:server": "node ./out/test/run-server.js",
"test:ensure-coverage": "npx c8 check-coverage --lines 70 --functions 80 --branches 80 --statements 70"
"test:ensure-coverage": "npx c8 check-coverage --lines 70 --functions 80 --branches 75 --statements 70"
},
"devDependencies": {
"@graphql-tools/mock": "^9.0.0",
Expand Down Expand Up @@ -152,6 +157,7 @@
"dependencies": {
"@monokle/synchronizer": "^0.2.0",
"@monokle/validation": "^0.25.2",
"@segment/analytics-node": "^1.1.0",
"uuid": "^9.0.0",
"yaml": "^2.3.1"
},
Expand Down
46 changes: 38 additions & 8 deletions src/commands/bootstrap-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { canRun } from '../utils/commands';
import { getWorkspaceConfig, getWorkspaceFolders } from '../utils/workspace';
import { createDefaultConfigFile } from '../utils/validation';
import { raiseInfo, raiseWarning } from '../utils/errors';
import { trackEvent } from '../utils/telemetry';
import logger from '../utils/logger';
import type { Folder } from '../utils/workspace';

Expand All @@ -17,6 +18,10 @@ export function getBootstrapConfigurationCommand() {
return null;
}

trackEvent('command/bootstrap_configuration', {
status: 'started',
});

const folders = getWorkspaceFolders();

if (!folders.length) {
Expand All @@ -29,27 +34,46 @@ export function getBootstrapConfigurationCommand() {
const currentConfig = await getWorkspaceConfig(folder);
if (currentConfig.type === 'file') {
raiseInfo(`Local '${currentConfig.fileName}' configuration file already exists, opening it.`);
return currentConfig.path;
return {
path: currentConfig.path,
type: currentConfig.type,
};
}

if (currentConfig.type === 'config') {
raiseWarning(`Shared '${currentConfig.path}' configuration file already exists, opening it.`);
return currentConfig.path;
return {
path: currentConfig.path,
type: currentConfig.type,
};
}

if (currentConfig.type === 'remote') {
raiseWarning(`Remote '${currentConfig.fileName}' configuration file already exists, opening it.`);
return currentConfig.path;
return {
path: currentConfig.path,
type: currentConfig.type,
};
}

const configPath = (await createDefaultConfigFile(folder.uri.fsPath)).fsPath;

return configPath;
return {
path: configPath,
type: 'default',
};
};

if (folders.length === 1) {
const configPath = await generateConfig(folders[0]);
return await commands.executeCommand('vscode.open', Uri.file(configPath));
const configData = await generateConfig(folders[0]);
await commands.executeCommand('vscode.open', Uri.file(configData.path));

trackEvent('command/bootstrap_configuration', {
status: 'success',
configurationType: configData.type,
});

return null;
}

const quickPick = window.createQuickPick<FolderItem>();
Expand All @@ -63,13 +87,19 @@ export function getBootstrapConfigurationCommand() {
// error
}

const configPath = await generateConfig(selectedFolder);
const configData = await generateConfig(selectedFolder);

quickPick.hide();

await commands.executeCommand('vscode.open', Uri.file(configPath));
await commands.executeCommand('vscode.open', Uri.file(configData.path));

trackEvent('command/bootstrap_configuration', {
status: 'success',
configurationType: configData.type,
});
}
});

quickPick.onDidHide(() => quickPick.dispose());
quickPick.show();

Expand Down
Loading