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

Telemetry Command #76029

Merged
merged 10 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions build/azure-pipelines/darwin/product-build-darwin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ steps:
node build/lib/builtInExtensions.js
displayName: Install distro dependencies and extensions

- script: |
set -e
cd ..
git clone https://github.com/microsoft/vscode-telemetry-extractor.git
cd vscode-telemetry-extractor
npm install
./node_modules/typescript/bin/tsc
npm run setup-extension-repos
node ./out/cli-extract.js --sourceDir ../s --excludedDirPattern extensions --outputDir . --applyEndpoints --includeIsMeasurement --patchWebsiteEvents
node ./out/cli-extract-extensions.js --sourceDir ./src/telemetry-sources/ --outputDir . --applyEndpoints --includeIsMeasurement
mv declarations-resolved.json ../s/src/telemetry-core.json
mv declarations-extensions-resolved.json ../s/src/telemetry-extensions.json
echo 'Moved Files'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So Darwin doesn't need a specific build script?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the echo. 👍

displayName: Extract Telemetry

- script: |
set -e
VSCODE_MIXIN_PASSWORD="$(github-distro-mixin-password)" \
Expand Down
15 changes: 15 additions & 0 deletions build/azure-pipelines/linux/product-build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ steps:
node build/lib/builtInExtensions.js
displayName: Install distro dependencies and extensions

- script: |
set -e
cd ..
git clone https://github.com/microsoft/vscode-telemetry-extractor.git
cd vscode-telemetry-extractor
npm install
./node_modules/typescript/bin/tsc
npm run setup-extension-repos
node ./out/cli-extract.js --sourceDir ../s --excludedDirPattern extensions --outputDir . --applyEndpoints --includeIsMeasurement --patchWebsiteEvents
node ./out/cli-extract-extensions.js --sourceDir ./src/telemetry-sources/ --outputDir . --applyEndpoints --includeIsMeasurement
mv declarations-resolved.json ../s/src/telemetry-core.json
joaomoreno marked this conversation as resolved.
Show resolved Hide resolved
mv declarations-extensions-resolved.json ../s/src/telemetry-extensions.json
echo 'Moved Files'
displayName: Extract Telemetry

- script: |
set -e
VSCODE_MIXIN_PASSWORD="$(github-distro-mixin-password)" \
Expand Down
17 changes: 17 additions & 0 deletions build/azure-pipelines/win32/product-build-win32.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ steps:
exec { node build/lib/builtInExtensions.js }
displayName: Install distro dependencies and extensions

- powershell: |
. build/azure-pipelines/win32/exec.ps1
$ErrorActionPreference = "Stop"
cd ..
git clone https://github.com/microsoft/vscode-telemetry-extractor.git
cd vscode-telemetry-extractor
npm install
npm install -g typescript
tsc
npm run setup-extension-repos
node ./out/cli-extract.js --sourceDir ../s --excludedDirPattern extensions --outputDir . --applyEndpoints --includeIsMeasurement --patchWebsiteEvents
node ./out/cli-extract-extensions.js --sourceDir ./src/telemetry-sources/ --outputDir . --applyEndpoints --includeIsMeasurement
mv declarations-resolved.json ../s/src/telemetry-core.json
mv declarations-extensions-resolved.json ../s/src/telemetry-extensions.json
echo 'Moved Files'
displayName: Extract Telemetry

- powershell: |
. build/azure-pipelines/win32/exec.ps1
$ErrorActionPreference = "Stop"
Expand Down
4 changes: 3 additions & 1 deletion build/gulpfile.vscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const vscodeResources = [
'out-build/bootstrap-amd.js',
'out-build/bootstrap-window.js',
'out-build/paths.js',
'out-build/telemetry-core.json',
'out-build/telemetry-extensions.json',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lramos15 I noticed this code isn't in master anymore but it wasn't removed during the PR to remove the command. What happened to it?

'out-build/vs/**/*.{svg,png,cur,html}',
'!out-build/vs/code/browser/**/*.html',
'out-build/vs/base/common/performance.js',
Expand Down Expand Up @@ -327,7 +329,7 @@ function packageTask(platform, arch, sourceFolderName, destinationFolderName, op
.pipe(createAsar(path.join(process.cwd(), 'node_modules'), ['**/*.node', '**/vscode-ripgrep/bin/*', '**/node-pty/build/Release/*'], 'app/node_modules.asar'));

let all = es.merge(
packageJsonStream,
packageJsonStream,
productJsonStream,
license,
api,
Expand Down
1 change: 1 addition & 0 deletions resources/completions/zsh/_code
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ arguments=(
'--user-data-dir[specify the directory that user data is kept in]:directory:_directories'
'(- *)'{-v,--version}'[print version]'
'(- *)'{-h,--help}'[print usage]'
'(- *)'{--telemetry}'[Shows all telemetry events which VS code collects.]'
'--extensions-dir[set the root path for extensions]:root path:_directories'
'--list-extensions[list the installed extensions]'
'--show-versions[show versions of installed extensions, when using --list-extension]'
Expand Down
3 changes: 2 additions & 1 deletion src/vs/code/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function shouldSpawnCliProcess(argv: ParsedArgs): boolean {
|| !!argv['list-extensions']
|| !!argv['install-extension']
|| !!argv['uninstall-extension']
|| !!argv['locate-extension'];
|| !!argv['locate-extension']
|| !!argv['telemetry'];
}

interface IMainCli {
Expand Down
3 changes: 3 additions & 0 deletions src/vs/code/node/cliProcessMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { LocalizationsService } from 'vs/platform/localizations/node/localizations';
import { Schemas } from 'vs/base/common/network';
import { SpdLogService } from 'vs/platform/log/node/spdlogService';
import { buildTelemetryMessage } from 'vs/platform/environment/node/argv';

const notFound = (id: string) => localize('notFound', "Extension '{0}' not found.", id);
const notInstalled = (id: string) => localize('notInstalled', "Extension '{0}' is not installed.", id);
Expand Down Expand Up @@ -94,6 +95,8 @@ export class Main {
const arg = argv['locate-extension'];
const ids: string[] = typeof arg === 'string' ? [arg] : arg;
await this.locateExtension(ids);
} else if (argv['telemetry']) {
console.log(buildTelemetryMessage(this.environmentService.appRoot, this.environmentService.extensionsPath));
}
}

Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/environment/common/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface ParsedArgs {
_urls?: string[];
help?: boolean;
version?: boolean;
telemetry?: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lramos15 shouldn't break anything but missed this arg when removing the command

status?: boolean;
wait?: boolean;
waitMarkerFilePath?: string;
Expand Down
36 changes: 35 additions & 1 deletion src/vs/platform/environment/node/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import * as os from 'os';
import { localize } from 'vs/nls';
import { ParsedArgs } from 'vs/platform/environment/common/environment';
import { join } from 'vs/base/common/path';
import { writeFileSync } from 'vs/base/node/pfs';
import { statSync, readFileSync } from 'fs';
import { writeFileSync, readdirSync } from 'vs/base/node/pfs';

/**
* This code is also used by standalone cli's. Avoid adding any other dependencies.
Expand Down Expand Up @@ -41,6 +42,7 @@ export const options: Option[] = [
{ id: 'user-data-dir', type: 'string', cat: 'o', args: 'dir', description: localize('userDataDir', "Specifies the directory that user data is kept in. Can be used to open multiple distinct instances of Code.") },
{ id: 'version', type: 'boolean', cat: 'o', alias: 'v', description: localize('version', "Print version.") },
{ id: 'help', type: 'boolean', cat: 'o', alias: 'h', description: localize('help', "Print usage.") },
{ id: 'telemetry', type: 'boolean', cat: 'o', description: localize('telemetry', "Shows all telemetry events which VS code collects.") },
{ id: 'folder-uri', type: 'string', cat: 'o', args: 'uri', description: localize('folderUri', "Opens a window with given folder uri(s)") },
{ id: 'file-uri', type: 'string', cat: 'o', args: 'uri', description: localize('fileUri', "Opens a window with given file uri(s)") },

Expand Down Expand Up @@ -217,6 +219,38 @@ export function buildVersionMessage(version: string | undefined, commit: string
return `${version || localize('unknownVersion', "Unknown version")}\n${commit || localize('unknownCommit', "Unknown commit")}\n${process.arch}`;
}

export function buildTelemetryMessage(appRoot: string, extensionsPath: string): string {
try {
lramos15 marked this conversation as resolved.
Show resolved Hide resolved
joaomoreno marked this conversation as resolved.
Show resolved Hide resolved
// Gets all the directories inside the extension directory
const dirs = readdirSync(extensionsPath).filter(files => statSync(join(extensionsPath, files)).isDirectory());
const telemetryJsonFolders: string[] = [];
dirs.forEach((dir) => {
const files = readdirSync(join(extensionsPath, dir)).filter(file => file === 'telemetry.json');
// We know it contains a telemetry.json file so we add it to the list of folders which have one
if (files.length === 1) {
telemetryJsonFolders.push(dir);
}
});
const mergedTelemetry = Object.create(null);
// Simple function to merge the telemetry into one json object
const mergeTelemetry = (contents: string, dirName: string) => {
const telemetryData = JSON.parse(contents);
mergedTelemetry[dirName] = telemetryData;
};
telemetryJsonFolders.forEach((folder) => {
const contents = readFileSync(join(extensionsPath, folder, 'telemetry.json')).toString();
mergeTelemetry(contents, folder);
});
let contents = readFileSync(join(appRoot, 'out/', 'telemetry-core.json')).toString();
mergeTelemetry(contents, 'vscode-core');
contents = readFileSync(join(appRoot, 'out/', 'telemetry-extensions.json')).toString();
mergeTelemetry(contents, 'vscode-extensions');
return JSON.stringify(mergedTelemetry, null, 4);
} catch (err) {
return 'Unable to read VS Code telemetry events!';
Copy link
Member

@joaomoreno joaomoreno Jun 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove the whole try catch block and let the actual error bubble up and be printed to the console.

}
}

/**
* Converts an argument into an array
* @param arg a argument value. Can be undefined, an entry or an array
Expand Down