forked from microsoft/vscode-cpptools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
telemetry.ts
61 lines (52 loc) · 1.97 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
61
/* --------------------------------------------------------------------------------------------
* 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;
}
let telemetryReporter: TelemetryReporter | null;
const appInsightsKey: string = "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217";
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 {
if (telemetryReporter) {
const eventNamePrefix: string = "cppdbg/VS/Diagnostics/Debugger/";
telemetryReporter.sendTelemetryEvent(eventNamePrefix + eventName, properties);
}
}
export function logLanguageServerEvent(eventName: string, properties?: { [key: string]: string }, metrics?: { [key: string]: number }): void {
if (telemetryReporter) {
const eventNamePrefix: string = "C_Cpp/LanguageServer/";
telemetryReporter.sendTelemetryEvent(eventNamePrefix + eventName, properties, metrics);
}
}
function createReporter(): TelemetryReporter | null {
if (util.extensionContext) {
const packageInfo: IPackageInfo = getPackageInfo();
if (packageInfo) {
return new TelemetryReporter(packageInfo.name, packageInfo.version, appInsightsKey);
}
}
return null;
}
function getPackageInfo(): IPackageInfo {
return {
name: util.packageJson.publisher + "." + util.packageJson.name,
version: util.packageJson.version
};
}