add telemetry to the typescript extension
This commit is contained in:
parent
eaba095155
commit
0a90859d90
5 changed files with 60 additions and 1 deletions
|
@ -6,6 +6,7 @@
|
|||
"author": "Microsoft Corporation",
|
||||
"license": "MIT",
|
||||
"publisher": "vscode",
|
||||
"aiKey":"AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
|
||||
"engines": {
|
||||
"vscode": "*"
|
||||
},
|
||||
|
|
|
@ -18,6 +18,8 @@ import { ITypescriptServiceClient, ITypescriptServiceClientHost } from './types
|
|||
|
||||
import * as VersionStatus from './utils/versionStatus';
|
||||
|
||||
import TelemetryReporter from 'vscode-extension-telemetry';
|
||||
|
||||
interface CallbackItem {
|
||||
c: (value: any) => void;
|
||||
e: (err: any) => void;
|
||||
|
@ -34,6 +36,12 @@ interface RequestItem {
|
|||
callbacks: CallbackItem;
|
||||
}
|
||||
|
||||
interface IPackageInfo {
|
||||
name: string;
|
||||
version: string;
|
||||
aiKey: string;
|
||||
}
|
||||
|
||||
export default class TypeScriptServiceClient implements ITypescriptServiceClient {
|
||||
|
||||
public static Trace: boolean = process.env.TSS_TRACE || false;
|
||||
|
@ -56,6 +64,9 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
|||
private pendingResponses: number;
|
||||
private callbacks: CallbackMap;
|
||||
|
||||
private _packageInfo: IPackageInfo;
|
||||
private telemetryReporter: TelemetryReporter;
|
||||
|
||||
constructor(host: ITypescriptServiceClientHost) {
|
||||
this.host = host;
|
||||
this.pathSeparator = path.sep;
|
||||
|
@ -83,6 +94,9 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
|||
this.startService();
|
||||
}
|
||||
});
|
||||
if (this.packageInfo && this.packageInfo.aiKey) {
|
||||
this.telemetryReporter = new TelemetryReporter(this.packageInfo.name, this.packageInfo.version, this.packageInfo.aiKey);
|
||||
}
|
||||
this.startService();
|
||||
}
|
||||
|
||||
|
@ -94,6 +108,32 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
|||
return TypeScriptServiceClient.Trace;
|
||||
}
|
||||
|
||||
private get packageInfo(): IPackageInfo {
|
||||
|
||||
if (this._packageInfo !== undefined) {
|
||||
return this._packageInfo;
|
||||
}
|
||||
let packagePath = path.join(__dirname, './../package.json');
|
||||
let extensionPackage = require(packagePath);
|
||||
if (extensionPackage) {
|
||||
this._packageInfo = {
|
||||
name: extensionPackage.name,
|
||||
version: extensionPackage.version,
|
||||
aiKey: extensionPackage.aiKey
|
||||
};
|
||||
} else {
|
||||
this._packageInfo = null;
|
||||
}
|
||||
|
||||
return this._packageInfo;
|
||||
}
|
||||
|
||||
private logTelemetry(eventName: string, properties?: {[prop: string]: string}) {
|
||||
if (this.telemetryReporter) {
|
||||
this.telemetryReporter.sendTelemetryEvent(eventName, properties);
|
||||
}
|
||||
}
|
||||
|
||||
private service(): Promise<cp.ChildProcess> {
|
||||
if (this.servicePromise) {
|
||||
return this.servicePromise;
|
||||
|
@ -141,6 +181,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
|||
if (err) {
|
||||
this.lastError = err;
|
||||
window.showErrorMessage(`TypeScript language server couldn\'t be started. Error message is: ${err.message}`);
|
||||
this.logTelemetry('error', {message: err.message});
|
||||
return;
|
||||
}
|
||||
this.lastStart = Date.now();
|
||||
|
@ -212,6 +253,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
|||
} else if (diff < 2 * 1000 /* 2 seconds */) {
|
||||
startService = false;
|
||||
window.showErrorMessage('The Typesrript language service died 5 times right after it got started. The service will not be restarted. Please open a bug report.');
|
||||
this.logTelemetry('serviceExited');
|
||||
}
|
||||
}
|
||||
if (startService) {
|
||||
|
|
|
@ -26,3 +26,12 @@ declare var Console: {
|
|||
prototype: Console;
|
||||
new(): Console;
|
||||
};
|
||||
|
||||
declare var require: {
|
||||
toUrl(path: string): string;
|
||||
(moduleName: string): any;
|
||||
(dependencies: string[], callback: (...args: any[]) => any, errorback?: (err: any) => void): any;
|
||||
config(data: any): any;
|
||||
onError: Function;
|
||||
__$__nodeRequire<T>(moduleName: string): T;
|
||||
};
|
6
extensions/typescript/src/typings/vscode-extension-telemetry.d.ts
vendored
Normal file
6
extensions/typescript/src/typings/vscode-extension-telemetry.d.ts
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
declare module 'vscode-extension-telemetry' {
|
||||
export default class TelemetryReporter {
|
||||
constructor(extensionId: string,extensionVersion: string, key: string);
|
||||
sendTelemetryEvent(eventName: string, properties?: { [key: string]: string }, measures?: { [key: string]: number }): void;
|
||||
}
|
||||
}
|
|
@ -24,11 +24,12 @@
|
|||
"http-proxy-agent": "^0.2.6",
|
||||
"https-proxy-agent": "^0.3.5",
|
||||
"iconv-lite": "^0.4.13",
|
||||
"native-keymap": "^0.1.2",
|
||||
"sax": "^1.1.1",
|
||||
"semver": "^4.2.0",
|
||||
"vscode-debugprotocol": "^1.5.0",
|
||||
"vscode-extension-telemetry": "^0.0.4",
|
||||
"vscode-textmate": "^1.0.11",
|
||||
"native-keymap": "^0.1.2",
|
||||
"weak": "^1.0.1",
|
||||
"winreg": "0.0.12",
|
||||
"yauzl": "^2.3.1"
|
||||
|
|
Loading…
Reference in a new issue