@react-native-windows/telemetry 0.0.0-canary.11 → 0.0.0-canary.111

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 +26 -0
  2. package/lib-commonjs/e2etest/telemetry.test.js +489 -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 +74 -27
  8. package/lib-commonjs/telemetry.js +404 -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 +145 -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 +160 -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 +92 -0
  26. package/lib-commonjs/utils/basePropUtils.js +217 -0
  27. package/lib-commonjs/utils/basePropUtils.js.map +1 -0
  28. package/lib-commonjs/utils/errorUtils.d.ts +93 -0
  29. package/lib-commonjs/utils/errorUtils.js +183 -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 +85 -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 +40 -22
  44. package/CHANGELOG.json +0 -155
  45. package/CHANGELOG.md +0 -79
  46. package/lib-commonjs/test/sanitize.test.js +0 -220
  47. package/lib-commonjs/test/sanitize.test.js.map +0 -1
@@ -1,172 +1,405 @@
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 nodeModules = '\\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(nodeModules)) {
68
- return 'node_modules' + rest.slice(nodeModules.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 coreOneDS = __importStar(require("@microsoft/1ds-core-js"));
33
+ const _1ds_post_js_1 = require("@microsoft/1ds-post-js");
34
+ const basePropUtils = __importStar(require("./utils/basePropUtils"));
35
+ const versionUtils = __importStar(require("./utils/versionUtils"));
36
+ const errorUtils = __importStar(require("./utils/errorUtils"));
37
+ // 1DS instrumentation key
38
+ const RNW_1DS_INSTRUMENTATION_KEY = '';
39
+ // Environment variable to override the default setup string
40
+ const ENV_SETUP_OVERRIDE = 'RNW_TELEMETRY_SETUP';
41
+ // Environment variable to override the http proxy (such as http://localhost:8888 for Fiddler debugging)
42
+ const ENV_PROXY_OVERRIDE = 'RNW_TELEMETRY_PROXY';
43
+ exports.CommandEventName = 'RNWCLI.Command';
44
+ exports.CodedErrorEventName = 'RNWCLI.CodedError';
45
+ // These are the event names we're tracking
46
+ exports.EventNamesWeTrack = [
47
+ exports.CommandEventName,
48
+ exports.CodedErrorEventName,
49
+ ];
50
+ // These are NPM packages we care about, in terms of capturing versions used
51
+ // and getting more details about when reporting errors
52
+ exports.NpmPackagesWeTrack = [
53
+ '@react-native-community/cli',
54
+ '@react-native-windows/cli',
55
+ '@react-native-windows/telemetry',
56
+ 'react',
57
+ 'react-native',
58
+ 'react-native-windows',
59
+ 'react-native-windows-init',
60
+ ];
61
+ // These are NPM packages we care about, in terms of capturing versions used
62
+ exports.NuGetPackagesWeTrack = [
63
+ 'Microsoft.UI.Xaml',
64
+ 'Microsoft.Windows.CppWinRT',
65
+ 'Microsoft.WinUI',
66
+ ];
67
+ /**
68
+ * The Telemetry class is responsible for reporting telemetry for RNW CLI.
69
+ */
70
+ class Telemetry {
71
+ static getDefaultSetupString() {
72
+ var _a;
73
+ // Enable overriding the default setup string via an environment variable
74
+ return (_a = process.env[ENV_SETUP_OVERRIDE]) !== null && _a !== void 0 ? _a : RNW_1DS_INSTRUMENTATION_KEY;
75
+ }
76
+ static reset() {
77
+ // Reset client
78
+ if (Telemetry.appInsightsCore) {
79
+ Telemetry.appInsightsCore.flush();
80
+ Telemetry.appInsightsCore = undefined;
81
+ }
82
+ // Reset local members
83
+ Telemetry.options = {
84
+ setupString: Telemetry.getDefaultSetupString(),
85
+ preserveErrorMessages: false,
86
+ populateNpmPackageVersions: true,
87
+ };
88
+ Telemetry.commandInfo = {};
89
+ Telemetry.versionsProp = {};
90
+ Telemetry.projectProp = undefined;
91
+ }
92
+ static isEnabled() {
93
+ return Telemetry.appInsightsCore !== undefined;
94
+ }
95
+ static getSessionId() {
96
+ return basePropUtils.getSessionId();
97
+ }
98
+ /** Sets up the Telemetry static to be used elsewhere. */
99
+ static async setup(options) {
100
+ if (Telemetry.appInsightsCore) {
101
+ // Bail since we've already setup
102
+ return;
103
+ }
104
+ // Bail if we're in CI and not capturing CI
105
+ if (!Telemetry.isTestEnvironment &&
106
+ basePropUtils.isCI() &&
107
+ !basePropUtils.captureCI()) {
108
+ return;
109
+ }
110
+ // Save off options for later
111
+ Object.assign(Telemetry.options, options);
112
+ Telemetry.setupClient();
113
+ await Telemetry.setupBaseProperties();
114
+ }
115
+ static basicTelemetryInitializer(envelope) {
116
+ // Filter out "legacy" events from older stable branches
117
+ if (envelope.name && exports.EventNamesWeTrack.includes(envelope.name)) {
118
+ return true;
119
+ }
120
+ return false;
121
+ }
122
+ /** Sets up Telemetry.appInsightsCore. */
123
+ static setupClient() {
124
+ const postChannel = new _1ds_post_js_1.PostChannel();
125
+ const coreConfiguration = {
126
+ instrumentationKey: Telemetry.getDefaultSetupString(),
127
+ };
128
+ const postChannelConfig = {
129
+ eventsLimitInMem: 5000,
130
+ };
131
+ coreConfiguration.extensionConfig = {};
132
+ coreConfiguration.extensionConfig[postChannel.identifier] =
133
+ postChannelConfig;
134
+ // Allow overriding the endpoint URL via an environment variable.
135
+ if (process.env[ENV_PROXY_OVERRIDE] !== undefined) {
136
+ coreConfiguration.endpointUrl = process.env[ENV_PROXY_OVERRIDE];
137
+ }
138
+ Telemetry.appInsightsCore = new coreOneDS.AppInsightsCore();
139
+ Telemetry.appInsightsCore.initialize(coreConfiguration, [postChannel] /* extensions */);
140
+ Telemetry.appInsightsCore.addTelemetryInitializer(Telemetry.basicTelemetryInitializer);
141
+ }
142
+ /** Sets up any base properties that all telemetry events require. */
143
+ static async setupBaseProperties() {
144
+ Telemetry.commonProperties.deviceId = await basePropUtils.deviceId();
145
+ Telemetry.commonProperties.fullBuildInfo =
146
+ await basePropUtils.fullBuildInfo();
147
+ Telemetry.commonProperties.deviceArchitecture =
148
+ basePropUtils.deviceArchitecture();
149
+ Telemetry.commonProperties.nodeArchitecture =
150
+ basePropUtils.nodeArchitecture();
151
+ Telemetry.commonProperties.nodePlatform = basePropUtils.nodePlatform();
152
+ Telemetry.commonProperties.deviceClass = basePropUtils.deviceClass();
153
+ Telemetry.commonProperties.deviceLocale =
154
+ await basePropUtils.deviceLocale();
155
+ Telemetry.commonProperties.deviceNumCPUs = basePropUtils
156
+ .deviceNumCPUs()
157
+ .toString();
158
+ Telemetry.commonProperties.deviceTotalMemory = basePropUtils
159
+ .deviceTotalMemory()
160
+ .toString();
161
+ Telemetry.commonProperties.deviceDiskFreeSpace = basePropUtils
162
+ .deviceDiskFreeSpace()
163
+ .toString();
164
+ Telemetry.commonProperties.ciCaptured = basePropUtils
165
+ .captureCI()
166
+ .toString();
167
+ Telemetry.commonProperties.ciType = basePropUtils.ciType();
168
+ Telemetry.commonProperties.isMsftInternal = basePropUtils
169
+ .isMsftInternal()
170
+ .toString();
171
+ Telemetry.commonProperties.isTest = Telemetry.isTestEnvironment.toString();
172
+ Telemetry.commonProperties.sessionId = Telemetry.getSessionId();
173
+ await Telemetry.populateToolsVersions();
174
+ if (Telemetry.options.populateNpmPackageVersions) {
175
+ await Telemetry.populateNpmPackageVersions();
176
+ }
177
+ }
178
+ /** Tries to update the version of the named package/tool by calling getValue(). */
179
+ static async tryUpdateVersionsProp(name, getValue, forceRefresh) {
180
+ if (!Telemetry.appInsightsCore) {
181
+ return true;
182
+ }
183
+ if (forceRefresh === true || !Telemetry.versionsProp[name]) {
184
+ const value = await getValue();
185
+ if (value) {
186
+ Telemetry.versionsProp[name] = value;
187
+ return true;
188
+ }
189
+ }
190
+ return false;
191
+ }
192
+ /** Populates the versions property of tools we care to track. */
193
+ static async populateToolsVersions(refresh) {
194
+ await Telemetry.tryUpdateVersionsProp('node', versionUtils.getNodeVersion, refresh);
195
+ await Telemetry.tryUpdateVersionsProp('npm', versionUtils.getNpmVersion, refresh);
196
+ await Telemetry.tryUpdateVersionsProp('yarn', versionUtils.getYarnVersion, refresh);
197
+ await Telemetry.tryUpdateVersionsProp('VisualStudio', versionUtils.getVisualStudioVersion, refresh);
198
+ }
199
+ /** Populates the versions property of npm packages we care to track. */
200
+ static async populateNpmPackageVersions(refresh) {
201
+ for (const npmPackage of exports.NpmPackagesWeTrack) {
202
+ await Telemetry.tryUpdateVersionsProp(npmPackage, async () => await versionUtils.getVersionOfNpmPackage(npmPackage), refresh);
203
+ }
204
+ }
205
+ /** Populates the versions property of nuget packages we care to track. */
206
+ static async populateNuGetPackageVersions(projectFile, refresh) {
207
+ const nugetVersions = await versionUtils.getVersionsOfNuGetPackages(projectFile, exports.NuGetPackagesWeTrack);
208
+ for (const nugetPackage of exports.NuGetPackagesWeTrack) {
209
+ await Telemetry.tryUpdateVersionsProp(nugetPackage, async () => nugetVersions[nugetPackage], refresh);
210
+ }
211
+ }
212
+ static setProjectInfo(info) {
213
+ if (!Telemetry.appInsightsCore) {
214
+ return;
215
+ }
216
+ Telemetry.projectProp = info;
217
+ }
218
+ static startCommand(info) {
219
+ if (!Telemetry.appInsightsCore) {
220
+ return;
221
+ }
222
+ // startCommand() was called before invoking endCommand(), bail out.
223
+ if (Telemetry.commandInfo.startInfo) {
224
+ return;
225
+ }
226
+ Telemetry.commandInfo.startTime = Date.now();
227
+ Telemetry.commandInfo.startInfo = info;
228
+ // Set common command props
229
+ Telemetry.commonProperties.commandName = info.commandName;
230
+ }
231
+ static endCommand(info, extraProps) {
232
+ if (!Telemetry.appInsightsCore) {
233
+ return;
234
+ }
235
+ // startCommand() wasn't called, bail out.
236
+ if (!Telemetry.commandInfo.startInfo) {
237
+ return;
238
+ }
239
+ Telemetry.commandInfo.endTime = Date.now();
240
+ Telemetry.commandInfo.endInfo = info;
241
+ Telemetry.trackCommandEvent(extraProps);
242
+ }
243
+ static trackEvent(telemetryItem) {
244
+ // Populate Part A
245
+ telemetryItem.ver = '4.0'; // Current Common Schema version
246
+ telemetryItem.time = new Date().toISOString();
247
+ telemetryItem.iKey = RNW_1DS_INSTRUMENTATION_KEY;
248
+ // Populate Part A extensions
249
+ telemetryItem.ext = {};
250
+ telemetryItem.ext.device = {
251
+ id: Telemetry.commonProperties.deviceId,
252
+ deviceClass: Telemetry.commonProperties.deviceClass,
253
+ };
254
+ telemetryItem.ext.os = {
255
+ locale: Telemetry.commonProperties.deviceLocale,
256
+ ver: Telemetry.commonProperties.fullBuildInfo,
257
+ };
258
+ // Populate most of "common" properties into Part B.
259
+ telemetryItem.baseData = {
260
+ common: {
261
+ device: {
262
+ architecture: Telemetry.commonProperties.deviceArchitecture,
263
+ numCPUs: Telemetry.commonProperties.numCPUs,
264
+ totalMemory: Telemetry.commonProperties.totalMemory,
265
+ diskFreeSpace: Telemetry.commonProperties.deviceDiskFreeSpace,
266
+ },
267
+ nodePlatform: Telemetry.commonProperties.nodePlatform,
268
+ nodeArchitecture: Telemetry.commonProperties.nodeArchitecture,
269
+ ciCaptured: Telemetry.commonProperties.ciCaptured,
270
+ ciType: Telemetry.commonProperties.ciType,
271
+ isMsftInternal: Telemetry.commonProperties.isMsftInternal,
272
+ isCliTest: Telemetry.commonProperties.isTest,
273
+ sessionId: Telemetry.commonProperties.sessionId,
274
+ commandName: Telemetry.commonProperties.commandName,
275
+ },
276
+ // Set project and versions props, belonging to Part B.
277
+ project: Telemetry.projectProp,
278
+ versions: Telemetry.versionsProp,
279
+ };
280
+ // Send and post the telemetry event!
281
+ Telemetry.appInsightsCore.track(telemetryItem);
282
+ Telemetry.appInsightsCore.flush();
283
+ }
284
+ static trackCommandEvent(extraProps) {
285
+ var _a, _b, _c, _d;
286
+ const telemetryItem = { name: exports.CommandEventName };
287
+ // This is logged in Part C.
288
+ const command = {
289
+ options: (_a = Telemetry.commandInfo.startInfo) === null || _a === void 0 ? void 0 : _a.options,
290
+ defaultOptions: (_b = Telemetry.commandInfo.startInfo) === null || _b === void 0 ? void 0 : _b.defaultOptions,
291
+ args: (_c = Telemetry.commandInfo.startInfo) === null || _c === void 0 ? void 0 : _c.args,
292
+ durationInSecs: (Telemetry.commandInfo.endTime - Telemetry.commandInfo.startTime) /
293
+ 1000,
294
+ resultCode: (_d = Telemetry.commandInfo.endInfo) === null || _d === void 0 ? void 0 : _d.resultCode,
295
+ };
296
+ telemetryItem.data = {
297
+ command: command,
298
+ };
299
+ if (extraProps) {
300
+ telemetryItem.data.additionalData = extraProps;
301
+ }
302
+ // Populate common properties and fire event
303
+ Telemetry.trackEvent(telemetryItem);
304
+ }
305
+ static trackException(error, extraProps) {
306
+ var _a, _b;
307
+ if (!Telemetry.appInsightsCore) {
308
+ return;
309
+ }
310
+ const telemetryItem = { name: exports.CodedErrorEventName };
311
+ // Save off CodedError info in Part C.
312
+ const codedError = error instanceof errorUtils.CodedError
313
+ ? error
314
+ : null;
315
+ const codedErrorStruct = {
316
+ type: (_a = codedError === null || codedError === void 0 ? void 0 : codedError.type) !== null && _a !== void 0 ? _a : 'Unknown',
317
+ data: (_b = codedError === null || codedError === void 0 ? void 0 : codedError.data) !== null && _b !== void 0 ? _b : {},
318
+ };
319
+ // Copy msBuildErrorMessages into the codedError.data object
320
+ if (error.msBuildErrorMessages) {
321
+ // Always grab MSBuild error codes if possible
322
+ codedErrorStruct.data.msBuildErrors = error.msBuildErrorMessages
323
+ .map(errorUtils.tryGetErrorCode)
324
+ .filter((msg) => msg);
325
+ // Grab sanitized MSBuild error messages if we're preserving them
326
+ if (Telemetry.options.preserveErrorMessages) {
327
+ codedErrorStruct.data.msBuildErrorMessages = error.msBuildErrorMessages
328
+ .map(errorUtils.sanitizeErrorMessage)
329
+ .filter((msg) => msg);
330
+ }
331
+ }
332
+ // Copy miscellaneous system error fields into the codedError.data object
333
+ const syscallExceptionFieldsToCopy = ['errno', 'syscall', 'code'];
334
+ for (const f of syscallExceptionFieldsToCopy) {
335
+ if (error[f]) {
336
+ codedErrorStruct.data.codedError.data[f] = error[f];
337
+ }
338
+ }
339
+ // Break down TS Error object into Exception Data
340
+ const exceptionData = Telemetry.convertErrorIntoExceptionData(error);
341
+ telemetryItem.data = {
342
+ codedError: codedErrorStruct,
343
+ exceptionData: exceptionData,
344
+ };
345
+ Telemetry.trackEvent(telemetryItem);
346
+ }
347
+ static convertErrorIntoExceptionData(error) {
348
+ var _a;
349
+ const exceptionData = {
350
+ hasFullStack: false,
351
+ message: error.message,
352
+ parsedStack: {},
353
+ };
354
+ exceptionData.message = exceptionData.message || '[None]';
355
+ // CodedError has non-PII information in its 'type' member, plus optionally some more info in its 'data'.
356
+ // The message may contain PII information. This can be sanitized, but for now delete it.
357
+ if (Telemetry.options.preserveErrorMessages) {
358
+ exceptionData.message = errorUtils.sanitizeErrorMessage(exceptionData.message);
359
+ }
360
+ else {
361
+ exceptionData.message = '[Removed]';
362
+ }
363
+ const lines = (_a = error.stack) === null || _a === void 0 ? void 0 : _a.split('\n');
364
+ const parsedStack = lines === null || lines === void 0 ? void 0 : lines.slice(1).map(line => {
365
+ const errorStackFrame = {};
366
+ const match = line
367
+ .trim()
368
+ .match(/^\s*at\s+(?:(.*?)\s+\((.*):(\d+):(\d+)\)|(.*):(\d+):(\d+))$/);
369
+ if (match) {
370
+ errorStackFrame.functionName = match[1] || 'N/A'; // Use a default value if no function name
371
+ errorStackFrame.filePath = match[2] || match[5];
372
+ errorStackFrame.lineNumber =
373
+ parseInt(match[3], 10) || parseInt(match[6], 10);
374
+ errorStackFrame.columnNumber =
375
+ parseInt(match[4], 10) || parseInt(match[7], 10);
376
+ }
377
+ return errorStackFrame;
378
+ });
379
+ if (parsedStack) {
380
+ parsedStack.filter(Boolean);
381
+ // Sanitize parsed error stack frames
382
+ for (const frame of parsedStack) {
383
+ errorUtils.sanitizeErrorStackFrame(frame);
384
+ }
385
+ exceptionData.hasFullStack = true;
386
+ exceptionData.parsedStack = parsedStack;
387
+ }
388
+ return exceptionData;
389
+ }
390
+ }
391
+ Telemetry.appInsightsCore = undefined;
392
+ Telemetry.options = {
393
+ setupString: Telemetry.getDefaultSetupString(),
394
+ preserveErrorMessages: false,
395
+ populateNpmPackageVersions: true,
396
+ };
397
+ Telemetry.isTestEnvironment = basePropUtils.isCliTest();
398
+ Telemetry.commandInfo = {};
399
+ // Stores the version of a list of packages used by the RNW app project.
400
+ Telemetry.versionsProp = {};
401
+ Telemetry.projectProp = undefined;
402
+ // Store "Common Properties" in a single object. This will be logged in all telemetry events.
403
+ Telemetry.commonProperties = {};
404
+ exports.Telemetry = Telemetry;
172
405
  //# sourceMappingURL=telemetry.js.map