-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
telemetry.ts
60 lines (51 loc) · 1.92 KB
/
telemetry.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* See 'LICENSE' in the project root for license information.
* ------------------------------------------------------------------------------------------ */
'use strict';
import TelemetryReporter from 'vscode-extension-telemetry';
import * as util from './common';
interface IPackageInfo {
name: string;
version: string;
aiKey: string;
}
let telemetryReporter: TelemetryReporter;
export function activate(): void {
try {
telemetryReporter = createReporter();
} catch (e) {
// can't really do much about this
}
}
export function deactivate(): void {
if (telemetryReporter) {
telemetryReporter.dispose();
}
}
export function logDebuggerEvent(eventName: string, properties?: { [key: string]: string }): void {
const eventNamePrefix: string = "cppdbg/VS/Diagnostics/Debugger/";
if (telemetryReporter) {
telemetryReporter.sendTelemetryEvent(eventNamePrefix + eventName, properties);
}
}
export function logLanguageServerEvent(eventName: string, properties?: { [key: string]: string }, metrics?: { [key: string]: number }): void {
const eventNamePrefix: string = "C_Cpp/LanguageServer/";
if (telemetryReporter) {
telemetryReporter.sendTelemetryEvent(eventNamePrefix + eventName, properties, metrics);
}
}
function createReporter(): TelemetryReporter {
let packageInfo: IPackageInfo = getPackageInfo();
if (packageInfo && packageInfo.aiKey) {
return new TelemetryReporter(packageInfo.name, packageInfo.version, packageInfo.aiKey);
}
return null;
}
function getPackageInfo(): IPackageInfo {
return {
name: util.packageJson.publisher + "." + util.packageJson.name,
version: util.packageJson.version,
aiKey: util.packageJson.contributes.debuggers[0].aiKey
};
}