8000 Add telemetry and option to disable by kylecarbs · Pull Request #519 · coder/code-server · GitHub
[go: up one dir, main page]

Skip to content

Add telemetry and option to disable #519

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

Merged
merged 5 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add telemetry and option to disable
  • Loading branch information
kylecarbs committed Apr 17, 2019
commit 3cf535e03e03f44a10e3134871a8f434e9ce4c08
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ Quickstart guides for [Google Cloud](doc/admin/install/google_cloud.md), [AWS](d

How to [secure your setup](/doc/security/ssl.md).

### Telemetry

Use the `--disable-telemetry` flag to disable tracking ENTIRELY.

We use data collected to improve code-server.

## Development

### Known Issues
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:binary": "ts-node scripts/nbin.ts"
},
"dependencies": {
"@coder/nbin": "^1.1.1",
"@coder/nbin": "^1.1.2",
"commander": "^2.19.0",
"express": "^4.16.4",
"express-static-gzip": "^1.1.3",
Expand Down
6 changes: 6 additions & 0 deletions packages/server/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ commander.version(process.env.VERSION || "development")
.option("-N, --no-auth", "Start without requiring authentication.", undefined)
.option("-H, --allow-http", "Allow http connections.", false)
.option("-P, --password <value>", "Specify a password for authentication.")
.option("--disable-telemetry", "Disables ALL telemetry.", false)
.opti 10000 on("--bootstrap-fork <name>", "Used for development. Never set.")
.option("--extra-args <args>", "Used for development. Never set.")
.arguments("Specify working directory.")
Expand All @@ -51,6 +52,7 @@ const bold = (text: string | number): string | number => {
readonly allowHttp: boolean;
readonly host: string;
readonly port: number;
readonly disableTelemetry: boolean;

readonly userDataDir?: string;
readonly extensionsDir?: string;
Expand All @@ -65,6 +67,10 @@ const bold = (text: string | number): string | number => {
readonly extraArgs?: string;
};

if (options.disableTelemetry) {
process.env.DISABLE_TELEMETRY = "true";
}

// Commander has an exception for `--no` prefixes. Here we'll adjust that.
// tslint:disable-next-line:no-any
const noAuthValue = (commander as any).auth;
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/vscode/sharedProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class SharedProcess {
env: {
VSCODE_ALLOW_IO: "true",
VSCODE_LOGS: process.env.VSCODE_LOGS,
DISABLE_TELEMETRY: process.env.DISABLE_TELEMETRY,
},
}, this.userDataDir);
this.activeProcess = activeProcess;
Expand Down
170 changes: 170 additions & 0 deletions packages/vscode/src/fill/applicationInsights.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/**
* Used by node
*/
import * as https from "https";
import * as os from "os";

export const defaultClient = "filler";

export class TelemetryClient {
public channel = {
setUseDiskRetryCaching: (): void => undefined,
};

public constructor() {
//
}

public trackEvent(options: {
name: string;
properties: object;
measurements: object;
}): void {
if (!options.properties) {
options.properties = {};
}
if (!options.measurements) {
options.measurements = {};
}

try {
const cpus = os.cpus();
// tslint:disable-next-line:no-any
(options.measurements as any).cpu = {
model: cpus[0].model,
cores: cpus.length,
};
} catch (ex) {
// Nothin
}

try {
// tslint:disable-next-line:no-any
(options.measurements as any).memory = {
virtual_free: os.freemem(),
virtual_used: os.totalmem(),
};
} catch (ex) {
//
}

try {
// tslint:disable:no-any
(options.properties as any)["common.shell"] = os.userInfo().shell;
(options.properties as any)["common.release"] = os.release();
(options.properties as any)["common.arch"] = os.arch();
// tslint:enable:no-any
} catch (ex) {
//
}

try {
// tslint:disable-next-line:no-any
(options.properties as any)["common.machineId"] = machineIdSync();
} catch (ex) {
//
}

try {
const request = https.request({
host: "v1.telemetry.coder.com",
port: 443,
path: "/track",
method: "POST",
headers: {
"Content-Type": "application/json",
},
});
request.on("error", () => {
// Do nothing, we don"t really care
});
request.write(JSON.stringify(options));
request.end();
} catch (ex) {
// Suppress all errs
}
}

public flush(options: {
readonly callback: () => void;
}): void {
options.callback();
}
}

// Taken from https://github.com/automation-stack/node-machine-id
import { exec, execSync } from "child_process";
import { createHash } from "crypto";

const isWindowsProcessMixedOrNativeArchitecture = (): "" | "mixed" | "native" => {
// detect if the node binary is the same arch as the Windows OS.
// or if this is 32 bit node on 64 bit windows.
if (process.platform !== "win32") {
return "";
}
if (process.arch === "ia32" && process.env.hasOwnProperty("PROCESSOR_ARCHITEW6432")) {
return "mixed";
}

return "native";
};

let { platform } = process,
win32RegBinPath = {
native: "%windir%\\System32",
mixed: "%windir%\\sysnative\\cmd.exe /c %windir%\\System32",
"": "",
},
guid = {
darwin: "ioreg -rd1 -c IOPlatformExpertDevice",
win32: `${win32RegBinPath[isWindowsProcessMixedOrNativeArchitecture()]}\\REG ` +
"QUERY HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography " +
"/v MachineGuid",
linux: "( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :",
freebsd: "kenv -q smbios.system.uuid || sysctl -n kern.hostuuid",
// tslint:disable-next-line:no-any
} as any;

const hash = (guid: string): string => {
return createHash("sha256").update(guid).digest("hex");
};

const expose = (result: string): string => {
switch (platform) {
case "darwin":
return result
.split("IOPlatformUUID")[1]
.split("\n")[0].replace(/\=|\s+|\"/ig, "")
.toLowerCase();
case "win32":
return result
.toString()
.split("REG_SZ")[1]
.replace(/\r+|\n+|\s+/ig, "")
.toLowerCase();
case "linux":
return result
.toString()
.replace(/\r+|\n+|\s+/ig, "")
.toLowerCase();
case "freebsd":
return result
.toString()
.replace(/\r+|\n+|\s+/ig, "")
.toLowerCase();
default:
throw new Error(`Unsupported platform: ${process.platform}`);
}
};

let cachedMachineId: string | undefined;

const machineIdSync = (): string => {
if (cachedMachineId) {
return cachedMachineId;
}
let id: string = expose(execSync(guid[platform]).toString());
cachedMachineId = hash(id);

return cachedMachineId;
};
9 changes: 8 additions & 1 deletion packages/vscode/src/fill/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class Product implements IProductConfiguration {
public tipsAndTricksUrl = "https://code.visualstudio.com/docs/getstarted/tips-and-tricks";
public twitterUrl = "https://twitter.com/code";
public licenseUrl = "https://github.com/codercom/code-server/blob/master/LICENSE";
public aiConfig = process.env.DISABLE_TELEMETRY ? undefined! : {
// Only needed so vscode can see that content exists for this value.
// We override the application insights module.
asimovKey: "content",
};
public enableTelemetry = process.env.DISABLE_TELEMETRY ? false : true;

private _dataFolderName: string | undefined;
public get dataFolderName(): string {
Expand All @@ -26,7 +32,8 @@ class Product implements IProductConfiguration {
serviceUrl: global && global.process && global.process.env.SERVICE_URL
|| process.env.SERVICE_URL
|| "https://v1.extapi.coder.com",
};
// tslint:disable-next-line:no-any
} as any;

public extensionExecutionEnvironments = {
"wayou.vscode-todo-highlight": "worker",
Expand Down
1 change: 1 addition & 0 deletions packages/vscode/webpack.bootstrap.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module.exports = merge(
"vscode-sqlite3": path.resolve(fills, "empty.ts"),
"vs/base/browser/browser": path.resolve(fills, "empty.ts"),

"applicationinsights": path.join(vsFills, "applicationInsights.ts"),
"electron": path.join(vsFills, "stdioElectron.ts"),
"vscode-ripgrep": path.join(vsFills, "ripgrep.ts"),
"native-keymap": path.join(vsFills, "native-keymap.ts"),
Expand Down
0