@react-native-windows/telemetry 0.0.0-canary.4 → 0.0.0-canary.40
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 -1
- package/lib-commonjs/index.js +15 -3
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/telemetry.d.ts +76 -12
- package/lib-commonjs/telemetry.js +351 -109
- 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 +132 -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 +166 -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 +88 -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 +98 -0
- package/lib-commonjs/test/sanitizeUtils.test.js.map +1 -0
- package/lib-commonjs/test/telemetry.test.d.ts +28 -0
- package/lib-commonjs/test/telemetry.test.js +504 -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 +115 -0
- package/lib-commonjs/test/versionUtils.test.js.map +1 -0
- package/lib-commonjs/utils/basePropUtils.d.ts +76 -0
- package/lib-commonjs/utils/basePropUtils.js +147 -0
- package/lib-commonjs/utils/basePropUtils.js.map +1 -0
- package/lib-commonjs/utils/errorUtils.d.ts +80 -0
- package/lib-commonjs/utils/errorUtils.js +170 -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 +35 -19
- package/CHANGELOG.json +0 -50
- package/CHANGELOG.md +0 -31
- package/lib-commonjs/test/sanitize.test.js +0 -187
- package/lib-commonjs/test/sanitize.test.js.map +0 -1
package/lib-commonjs/index.d.ts
CHANGED
|
@@ -3,4 +3,8 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
* @format
|
|
5
5
|
*/
|
|
6
|
-
export {
|
|
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,8 +5,20 @@
|
|
|
5
5
|
* @format
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.getVersionOfNpmPackage = exports.getProjectFileFromConfig = exports.configToProjectInfo = exports.optionsToArgs = exports.commanderOptionsToOptions = exports.commanderNameToOptionName = exports.yargsOptionsToOptions = exports.CodedErrors = exports.CodedError = exports.Telemetry = void 0;
|
|
8
9
|
var telemetry_1 = require("./telemetry");
|
|
9
|
-
Object.defineProperty(exports, "
|
|
10
|
-
|
|
11
|
-
Object.defineProperty(exports, "
|
|
10
|
+
Object.defineProperty(exports, "Telemetry", { enumerable: true, get: function () { return telemetry_1.Telemetry; } });
|
|
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; } });
|
|
12
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG
|
|
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,17 +4,81 @@
|
|
|
4
4
|
* @format
|
|
5
5
|
*/
|
|
6
6
|
import * as appInsights from 'applicationinsights';
|
|
7
|
-
|
|
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;
|
|
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[];
|
|
8
34
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @param msg the string to sanitize
|
|
35
|
+
* The Telemetry class is responsible for reporting telemetry for RNW CLI.
|
|
11
36
|
*/
|
|
12
|
-
export declare
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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 {};
|
|
@@ -4,125 +4,367 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
* @format
|
|
6
6
|
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
24
|
+
if (mod && mod.__esModule) return mod;
|
|
25
|
+
var result = {};
|
|
26
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
27
|
+
__setModuleDefault(result, mod);
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
7
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
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
|
-
|
|
31
|
+
exports.Telemetry = exports.NuGetPackagesWeTrack = exports.NpmPackagesWeTrack = exports.EventNamesWeTrack = exports.CodedErrorEventName = exports.CommandEventName = void 0;
|
|
32
|
+
const appInsights = __importStar(require("applicationinsights"));
|
|
33
|
+
const basePropUtils = __importStar(require("./utils/basePropUtils"));
|
|
34
|
+
const versionUtils = __importStar(require("./utils/versionUtils"));
|
|
35
|
+
const errorUtils = __importStar(require("./utils/errorUtils"));
|
|
36
|
+
// This is our key with the AI backend
|
|
37
|
+
const RNWSetupString = '795006ca-cf54-40ee-8bc6-03deb91401c3';
|
|
38
|
+
// Environment variable to override the default setup string
|
|
39
|
+
const ENV_SETUP_OVERRIDE = 'RNW_TELEMETRY_SETUP';
|
|
40
|
+
// Environment variable to override the http proxy (such as http://localhost:8888 for Fiddler debugging)
|
|
41
|
+
const ENV_PROXY_OVERRIDE = 'RNW_TELEMETRY_PROXY';
|
|
42
|
+
exports.CommandEventName = 'RNWCLI.Command';
|
|
43
|
+
exports.CodedErrorEventName = 'RNWCLI.CodedError';
|
|
44
|
+
// These are the event names we're tracking
|
|
45
|
+
exports.EventNamesWeTrack = [
|
|
46
|
+
exports.CommandEventName,
|
|
47
|
+
exports.CodedErrorEventName,
|
|
48
|
+
];
|
|
49
|
+
// These are NPM packages we care about, in terms of capturing versions used
|
|
50
|
+
// and getting more details about when reporting errors
|
|
51
|
+
exports.NpmPackagesWeTrack = [
|
|
52
|
+
'@react-native-community/cli',
|
|
53
|
+
'@react-native-windows/cli',
|
|
54
|
+
'@react-native-windows/telemetry',
|
|
55
|
+
'react',
|
|
56
|
+
'react-native',
|
|
57
|
+
'react-native-windows',
|
|
58
|
+
'react-native-windows-init',
|
|
59
|
+
];
|
|
60
|
+
// These are NPM packages we care about, in terms of capturing versions used
|
|
61
|
+
exports.NuGetPackagesWeTrack = [
|
|
62
|
+
'Microsoft.UI.Xaml',
|
|
63
|
+
'Microsoft.Windows.CppWinRT',
|
|
64
|
+
'Microsoft.WinUI',
|
|
65
|
+
];
|
|
66
|
+
/**
|
|
67
|
+
* The Telemetry class is responsible for reporting telemetry for RNW CLI.
|
|
68
|
+
*/
|
|
69
|
+
class Telemetry {
|
|
70
|
+
static getDefaultSetupString() {
|
|
71
|
+
var _a;
|
|
72
|
+
// Enable overriding the default setup string via an environment variable
|
|
73
|
+
return (_a = process.env[ENV_SETUP_OVERRIDE]) !== null && _a !== void 0 ? _a : RNWSetupString;
|
|
74
|
+
}
|
|
75
|
+
static reset() {
|
|
76
|
+
// Reset client
|
|
77
|
+
if (Telemetry.client) {
|
|
78
|
+
Telemetry.client.flush();
|
|
79
|
+
Telemetry.client = undefined;
|
|
80
|
+
}
|
|
81
|
+
// Reset local members
|
|
82
|
+
Telemetry.options = {
|
|
83
|
+
setupString: Telemetry.getDefaultSetupString(),
|
|
84
|
+
preserveErrorMessages: false,
|
|
85
|
+
populateNpmPackageVersions: true,
|
|
86
|
+
};
|
|
87
|
+
Telemetry.commandInfo = {};
|
|
88
|
+
Telemetry.versionsProp = {};
|
|
89
|
+
Telemetry.projectProp = undefined;
|
|
90
|
+
}
|
|
91
|
+
static isEnabled() {
|
|
92
|
+
return Telemetry.client !== undefined;
|
|
93
|
+
}
|
|
94
|
+
static getSessionId() {
|
|
95
|
+
return basePropUtils.getSessionId();
|
|
96
|
+
}
|
|
97
|
+
/** Sets up the Telemetry static to be used elsewhere. */
|
|
98
|
+
static async setup(options) {
|
|
99
|
+
if (Telemetry.client) {
|
|
100
|
+
// Bail since we've already setup
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
// Bail if we're in CI and not capturing CI
|
|
104
|
+
if (!this.isTest && basePropUtils.isCI() && !basePropUtils.captureCI()) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
// Save off options for later
|
|
108
|
+
Object.assign(Telemetry.options, options);
|
|
109
|
+
Telemetry.setupClient();
|
|
110
|
+
await Telemetry.setupBaseProperties();
|
|
111
|
+
Telemetry.setupTelemetryProcessors();
|
|
112
|
+
}
|
|
113
|
+
/** Sets up Telemetry.client. */
|
|
114
|
+
static setupClient() {
|
|
115
|
+
var _a;
|
|
116
|
+
appInsights.Configuration.setInternalLogging(false, false);
|
|
117
|
+
Telemetry.client = new appInsights.TelemetryClient(Telemetry.options.setupString);
|
|
118
|
+
// Allow overriding the proxy server via an environment variable
|
|
119
|
+
const proxyServer = process.env[ENV_PROXY_OVERRIDE];
|
|
120
|
+
if (proxyServer) {
|
|
121
|
+
Telemetry.client.config.proxyHttpUrl = proxyServer;
|
|
122
|
+
Telemetry.client.config.proxyHttpsUrl = proxyServer;
|
|
123
|
+
}
|
|
124
|
+
Telemetry.client.config.disableAppInsights = Telemetry.isTest;
|
|
125
|
+
Telemetry.client.config.disableStatsbeat = true;
|
|
126
|
+
// Despite trying to disable the statsbeat, it might still be running: https://github.com/microsoft/ApplicationInsights-node.js/issues/943
|
|
127
|
+
// So we want to disable it, and despite the method's typing, getStatsbeat() _can_ return undefined
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
129
|
+
(_a = Telemetry.client.getStatsbeat()) === null || _a === void 0 ? void 0 : _a.enable(false);
|
|
130
|
+
Telemetry.client.channel.setUseDiskRetryCaching(!Telemetry.isTest);
|
|
131
|
+
}
|
|
132
|
+
/** Sets up any base properties that all telemetry events require. */
|
|
133
|
+
static async setupBaseProperties() {
|
|
134
|
+
Telemetry.client.commonProperties.deviceId =
|
|
135
|
+
await basePropUtils.deviceId();
|
|
136
|
+
Telemetry.client.commonProperties.deviceArchitecture =
|
|
137
|
+
basePropUtils.deviceArchitecture();
|
|
138
|
+
Telemetry.client.commonProperties.devicePlatform =
|
|
139
|
+
basePropUtils.devicePlatform();
|
|
140
|
+
Telemetry.client.commonProperties.deviceLocale =
|
|
141
|
+
await basePropUtils.deviceLocale();
|
|
142
|
+
Telemetry.client.commonProperties.deviceNumCPUs = basePropUtils
|
|
143
|
+
.deviceNumCPUs()
|
|
144
|
+
.toString();
|
|
145
|
+
Telemetry.client.commonProperties.deviceTotalMemory = basePropUtils
|
|
146
|
+
.deviceTotalMemory()
|
|
147
|
+
.toString();
|
|
148
|
+
Telemetry.client.commonProperties.deviceDiskFreeSpace = basePropUtils
|
|
149
|
+
.deviceDiskFreeSpace()
|
|
150
|
+
.toString();
|
|
151
|
+
Telemetry.client.commonProperties.ciCaptured = basePropUtils
|
|
152
|
+
.captureCI()
|
|
153
|
+
.toString();
|
|
154
|
+
Telemetry.client.commonProperties.ciType = basePropUtils.ciType();
|
|
155
|
+
Telemetry.client.commonProperties.isMsftInternal = basePropUtils
|
|
156
|
+
.isMsftInternal()
|
|
157
|
+
.toString();
|
|
158
|
+
Telemetry.client.commonProperties.sampleRate = basePropUtils
|
|
159
|
+
.sampleRate()
|
|
160
|
+
.toString();
|
|
161
|
+
Telemetry.client.commonProperties.isTest = Telemetry.isTest.toString();
|
|
162
|
+
Telemetry.client.commonProperties.sessionId = Telemetry.getSessionId();
|
|
163
|
+
Telemetry.client.config.samplingPercentage = basePropUtils.sampleRate();
|
|
164
|
+
await Telemetry.populateToolsVersions();
|
|
165
|
+
if (Telemetry.options.populateNpmPackageVersions) {
|
|
166
|
+
await Telemetry.populateNpmPackageVersions();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** Sets up any telemetry processors. */
|
|
170
|
+
static setupTelemetryProcessors() {
|
|
171
|
+
Telemetry.client.addTelemetryProcessor(Telemetry.basicTelemetryProcessor);
|
|
172
|
+
Telemetry.client.addTelemetryProcessor(Telemetry.errorTelemetryProcessor);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Performs the processing necessary (mostly PII sanitization) for all events.
|
|
176
|
+
* @param envelope The ApplicationInsights event envelope.
|
|
177
|
+
* @param _contextObjects An optional context object.
|
|
178
|
+
* @returns Whether to kee
|
|
179
|
+
*/
|
|
180
|
+
static basicTelemetryProcessor(envelope, _contextObjects) {
|
|
181
|
+
var _a;
|
|
182
|
+
delete envelope.tags['ai.cloud.roleInstance'];
|
|
183
|
+
// Filter out "legacy" events from older stable branches
|
|
184
|
+
const properties = (_a = envelope.data.baseData) === null || _a === void 0 ? void 0 : _a.properties;
|
|
185
|
+
if ((properties === null || properties === void 0 ? void 0 : properties.eventName) &&
|
|
186
|
+
exports.EventNamesWeTrack.includes(properties.eventName)) {
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Performs the processing necessary (mostly PII sanitization) for error events.
|
|
193
|
+
* @param envelope
|
|
194
|
+
* @param _contextObjects
|
|
195
|
+
* @returns
|
|
196
|
+
*/
|
|
197
|
+
static errorTelemetryProcessor(envelope, _contextObjects) {
|
|
198
|
+
if (envelope.data.baseType === 'ExceptionData') {
|
|
199
|
+
const data = envelope.data.baseData;
|
|
200
|
+
if (data === null || data === void 0 ? void 0 : data.exceptions) {
|
|
201
|
+
for (const exception of data.exceptions) {
|
|
202
|
+
for (const frame of exception.parsedStack) {
|
|
203
|
+
errorUtils.sanitizeErrorStackFrame(frame);
|
|
204
|
+
}
|
|
205
|
+
// Exception message must never be blank, or AI will reject it
|
|
206
|
+
exception.message = exception.message || '[None]';
|
|
207
|
+
// CodedError has non-PII information in its 'type' member, plus optionally some more info in its 'data'.
|
|
208
|
+
// The message may contain PII information. This can be sanitized, but for now delete it.
|
|
209
|
+
// Note that the type of data.exceptions[0] is always going to be ExceptionDetails. It is not the original thrown exception.
|
|
210
|
+
// https://github.com/microsoft/ApplicationInsights-node.js/issues/707
|
|
211
|
+
if (Telemetry.options.preserveErrorMessages) {
|
|
212
|
+
exception.message = errorUtils.sanitizeErrorMessage(exception.message);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
exception.message = '[Removed]';
|
|
216
|
+
}
|
|
217
|
+
}
|
|
38
218
|
}
|
|
39
219
|
}
|
|
220
|
+
return true;
|
|
40
221
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
for (const part of parts) {
|
|
52
|
-
if (pathRegEx.test(part)) {
|
|
53
|
-
pathRegEx.lastIndex = -1;
|
|
54
|
-
let matches;
|
|
55
|
-
let noPath = '';
|
|
56
|
-
let last = 0;
|
|
57
|
-
while ((matches = pathRegEx.exec(part))) {
|
|
58
|
-
noPath +=
|
|
59
|
-
part.substr(last, matches.index - last) +
|
|
60
|
-
getAnonymizedPath(matches[0]);
|
|
61
|
-
last = matches.index + matches[0].length;
|
|
222
|
+
/** Tries to update the version of the named package/tool by calling getValue(). */
|
|
223
|
+
static async tryUpdateVersionsProp(name, getValue, forceRefresh) {
|
|
224
|
+
if (!Telemetry.client) {
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
if (forceRefresh === true || !Telemetry.versionsProp[name]) {
|
|
228
|
+
const value = await getValue();
|
|
229
|
+
if (value) {
|
|
230
|
+
Telemetry.versionsProp[name] = value;
|
|
231
|
+
return true;
|
|
62
232
|
}
|
|
63
|
-
clean.push(noPath);
|
|
64
233
|
}
|
|
65
|
-
|
|
66
|
-
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
/** Populates the versions property of tools we care to track. */
|
|
237
|
+
static async populateToolsVersions(refresh) {
|
|
238
|
+
await Telemetry.tryUpdateVersionsProp('node', versionUtils.getNodeVersion, refresh);
|
|
239
|
+
await Telemetry.tryUpdateVersionsProp('npm', versionUtils.getNpmVersion, refresh);
|
|
240
|
+
await Telemetry.tryUpdateVersionsProp('yarn', versionUtils.getYarnVersion, refresh);
|
|
241
|
+
await Telemetry.tryUpdateVersionsProp('VisualStudio', versionUtils.getVisualStudioVersion, refresh);
|
|
242
|
+
}
|
|
243
|
+
/** Populates the versions property of npm packages we care to track. */
|
|
244
|
+
static async populateNpmPackageVersions(refresh) {
|
|
245
|
+
for (const npmPackage of exports.NpmPackagesWeTrack) {
|
|
246
|
+
await Telemetry.tryUpdateVersionsProp(npmPackage, async () => await versionUtils.getVersionOfNpmPackage(npmPackage), refresh);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/** Populates the versions property of nuget packages we care to track. */
|
|
250
|
+
static async populateNuGetPackageVersions(projectFile, refresh) {
|
|
251
|
+
const nugetVersions = await versionUtils.getVersionsOfNuGetPackages(projectFile, exports.NuGetPackagesWeTrack);
|
|
252
|
+
for (const nugetPackage of exports.NuGetPackagesWeTrack) {
|
|
253
|
+
await Telemetry.tryUpdateVersionsProp(nugetPackage, async () => nugetVersions[nugetPackage], refresh);
|
|
67
254
|
}
|
|
68
255
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
256
|
+
static setProjectInfo(info) {
|
|
257
|
+
if (!Telemetry.client) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
Telemetry.projectProp = info;
|
|
261
|
+
}
|
|
262
|
+
static startCommand(info) {
|
|
263
|
+
if (!Telemetry.client) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (Telemetry.commandInfo.startInfo) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
Telemetry.commandInfo.startTime = Date.now();
|
|
270
|
+
Telemetry.commandInfo.startInfo = info;
|
|
271
|
+
// Set common command props
|
|
272
|
+
Telemetry.client.commonProperties.commandName = info.commandName;
|
|
273
|
+
}
|
|
274
|
+
static endCommand(info, extraProps) {
|
|
275
|
+
if (!Telemetry.client) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (!Telemetry.commandInfo.startInfo) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
Telemetry.commandInfo.endTime = Date.now();
|
|
282
|
+
Telemetry.commandInfo.endInfo = info;
|
|
283
|
+
Telemetry.trackCommandEvent(extraProps);
|
|
284
|
+
}
|
|
285
|
+
static trackCommandEvent(extraProps) {
|
|
286
|
+
var _a, _b, _c, _d;
|
|
287
|
+
const props = {
|
|
288
|
+
eventName: exports.CommandEventName,
|
|
289
|
+
};
|
|
290
|
+
// Set command props
|
|
291
|
+
props.command = {
|
|
292
|
+
options: (_a = Telemetry.commandInfo.startInfo) === null || _a === void 0 ? void 0 : _a.options,
|
|
293
|
+
defaultOptions: (_b = Telemetry.commandInfo.startInfo) === null || _b === void 0 ? void 0 : _b.defaultOptions,
|
|
294
|
+
args: (_c = Telemetry.commandInfo.startInfo) === null || _c === void 0 ? void 0 : _c.args,
|
|
295
|
+
durationInSecs: (Telemetry.commandInfo.endTime - Telemetry.commandInfo.startTime) /
|
|
296
|
+
1000,
|
|
297
|
+
resultCode: (_d = Telemetry.commandInfo.endInfo) === null || _d === void 0 ? void 0 : _d.resultCode,
|
|
298
|
+
};
|
|
299
|
+
// Set remaining common props
|
|
300
|
+
props.project = Telemetry.projectProp;
|
|
301
|
+
props.versions = Telemetry.versionsProp;
|
|
302
|
+
// Set extra props
|
|
303
|
+
props.extraProps = {};
|
|
304
|
+
Object.assign(props.extraProps, extraProps);
|
|
305
|
+
// Fire event
|
|
306
|
+
Telemetry.client.trackEvent({ name: props.eventName, properties: props });
|
|
307
|
+
Telemetry.client.flush();
|
|
308
|
+
}
|
|
309
|
+
static trackException(error, extraProps) {
|
|
310
|
+
var _a, _b;
|
|
311
|
+
if (!Telemetry.client) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const props = {
|
|
315
|
+
eventName: exports.CodedErrorEventName,
|
|
316
|
+
};
|
|
317
|
+
// Save off CodedError info
|
|
318
|
+
const codedError = error instanceof errorUtils.CodedError
|
|
319
|
+
? error
|
|
320
|
+
: null;
|
|
321
|
+
props.codedError = {
|
|
322
|
+
type: (_a = codedError === null || codedError === void 0 ? void 0 : codedError.type) !== null && _a !== void 0 ? _a : 'Unknown',
|
|
323
|
+
data: (_b = codedError === null || codedError === void 0 ? void 0 : codedError.data) !== null && _b !== void 0 ? _b : {},
|
|
324
|
+
};
|
|
325
|
+
// Copy msBuildErrorMessages into the codedError.data object
|
|
326
|
+
if (error.msBuildErrorMessages) {
|
|
327
|
+
// Always grab MSBuild error codes if possible
|
|
328
|
+
props.codedError.data.msBuildErrors = error.msBuildErrorMessages
|
|
329
|
+
.map(errorUtils.tryGetErrorCode)
|
|
330
|
+
.filter((msg) => msg);
|
|
331
|
+
// Grab sanitized MSBuild error messages if we're preserving them
|
|
332
|
+
if (Telemetry.options.preserveErrorMessages) {
|
|
333
|
+
props.codedError.data.msBuildErrorMessages = error.msBuildErrorMessages
|
|
334
|
+
.map(errorUtils.sanitizeErrorMessage)
|
|
335
|
+
.filter((msg) => msg);
|
|
96
336
|
}
|
|
97
|
-
exception.message = sanitizeMessage(exception.message);
|
|
98
337
|
}
|
|
338
|
+
// Copy miscellaneous system error fields into the codedError.data object
|
|
339
|
+
const syscallExceptionFieldsToCopy = ['errno', 'syscall', 'code'];
|
|
340
|
+
for (const f of syscallExceptionFieldsToCopy) {
|
|
341
|
+
if (error[f]) {
|
|
342
|
+
props.codedError.data[f] = error[f];
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
// Set remaining common props
|
|
346
|
+
props.project = Telemetry.projectProp;
|
|
347
|
+
props.versions = Telemetry.versionsProp;
|
|
348
|
+
// Set extra props
|
|
349
|
+
props.extraProps = {};
|
|
350
|
+
Object.assign(props.extraProps, extraProps);
|
|
351
|
+
// Fire event
|
|
352
|
+
Telemetry.client.trackException({
|
|
353
|
+
exception: error,
|
|
354
|
+
properties: props,
|
|
355
|
+
});
|
|
356
|
+
Telemetry.client.flush();
|
|
99
357
|
}
|
|
100
|
-
delete envelope.tags['ai.cloud.roleInstance'];
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
exports.sanitizeEnvelope = sanitizeEnvelope;
|
|
104
|
-
if (process.env.RNW_CLI_TEST) {
|
|
105
|
-
exports.telClient.commonProperties.isTest = process.env.RNW_CLI_TEST;
|
|
106
|
-
}
|
|
107
|
-
if (!exports.telClient.commonProperties.sessionId) {
|
|
108
|
-
exports.telClient.commonProperties.sessionId = crypto_1.randomBytes(16).toString('hex');
|
|
109
|
-
exports.telClient.addTelemetryProcessor(sanitizeEnvelope);
|
|
110
|
-
}
|
|
111
|
-
function isMSFTInternal() {
|
|
112
|
-
return (process.env.USERDNSDOMAIN !== undefined &&
|
|
113
|
-
process.env.USERDNSDOMAIN.endsWith('.microsoft.com'));
|
|
114
|
-
}
|
|
115
|
-
exports.isMSFTInternal = isMSFTInternal;
|
|
116
|
-
function getDiskFreeSpace(drivePath) {
|
|
117
|
-
const out = child_process_1.execSync(`dir /-C ${drivePath}`)
|
|
118
|
-
.toString()
|
|
119
|
-
.split('\r\n');
|
|
120
|
-
const line = out[out.length - 2];
|
|
121
|
-
const result = line.match(/(\d+) [^\d]+(\d+) /);
|
|
122
|
-
if (result && result.length > 2) {
|
|
123
|
-
return Number(result[2]);
|
|
124
|
-
}
|
|
125
|
-
return -1;
|
|
126
358
|
}
|
|
127
|
-
exports.
|
|
359
|
+
exports.Telemetry = Telemetry;
|
|
360
|
+
Telemetry.client = undefined;
|
|
361
|
+
Telemetry.options = {
|
|
362
|
+
setupString: Telemetry.getDefaultSetupString(),
|
|
363
|
+
preserveErrorMessages: false,
|
|
364
|
+
populateNpmPackageVersions: true,
|
|
365
|
+
};
|
|
366
|
+
Telemetry.isTest = basePropUtils.isCliTest();
|
|
367
|
+
Telemetry.commandInfo = {};
|
|
368
|
+
Telemetry.versionsProp = {};
|
|
369
|
+
Telemetry.projectProp = undefined;
|
|
128
370
|
//# sourceMappingURL=telemetry.js.map
|