@react-native-windows/telemetry 0.0.0-canary.9 → 0.0.0-canary.91

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