@react-native-windows/telemetry 0.67.1 → 0.68.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib-commonjs/index.d.ts +5 -2
- package/lib-commonjs/index.js +14 -6
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/telemetry.d.ts +75 -20
- package/lib-commonjs/telemetry.js +284 -168
- package/lib-commonjs/telemetry.js.map +1 -1
- package/lib-commonjs/test/{sanitize.test.d.ts → basePropUtils.test.d.ts} +0 -0
- package/lib-commonjs/test/basePropUtils.test.js +116 -0
- package/lib-commonjs/test/basePropUtils.test.js.map +1 -0
- package/lib-commonjs/test/errorUtils.test.d.ts +7 -0
- package/lib-commonjs/test/errorUtils.test.js +159 -0
- package/lib-commonjs/test/errorUtils.test.js.map +1 -0
- package/lib-commonjs/test/projectUtils.test.d.ts +7 -0
- package/lib-commonjs/test/projectUtils.test.js +84 -0
- package/lib-commonjs/test/projectUtils.test.js.map +1 -0
- package/lib-commonjs/test/sanitizeUtils.test.d.ts +7 -0
- package/lib-commonjs/test/sanitizeUtils.test.js +94 -0
- package/lib-commonjs/test/sanitizeUtils.test.js.map +1 -0
- package/lib-commonjs/test/telemetry.test.d.ts +26 -0
- package/lib-commonjs/test/telemetry.test.js +469 -0
- package/lib-commonjs/test/telemetry.test.js.map +1 -0
- package/lib-commonjs/test/versionUtils.test.d.ts +7 -0
- package/lib-commonjs/test/versionUtils.test.js +111 -0
- package/lib-commonjs/test/versionUtils.test.js.map +1 -0
- package/lib-commonjs/utils/basePropUtils.d.ts +66 -0
- package/lib-commonjs/utils/basePropUtils.js +131 -0
- package/lib-commonjs/utils/basePropUtils.js.map +1 -0
- package/lib-commonjs/{CodedError.d.ts → utils/errorUtils.d.ts} +27 -8
- package/lib-commonjs/utils/errorUtils.js +164 -0
- package/lib-commonjs/utils/errorUtils.js.map +1 -0
- package/lib-commonjs/utils/optionUtils.d.ts +45 -0
- package/lib-commonjs/utils/optionUtils.js +96 -0
- package/lib-commonjs/utils/optionUtils.js.map +1 -0
- package/lib-commonjs/utils/projectUtils.d.ts +50 -0
- package/lib-commonjs/utils/projectUtils.js +187 -0
- package/lib-commonjs/utils/projectUtils.js.map +1 -0
- package/lib-commonjs/utils/sanitizeUtils.d.ts +12 -0
- package/lib-commonjs/utils/sanitizeUtils.js +82 -0
- package/lib-commonjs/utils/sanitizeUtils.js.map +1 -0
- package/lib-commonjs/utils/versionUtils.d.ts +38 -0
- package/lib-commonjs/utils/versionUtils.js +156 -0
- package/lib-commonjs/utils/versionUtils.js.map +1 -0
- package/package.json +20 -9
- package/CHANGELOG.json +0 -618
- package/CHANGELOG.md +0 -260
- package/lib-commonjs/CodedError.js +0 -77
- package/lib-commonjs/CodedError.js.map +0 -1
- package/lib-commonjs/test/sanitize.test.js +0 -259
- package/lib-commonjs/test/sanitize.test.js.map +0 -1
package/lib-commonjs/index.d.ts
CHANGED
|
@@ -3,5 +3,8 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
* @format
|
|
5
5
|
*/
|
|
6
|
-
export { Telemetry,
|
|
7
|
-
export { CodedError, CodedErrorType, CodedErrors } from './
|
|
6
|
+
export { Telemetry, TelemetryOptions, CommandStartInfo, CommandEndInfo, } from './telemetry';
|
|
7
|
+
export { CodedError, CodedErrorType, CodedErrors } from './utils/errorUtils';
|
|
8
|
+
export { yargsOptionsToOptions, commanderNameToOptionName, commanderOptionsToOptions, optionsToArgs, OptionSanitizer, YargsOptionsType, CommanderOptionsType, } from './utils/optionUtils';
|
|
9
|
+
export { configToProjectInfo, getProjectFileFromConfig, AppProjectInfo, DependencyProjectInfo, } from './utils/projectUtils';
|
|
10
|
+
export { getVersionOfNpmPackage } from './utils/versionUtils';
|
package/lib-commonjs/index.js
CHANGED
|
@@ -5,12 +5,20 @@
|
|
|
5
5
|
* @format
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.
|
|
8
|
+
exports.getVersionOfNpmPackage = exports.getProjectFileFromConfig = exports.configToProjectInfo = exports.optionsToArgs = exports.commanderOptionsToOptions = exports.commanderNameToOptionName = exports.yargsOptionsToOptions = exports.CodedErrors = exports.CodedError = exports.Telemetry = void 0;
|
|
9
9
|
var telemetry_1 = require("./telemetry");
|
|
10
10
|
Object.defineProperty(exports, "Telemetry", { enumerable: true, get: function () { return telemetry_1.Telemetry; } });
|
|
11
|
-
|
|
12
|
-
Object.defineProperty(exports, "
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Object.defineProperty(exports, "
|
|
11
|
+
var errorUtils_1 = require("./utils/errorUtils");
|
|
12
|
+
Object.defineProperty(exports, "CodedError", { enumerable: true, get: function () { return errorUtils_1.CodedError; } });
|
|
13
|
+
Object.defineProperty(exports, "CodedErrors", { enumerable: true, get: function () { return errorUtils_1.CodedErrors; } });
|
|
14
|
+
var optionUtils_1 = require("./utils/optionUtils");
|
|
15
|
+
Object.defineProperty(exports, "yargsOptionsToOptions", { enumerable: true, get: function () { return optionUtils_1.yargsOptionsToOptions; } });
|
|
16
|
+
Object.defineProperty(exports, "commanderNameToOptionName", { enumerable: true, get: function () { return optionUtils_1.commanderNameToOptionName; } });
|
|
17
|
+
Object.defineProperty(exports, "commanderOptionsToOptions", { enumerable: true, get: function () { return optionUtils_1.commanderOptionsToOptions; } });
|
|
18
|
+
Object.defineProperty(exports, "optionsToArgs", { enumerable: true, get: function () { return optionUtils_1.optionsToArgs; } });
|
|
19
|
+
var projectUtils_1 = require("./utils/projectUtils");
|
|
20
|
+
Object.defineProperty(exports, "configToProjectInfo", { enumerable: true, get: function () { return projectUtils_1.configToProjectInfo; } });
|
|
21
|
+
Object.defineProperty(exports, "getProjectFileFromConfig", { enumerable: true, get: function () { return projectUtils_1.getProjectFileFromConfig; } });
|
|
22
|
+
var versionUtils_1 = require("./utils/versionUtils");
|
|
23
|
+
Object.defineProperty(exports, "getVersionOfNpmPackage", { enumerable: true, get: function () { return versionUtils_1.getVersionOfNpmPackage; } });
|
|
16
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,yCAKqB;AAJnB,sGAAA,SAAS,OAAA;AAMX,iDAA2E;AAAnE,wGAAA,UAAU,OAAA;AAAkB,yGAAA,WAAW,OAAA;AAE/C,mDAQ6B;AAP3B,oHAAA,qBAAqB,OAAA;AACrB,wHAAA,yBAAyB,OAAA;AACzB,wHAAA,yBAAyB,OAAA;AACzB,4GAAA,aAAa,OAAA;AAMf,qDAK8B;AAJ5B,mHAAA,mBAAmB,OAAA;AACnB,wHAAA,wBAAwB,OAAA;AAK1B,qDAA4D;AAApD,sHAAA,sBAAsB,OAAA","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\nexport {\n Telemetry,\n TelemetryOptions,\n CommandStartInfo,\n CommandEndInfo,\n} from './telemetry';\n\nexport {CodedError, CodedErrorType, CodedErrors} from './utils/errorUtils';\n\nexport {\n yargsOptionsToOptions,\n commanderNameToOptionName,\n commanderOptionsToOptions,\n optionsToArgs,\n OptionSanitizer,\n YargsOptionsType,\n CommanderOptionsType,\n} from './utils/optionUtils';\n\nexport {\n configToProjectInfo,\n getProjectFileFromConfig,\n AppProjectInfo,\n DependencyProjectInfo,\n} from './utils/projectUtils';\n\nexport {getVersionOfNpmPackage} from './utils/versionUtils';\n"]}
|
|
@@ -4,26 +4,81 @@
|
|
|
4
4
|
* @format
|
|
5
5
|
*/
|
|
6
6
|
import * as appInsights from 'applicationinsights';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
static shouldDisable: boolean;
|
|
14
|
-
static preserveMessages: boolean;
|
|
7
|
+
import * as errorUtils from './utils/errorUtils';
|
|
8
|
+
import * as projectUtils from './utils/projectUtils';
|
|
9
|
+
export interface TelemetryOptions {
|
|
10
|
+
setupString: string;
|
|
11
|
+
preserveErrorMessages: boolean;
|
|
12
|
+
populateNpmPackageVersions: boolean;
|
|
15
13
|
}
|
|
14
|
+
export interface CommandStartInfo {
|
|
15
|
+
commandName: string;
|
|
16
|
+
args: Record<string, any>;
|
|
17
|
+
options: Record<string, any>;
|
|
18
|
+
defaultOptions: Record<string, any>;
|
|
19
|
+
}
|
|
20
|
+
export interface CommandEndInfo {
|
|
21
|
+
resultCode: errorUtils.CodedErrorType;
|
|
22
|
+
}
|
|
23
|
+
interface CommandInfo {
|
|
24
|
+
startTime?: number;
|
|
25
|
+
endTime?: number;
|
|
26
|
+
startInfo?: CommandStartInfo;
|
|
27
|
+
endInfo?: CommandEndInfo;
|
|
28
|
+
}
|
|
29
|
+
export declare const CommandEventName = "RNWCLI.Command";
|
|
30
|
+
export declare const CodedErrorEventName = "RNWCLI.CodedError";
|
|
31
|
+
export declare const EventNamesWeTrack: string[];
|
|
32
|
+
export declare const NpmPackagesWeTrack: string[];
|
|
33
|
+
export declare const NuGetPackagesWeTrack: string[];
|
|
16
34
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @param msg the string to sanitize
|
|
19
|
-
*/
|
|
20
|
-
export declare function sanitizeMessage(msg: string): string;
|
|
21
|
-
export declare function sanitizeFrame(frame: any): void;
|
|
22
|
-
export declare function tryGetErrorCode(msg: string): string | undefined;
|
|
23
|
-
/**
|
|
24
|
-
* Remove PII from exceptions' stack traces and messages
|
|
25
|
-
* @param envelope the telemetry envelope. Provided by AppInsights.
|
|
35
|
+
* The Telemetry class is responsible for reporting telemetry for RNW CLI.
|
|
26
36
|
*/
|
|
27
|
-
export declare
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
export declare class Telemetry {
|
|
38
|
+
protected static client?: appInsights.TelemetryClient;
|
|
39
|
+
protected static options: TelemetryOptions;
|
|
40
|
+
protected static isTest: boolean;
|
|
41
|
+
protected static commandInfo: CommandInfo;
|
|
42
|
+
protected static versionsProp: Record<string, string>;
|
|
43
|
+
protected static projectProp?: projectUtils.AppProjectInfo | projectUtils.DependencyProjectInfo;
|
|
44
|
+
protected static getDefaultSetupString(): string;
|
|
45
|
+
protected static reset(): void;
|
|
46
|
+
static isEnabled(): boolean;
|
|
47
|
+
static getSessionId(): string;
|
|
48
|
+
/** Sets up the Telemetry static to be used elsewhere. */
|
|
49
|
+
static setup(options?: Partial<TelemetryOptions>): Promise<void>;
|
|
50
|
+
/** Sets up Telemetry.client. */
|
|
51
|
+
private static setupClient;
|
|
52
|
+
/** Sets up any base properties that all telemetry events require. */
|
|
53
|
+
private static setupBaseProperties;
|
|
54
|
+
/** Sets up any telemetry processors. */
|
|
55
|
+
private static setupTelemetryProcessors;
|
|
56
|
+
/**
|
|
57
|
+
* Performs the processing necessary (mostly PII sanitization) for all events.
|
|
58
|
+
* @param envelope The ApplicationInsights event envelope.
|
|
59
|
+
* @param _contextObjects An optional context object.
|
|
60
|
+
* @returns Whether to kee
|
|
61
|
+
*/
|
|
62
|
+
private static basicTelemetryProcessor;
|
|
63
|
+
/**
|
|
64
|
+
* Performs the processing necessary (mostly PII sanitization) for error events.
|
|
65
|
+
* @param envelope
|
|
66
|
+
* @param _contextObjects
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
private static errorTelemetryProcessor;
|
|
70
|
+
/** Tries to update the version of the named package/tool by calling getValue(). */
|
|
71
|
+
static tryUpdateVersionsProp(name: string, getValue: () => Promise<string | null>, forceRefresh?: boolean): Promise<boolean>;
|
|
72
|
+
/** Populates the versions property of tools we care to track. */
|
|
73
|
+
static populateToolsVersions(refresh?: boolean): Promise<void>;
|
|
74
|
+
/** Populates the versions property of npm packages we care to track. */
|
|
75
|
+
static populateNpmPackageVersions(refresh?: boolean): Promise<void>;
|
|
76
|
+
/** Populates the versions property of nuget packages we care to track. */
|
|
77
|
+
static populateNuGetPackageVersions(projectFile: string, refresh?: boolean): Promise<void>;
|
|
78
|
+
static setProjectInfo(info: projectUtils.AppProjectInfo | projectUtils.DependencyProjectInfo): void;
|
|
79
|
+
static startCommand(info: CommandStartInfo): void;
|
|
80
|
+
static endCommand(info: CommandEndInfo, extraProps?: Record<string, any>): void;
|
|
81
|
+
private static trackCommandEvent;
|
|
82
|
+
static trackException(error: Error, extraProps?: Record<string, any>): void;
|
|
83
|
+
}
|
|
84
|
+
export {};
|
|
@@ -23,202 +23,318 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
__setModuleDefault(result, mod);
|
|
24
24
|
return result;
|
|
25
25
|
};
|
|
26
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
-
};
|
|
29
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.
|
|
31
|
-
const path_1 = __importDefault(require("path"));
|
|
32
|
-
const crypto_1 = require("crypto");
|
|
27
|
+
exports.Telemetry = exports.NuGetPackagesWeTrack = exports.NpmPackagesWeTrack = exports.EventNamesWeTrack = exports.CodedErrorEventName = exports.CommandEventName = void 0;
|
|
33
28
|
const appInsights = __importStar(require("applicationinsights"));
|
|
34
|
-
const
|
|
35
|
-
const
|
|
29
|
+
const basePropUtils = __importStar(require("./utils/basePropUtils"));
|
|
30
|
+
const versionUtils = __importStar(require("./utils/versionUtils"));
|
|
31
|
+
const errorUtils = __importStar(require("./utils/errorUtils"));
|
|
32
|
+
// This is our key with the AI backend
|
|
33
|
+
const RNWSetupString = '795006ca-cf54-40ee-8bc6-03deb91401c3';
|
|
34
|
+
// Environment variable to override the default setup string
|
|
35
|
+
const ENV_SETUP_OVERRIDE = 'RNW_TELEMETRY_SETUP';
|
|
36
|
+
// Environment variable to override the http proxy (such as http://localhost:8888 for Fiddler debugging)
|
|
37
|
+
const ENV_PROXY_OVERRIDE = 'RNW_TELEMETRY_PROXY';
|
|
38
|
+
exports.CommandEventName = 'RNWCLI.Command';
|
|
39
|
+
exports.CodedErrorEventName = 'RNWCLI.CodedError';
|
|
40
|
+
// These are the event names we're tracking
|
|
41
|
+
exports.EventNamesWeTrack = [
|
|
42
|
+
exports.CommandEventName,
|
|
43
|
+
exports.CodedErrorEventName,
|
|
44
|
+
];
|
|
45
|
+
// These are NPM packages we care about, in terms of capturing versions used
|
|
46
|
+
// and getting more details about when reporting errors
|
|
47
|
+
exports.NpmPackagesWeTrack = [
|
|
48
|
+
'@react-native-community/cli',
|
|
49
|
+
'@react-native-windows/cli',
|
|
50
|
+
'@react-native-windows/telemetry',
|
|
51
|
+
'react',
|
|
52
|
+
'react-native',
|
|
53
|
+
'react-native-windows',
|
|
54
|
+
'react-native-windows-init',
|
|
55
|
+
];
|
|
56
|
+
// These are NPM packages we care about, in terms of capturing versions used
|
|
57
|
+
exports.NuGetPackagesWeTrack = [
|
|
58
|
+
'Microsoft.UI.Xaml',
|
|
59
|
+
'Microsoft.Windows.CppWinRT',
|
|
60
|
+
'Microsoft.WinUI',
|
|
61
|
+
];
|
|
62
|
+
/**
|
|
63
|
+
* The Telemetry class is responsible for reporting telemetry for RNW CLI.
|
|
64
|
+
*/
|
|
36
65
|
class Telemetry {
|
|
37
|
-
static
|
|
66
|
+
static getDefaultSetupString() {
|
|
67
|
+
var _a;
|
|
68
|
+
// Enable overriding the default setup string via an environment variable
|
|
69
|
+
return (_a = process.env[ENV_SETUP_OVERRIDE]) !== null && _a !== void 0 ? _a : RNWSetupString;
|
|
70
|
+
}
|
|
71
|
+
static reset() {
|
|
72
|
+
// Reset client
|
|
38
73
|
if (Telemetry.client) {
|
|
39
|
-
Telemetry.client.
|
|
74
|
+
Telemetry.client.flush();
|
|
75
|
+
Telemetry.client = undefined;
|
|
40
76
|
}
|
|
41
|
-
|
|
77
|
+
// Reset local members
|
|
78
|
+
Telemetry.options = {
|
|
79
|
+
setupString: Telemetry.getDefaultSetupString(),
|
|
80
|
+
preserveErrorMessages: false,
|
|
81
|
+
populateNpmPackageVersions: true,
|
|
82
|
+
};
|
|
83
|
+
Telemetry.commandInfo = {};
|
|
84
|
+
Telemetry.versionsProp = {};
|
|
85
|
+
Telemetry.projectProp = undefined;
|
|
42
86
|
}
|
|
43
|
-
static
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
87
|
+
static isEnabled() {
|
|
88
|
+
return Telemetry.client !== undefined;
|
|
89
|
+
}
|
|
90
|
+
static getSessionId() {
|
|
91
|
+
return basePropUtils.getSessionId();
|
|
92
|
+
}
|
|
93
|
+
/** Sets up the Telemetry static to be used elsewhere. */
|
|
94
|
+
static async setup(options) {
|
|
48
95
|
if (Telemetry.client) {
|
|
96
|
+
// Bail since we've already setup
|
|
49
97
|
return;
|
|
50
98
|
}
|
|
51
|
-
if
|
|
52
|
-
|
|
99
|
+
// Bail if we're in CI and not capturing CI
|
|
100
|
+
if (!this.isTest && basePropUtils.isCI() && !basePropUtils.captureCI()) {
|
|
101
|
+
return;
|
|
53
102
|
}
|
|
54
|
-
|
|
55
|
-
Telemetry.
|
|
56
|
-
|
|
57
|
-
|
|
103
|
+
// Save off options for later
|
|
104
|
+
Object.assign(Telemetry.options, options);
|
|
105
|
+
Telemetry.setupClient();
|
|
106
|
+
await Telemetry.setupBaseProperties();
|
|
107
|
+
Telemetry.setupTelemetryProcessors();
|
|
108
|
+
}
|
|
109
|
+
/** Sets up Telemetry.client. */
|
|
110
|
+
static setupClient() {
|
|
111
|
+
appInsights.Configuration.setInternalLogging(Telemetry.isTest, Telemetry.isTest);
|
|
112
|
+
Telemetry.client = new appInsights.TelemetryClient(Telemetry.options.setupString);
|
|
113
|
+
// Allow overriding the proxy server via an environment variable
|
|
114
|
+
const proxyServer = process.env[ENV_PROXY_OVERRIDE];
|
|
115
|
+
if (proxyServer) {
|
|
116
|
+
Telemetry.client.config.proxyHttpUrl = proxyServer;
|
|
117
|
+
Telemetry.client.config.proxyHttpsUrl = proxyServer;
|
|
58
118
|
}
|
|
59
|
-
Telemetry.
|
|
60
|
-
|
|
61
|
-
|
|
119
|
+
Telemetry.client.config.disableAppInsights = Telemetry.isTest;
|
|
120
|
+
Telemetry.client.channel.setUseDiskRetryCaching(!Telemetry.isTest);
|
|
121
|
+
}
|
|
122
|
+
/** Sets up any base properties that all telemetry events require. */
|
|
123
|
+
static async setupBaseProperties() {
|
|
124
|
+
Telemetry.client.commonProperties.deviceId =
|
|
125
|
+
await basePropUtils.deviceId();
|
|
126
|
+
Telemetry.client.commonProperties.deviceLocale =
|
|
127
|
+
await basePropUtils.deviceLocale();
|
|
128
|
+
Telemetry.client.commonProperties.deviceNumCPUs = basePropUtils
|
|
129
|
+
.deviceNumCPUs()
|
|
130
|
+
.toString();
|
|
131
|
+
Telemetry.client.commonProperties.deviceTotalMemory = basePropUtils
|
|
132
|
+
.deviceTotalMemory()
|
|
133
|
+
.toString();
|
|
134
|
+
Telemetry.client.commonProperties.deviceDiskFreeSpace = basePropUtils
|
|
135
|
+
.deviceDiskFreeSpace()
|
|
136
|
+
.toString();
|
|
137
|
+
Telemetry.client.commonProperties.ciCaptured = basePropUtils
|
|
138
|
+
.captureCI()
|
|
139
|
+
.toString();
|
|
140
|
+
Telemetry.client.commonProperties.ciType = basePropUtils.ciType();
|
|
141
|
+
Telemetry.client.commonProperties.isMsftInternal = basePropUtils
|
|
142
|
+
.isMsftInternal()
|
|
143
|
+
.toString();
|
|
144
|
+
Telemetry.client.config.samplingPercentage = basePropUtils.sampleRate();
|
|
145
|
+
if (Telemetry.isTest) {
|
|
146
|
+
Telemetry.client.commonProperties.isTest = true.toString();
|
|
62
147
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
148
|
+
Telemetry.client.commonProperties.sessionId = Telemetry.getSessionId();
|
|
149
|
+
await Telemetry.populateToolsVersions();
|
|
150
|
+
if (Telemetry.options.populateNpmPackageVersions) {
|
|
151
|
+
await Telemetry.populateNpmPackageVersions();
|
|
66
152
|
}
|
|
67
153
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
process.env.CI === 'true' // other CIs
|
|
73
|
-
);
|
|
154
|
+
/** Sets up any telemetry processors. */
|
|
155
|
+
static setupTelemetryProcessors() {
|
|
156
|
+
Telemetry.client.addTelemetryProcessor(Telemetry.basicTelemetryProcessor);
|
|
157
|
+
Telemetry.client.addTelemetryProcessor(Telemetry.errorTelemetryProcessor);
|
|
74
158
|
}
|
|
75
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Performs the processing necessary (mostly PII sanitization) for all events.
|
|
161
|
+
* @param envelope The ApplicationInsights event envelope.
|
|
162
|
+
* @param _contextObjects An optional context object.
|
|
163
|
+
* @returns Whether to kee
|
|
164
|
+
*/
|
|
165
|
+
static basicTelemetryProcessor(envelope, _contextObjects) {
|
|
76
166
|
var _a;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
167
|
+
delete envelope.tags['ai.cloud.roleInstance'];
|
|
168
|
+
// Filter out "legacy" events from older stable branches
|
|
169
|
+
const properties = (_a = envelope.data.baseData) === null || _a === void 0 ? void 0 : _a.properties;
|
|
170
|
+
if ((properties === null || properties === void 0 ? void 0 : properties.eventName) &&
|
|
171
|
+
exports.EventNamesWeTrack.includes(properties.eventName)) {
|
|
172
|
+
return true;
|
|
80
173
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Performs the processing necessary (mostly PII sanitization) for error events.
|
|
178
|
+
* @param envelope
|
|
179
|
+
* @param _contextObjects
|
|
180
|
+
* @returns
|
|
181
|
+
*/
|
|
182
|
+
static errorTelemetryProcessor(envelope, _contextObjects) {
|
|
183
|
+
if (envelope.data.baseType === 'ExceptionData') {
|
|
184
|
+
const data = envelope.data.baseData;
|
|
185
|
+
if (data === null || data === void 0 ? void 0 : data.exceptions) {
|
|
186
|
+
for (const exception of data.exceptions) {
|
|
187
|
+
for (const frame of exception.parsedStack) {
|
|
188
|
+
errorUtils.sanitizeErrorStackFrame(frame);
|
|
189
|
+
}
|
|
190
|
+
// CodedError has non-PII information in its 'type' member, plus optionally some more info in its 'data'.
|
|
191
|
+
// The message may contain PII information. This can be sanitized, but for now delete it.
|
|
192
|
+
// Note that the type of data.exceptions[0] is always going to be ExceptionDetails. It is not the original thrown exception.
|
|
193
|
+
// https://github.com/microsoft/ApplicationInsights-node.js/issues/707
|
|
194
|
+
if (Telemetry.options.preserveErrorMessages) {
|
|
195
|
+
exception.message = errorUtils.sanitizeErrorMessage(exception.message);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
delete exception.message;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
85
201
|
}
|
|
86
202
|
}
|
|
87
|
-
|
|
88
|
-
(_a = Telemetry.client) === null || _a === void 0 ? void 0 : _a.trackException({
|
|
89
|
-
exception: e,
|
|
90
|
-
properties: props,
|
|
91
|
-
});
|
|
203
|
+
return true;
|
|
92
204
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
Telemetry.client
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const ext = path_1.default.extname(filepath);
|
|
104
|
-
const rest = filepath.slice(projectRoot.length);
|
|
105
|
-
const nodeModules = '\\node_modules\\';
|
|
106
|
-
// this is in the project dir but not under node_modules
|
|
107
|
-
if (rest.toLowerCase().startsWith('\\windows\\')) {
|
|
108
|
-
return `[windows]\\???${ext}(${filepath.length})`;
|
|
109
|
-
}
|
|
110
|
-
else if (rest.toLowerCase().startsWith(nodeModules)) {
|
|
111
|
-
return 'node_modules' + rest.slice(nodeModules.length - 1);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
return `[project_dir]\\???${ext}(${filepath.length})`;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
for (const knownPath of knownPathsVars) {
|
|
119
|
-
if (process.env[knownPath] &&
|
|
120
|
-
filepath.toLowerCase().startsWith(process.env[knownPath].toLowerCase())) {
|
|
121
|
-
return `[${knownPath}]\\???(${filepath.length})`;
|
|
205
|
+
/** Tries to update the version of the named package/tool by calling getValue(). */
|
|
206
|
+
static async tryUpdateVersionsProp(name, getValue, forceRefresh) {
|
|
207
|
+
if (!Telemetry.client) {
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
if (forceRefresh === true || !Telemetry.versionsProp[name]) {
|
|
211
|
+
const value = await getValue();
|
|
212
|
+
if (value) {
|
|
213
|
+
Telemetry.versionsProp[name] = value;
|
|
214
|
+
return true;
|
|
122
215
|
}
|
|
123
216
|
}
|
|
217
|
+
return false;
|
|
124
218
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const pathRegEx = /([A-Za-z]:|\\)[\\/]([^<>:;,?"*\t\r\n|/\\]+[\\/])+([^<>:;,?"*\t\r\n|]+\/?)/gi;
|
|
137
|
-
for (const part of parts) {
|
|
138
|
-
if (pathRegEx.test(part)) {
|
|
139
|
-
pathRegEx.lastIndex = -1;
|
|
140
|
-
let matches;
|
|
141
|
-
let noPath = '';
|
|
142
|
-
let last = 0;
|
|
143
|
-
while ((matches = pathRegEx.exec(part))) {
|
|
144
|
-
noPath +=
|
|
145
|
-
part.substr(last, matches.index - last) +
|
|
146
|
-
getAnonymizedPath(matches[0]);
|
|
147
|
-
last = matches.index + matches[0].length;
|
|
148
|
-
}
|
|
149
|
-
clean.push(noPath);
|
|
219
|
+
/** Populates the versions property of tools we care to track. */
|
|
220
|
+
static async populateToolsVersions(refresh) {
|
|
221
|
+
await Telemetry.tryUpdateVersionsProp('node', versionUtils.getNodeVersion, refresh);
|
|
222
|
+
await Telemetry.tryUpdateVersionsProp('npm', versionUtils.getNpmVersion, refresh);
|
|
223
|
+
await Telemetry.tryUpdateVersionsProp('yarn', versionUtils.getYarnVersion, refresh);
|
|
224
|
+
await Telemetry.tryUpdateVersionsProp('VisualStudio', versionUtils.getVisualStudioVersion, refresh);
|
|
225
|
+
}
|
|
226
|
+
/** Populates the versions property of npm packages we care to track. */
|
|
227
|
+
static async populateNpmPackageVersions(refresh) {
|
|
228
|
+
for (const npmPackage of exports.NpmPackagesWeTrack) {
|
|
229
|
+
await Telemetry.tryUpdateVersionsProp(npmPackage, async () => await versionUtils.getVersionOfNpmPackage(npmPackage), refresh);
|
|
150
230
|
}
|
|
151
|
-
|
|
152
|
-
|
|
231
|
+
}
|
|
232
|
+
/** Populates the versions property of nuget packages we care to track. */
|
|
233
|
+
static async populateNuGetPackageVersions(projectFile, refresh) {
|
|
234
|
+
const nugetVersions = await versionUtils.getVersionsOfNuGetPackages(projectFile, exports.NuGetPackagesWeTrack);
|
|
235
|
+
for (const nugetPackage of exports.NuGetPackagesWeTrack) {
|
|
236
|
+
await Telemetry.tryUpdateVersionsProp(nugetPackage, async () => nugetVersions[nugetPackage], refresh);
|
|
153
237
|
}
|
|
154
238
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
239
|
+
static setProjectInfo(info) {
|
|
240
|
+
if (!Telemetry.client) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
Telemetry.projectProp = info;
|
|
244
|
+
}
|
|
245
|
+
static startCommand(info) {
|
|
246
|
+
if (!Telemetry.client) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (Telemetry.commandInfo.startInfo) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
Telemetry.commandInfo.startTime = Date.now();
|
|
253
|
+
Telemetry.commandInfo.startInfo = info;
|
|
254
|
+
// Set common command props
|
|
255
|
+
Telemetry.client.commonProperties.commandName = info.commandName;
|
|
256
|
+
}
|
|
257
|
+
static endCommand(info, extraProps) {
|
|
258
|
+
if (!Telemetry.client) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (!Telemetry.commandInfo.startInfo) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
Telemetry.commandInfo.endTime = Date.now();
|
|
265
|
+
Telemetry.commandInfo.endInfo = info;
|
|
266
|
+
Telemetry.trackCommandEvent(extraProps);
|
|
267
|
+
}
|
|
268
|
+
static trackCommandEvent(extraProps) {
|
|
269
|
+
var _a, _b, _c, _d;
|
|
270
|
+
const props = {
|
|
271
|
+
eventName: exports.CommandEventName,
|
|
272
|
+
};
|
|
273
|
+
// Set command props
|
|
274
|
+
props.command = {
|
|
275
|
+
options: (_a = Telemetry.commandInfo.startInfo) === null || _a === void 0 ? void 0 : _a.options,
|
|
276
|
+
defaultOptions: (_b = Telemetry.commandInfo.startInfo) === null || _b === void 0 ? void 0 : _b.defaultOptions,
|
|
277
|
+
args: (_c = Telemetry.commandInfo.startInfo) === null || _c === void 0 ? void 0 : _c.args,
|
|
278
|
+
durationInSecs: (Telemetry.commandInfo.endTime - Telemetry.commandInfo.startTime) /
|
|
279
|
+
1000,
|
|
280
|
+
resultCode: (_d = Telemetry.commandInfo.endInfo) === null || _d === void 0 ? void 0 : _d.resultCode,
|
|
281
|
+
};
|
|
282
|
+
// Set remaining common props
|
|
283
|
+
Object.assign(props, extraProps);
|
|
284
|
+
props.project = Telemetry.projectProp;
|
|
285
|
+
props.versions = Telemetry.versionsProp;
|
|
286
|
+
// Fire event
|
|
287
|
+
Telemetry.client.trackEvent({ name: props.eventName, properties: props });
|
|
288
|
+
Telemetry.client.flush();
|
|
289
|
+
}
|
|
290
|
+
static trackException(error, extraProps) {
|
|
291
|
+
var _a, _b, _c;
|
|
292
|
+
if (!Telemetry.client) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const props = {
|
|
296
|
+
eventName: exports.CodedErrorEventName,
|
|
297
|
+
};
|
|
298
|
+
// Save off CodedError info
|
|
299
|
+
const codedError = error instanceof errorUtils.CodedError
|
|
300
|
+
? error
|
|
301
|
+
: null;
|
|
302
|
+
props.codedError = {
|
|
303
|
+
type: (_a = codedError === null || codedError === void 0 ? void 0 : codedError.type) !== null && _a !== void 0 ? _a : 'Unknown',
|
|
304
|
+
rawErrorCode: (_b = errorUtils.tryGetErrorCode(error.message)) !== null && _b !== void 0 ? _b : '',
|
|
305
|
+
data: (_c = codedError === null || codedError === void 0 ? void 0 : codedError.data) !== null && _c !== void 0 ? _c : {},
|
|
306
|
+
};
|
|
307
|
+
if (codedError === null || codedError === void 0 ? void 0 : codedError.data) {
|
|
308
|
+
Object.assign(props.codedError.data, codedError.data);
|
|
309
|
+
}
|
|
310
|
+
// Copy miscellaneous system error fields into the codedError.data object
|
|
311
|
+
const syscallExceptionFieldsToCopy = ['errno', 'syscall', 'code'];
|
|
312
|
+
for (const f of syscallExceptionFieldsToCopy) {
|
|
313
|
+
if (error[f]) {
|
|
314
|
+
props.codedError.data[f] = error[f];
|
|
200
315
|
}
|
|
201
316
|
}
|
|
317
|
+
// Set remaining common props
|
|
318
|
+
Object.assign(props, extraProps);
|
|
319
|
+
props.project = Telemetry.projectProp;
|
|
320
|
+
props.versions = Telemetry.versionsProp;
|
|
321
|
+
// Fire event
|
|
322
|
+
Telemetry.client.trackException({
|
|
323
|
+
exception: error,
|
|
324
|
+
properties: props,
|
|
325
|
+
});
|
|
326
|
+
Telemetry.client.flush();
|
|
202
327
|
}
|
|
203
|
-
delete envelope.tags['ai.cloud.roleInstance'];
|
|
204
|
-
return true;
|
|
205
|
-
}
|
|
206
|
-
exports.sanitizeEnvelope = sanitizeEnvelope;
|
|
207
|
-
function isMSFTInternal() {
|
|
208
|
-
return (process.env.UserDNSDomain !== undefined &&
|
|
209
|
-
process.env.UserDNSDomain.toLowerCase().endsWith('.microsoft.com'));
|
|
210
|
-
}
|
|
211
|
-
exports.isMSFTInternal = isMSFTInternal;
|
|
212
|
-
function getDiskFreeSpace(drivePath) {
|
|
213
|
-
const out = (0, child_process_1.execSync)(`dir /-C ${drivePath}`)
|
|
214
|
-
.toString()
|
|
215
|
-
.split('\r\n');
|
|
216
|
-
const line = out[out.length - 2];
|
|
217
|
-
const result = line.match(/(\d+) [^\d]+(\d+) /);
|
|
218
|
-
if (result && result.length > 2) {
|
|
219
|
-
return Number(result[2]);
|
|
220
|
-
}
|
|
221
|
-
return -1;
|
|
222
328
|
}
|
|
223
|
-
exports.
|
|
329
|
+
exports.Telemetry = Telemetry;
|
|
330
|
+
Telemetry.client = undefined;
|
|
331
|
+
Telemetry.options = {
|
|
332
|
+
setupString: Telemetry.getDefaultSetupString(),
|
|
333
|
+
preserveErrorMessages: false,
|
|
334
|
+
populateNpmPackageVersions: true,
|
|
335
|
+
};
|
|
336
|
+
Telemetry.isTest = basePropUtils.isCliTest();
|
|
337
|
+
Telemetry.commandInfo = {};
|
|
338
|
+
Telemetry.versionsProp = {};
|
|
339
|
+
Telemetry.projectProp = undefined;
|
|
224
340
|
//# sourceMappingURL=telemetry.js.map
|