Skip to content

Commit 71d1793

Browse files
authored
Revert vscode-extension-telemetry changes for the release (#11602)
* Revert "Fix slashes in telemetry unit tests (#11572)" This reverts commit 7431c9c. * Revert "Use vscode-extension-telemetry for our exceptions & error telemetry (#11524)" This reverts commit d5065e6. * Remove from changelog
1 parent aed9d12 commit 71d1793

File tree

8 files changed

+241
-174
lines changed

8 files changed

+241
-174
lines changed

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@
9191
([#11221](https://github.com/Microsoft/vscode-python/issues/11221))
9292
1. Lazy load types from `jupyterlab/services` and similar `npm modules`.
9393
([#11297](https://github.com/Microsoft/vscode-python/issues/11297))
94-
1. Update telemetry on errors and exceptions to use [vscode-extension-telemetry](https://www.npmjs.com/package/vscode-extension-telemetry).
95-
([#11436](https://github.com/Microsoft/vscode-python/issues/11436))
9694
1. Remove IJMPConnection implementation while maintaining tests written for it.
9795
([#11470](https://github.com/Microsoft/vscode-python/issues/11470))
9896
1. Implement an IJupyterVariables provider for the debugger.

gulpfile.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,7 @@ function getAllowedWarningsForWebPack(buildConfig) {
287287
'WARNING in ./node_modules/@jupyterlab/services/node_modules/ws/lib/validation.js',
288288
'WARNING in ./node_modules/any-promise/register.js',
289289
'WARNING in ./node_modules/log4js/lib/appenders/index.js',
290-
'WARNING in ./node_modules/log4js/lib/clustering.js',
291-
'WARNING in ./node_modules/diagnostic-channel-publishers/dist/src/azure-coretracing.pub.js',
292-
'WARNING in ./node_modules/applicationinsights/out/AutoCollection/NativePerformance.js'
290+
'WARNING in ./node_modules/log4js/lib/clustering.js'
293291
];
294292
case 'extension':
295293
return [
@@ -302,16 +300,10 @@ function getAllowedWarningsForWebPack(buildConfig) {
302300
303301
'WARNING in ./node_modules/@jupyterlab/services/node_modules/ws/lib/buffer-util.js',
304302
'WARNING in ./node_modules/@jupyterlab/services/node_modules/ws/lib/validation.js',
305-
'WARNING in ./node_modules/@jupyterlab/services/node_modules/ws/lib/Validation.js',
306-
'WARNING in ./node_modules/diagnostic-channel-publishers/dist/src/azure-coretracing.pub.js',
307-
'WARNING in ./node_modules/applicationinsights/out/AutoCollection/NativePerformance.js'
303+
'WARNING in ./node_modules/@jupyterlab/services/node_modules/ws/lib/Validation.js'
308304
];
309305
case 'debugAdapter':
310-
return [
311-
'WARNING in ./node_modules/vscode-uri/lib/index.js',
312-
'WARNING in ./node_modules/diagnostic-channel-publishers/dist/src/azure-coretracing.pub.js',
313-
'WARNING in ./node_modules/applicationinsights/out/AutoCollection/NativePerformance.js'
314-
];
306+
return ['WARNING in ./node_modules/vscode-uri/lib/index.js'];
315307
default:
316308
throw new Error('Unknown WebPack Configuration');
317309
}

package-lock.json

Lines changed: 17 additions & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2980,7 +2980,7 @@
29802980
"untildify": "^3.0.2",
29812981
"vscode-debugadapter": "^1.28.0",
29822982
"vscode-debugprotocol": "^1.28.0",
2983-
"vscode-extension-telemetry": "0.1.4",
2983+
"vscode-extension-telemetry": "0.1.0",
29842984
"vscode-jsonrpc": "^5.0.1",
29852985
"vscode-languageclient": "^6.2.0-next.2",
29862986
"vscode-languageserver": "^6.2.0-next.2",

src/client/telemetry/index.ts

Lines changed: 64 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
3-
3+
// tslint:disable:no-reference no-any import-name no-any function-name
4+
/// <reference path="./vscode-extension-telemetry.d.ts" />
45
import type { JSONObject } from '@phosphor/coreutils';
6+
import { basename as pathBasename, sep as pathSep } from 'path';
57
import * as stackTrace from 'stack-trace';
6-
// tslint:disable-next-line: import-name
7-
import TelemetryReporter from 'vscode-extension-telemetry/lib/telemetryReporter';
8+
import TelemetryReporter from 'vscode-extension-telemetry';
89

910
import { DiagnosticCodes } from '../application/diagnostics/constants';
1011
import { IWorkspaceService } from '../common/application/types';
11-
import { AppinsightsKey, isTestExecution, PVSC_EXTENSION_ID } from '../common/constants';
12+
import { AppinsightsKey, EXTENSION_ROOT_DIR, isTestExecution, PVSC_EXTENSION_ID } from '../common/constants';
1213
import { traceError, traceInfo } from '../common/logger';
1314
import { TerminalShellType } from '../common/terminal/types';
1415
import { StopWatch } from '../common/utils/stopWatch';
@@ -27,12 +28,10 @@ import { TestProvider } from '../testing/common/types';
2728
import { EventName, PlatformErrors } from './constants';
2829
import { LinterTrigger, TestTool } from './types';
2930

30-
// tslint:disable: no-any
31-
3231
/**
3332
* Checks whether telemetry is supported.
3433
* Its possible this function gets called within Debug Adapter, vscode isn't available in there.
35-
* Within DA, there's a completely different way to send telemetry.
34+
* Withiin DA, there's a completely different way to send telemetry.
3635
* @returns {boolean}
3736
*/
3837
function isTelemetrySupported(): boolean {
@@ -64,12 +63,14 @@ function getTelemetryReporter() {
6463
const extensionId = PVSC_EXTENSION_ID;
6564
// tslint:disable-next-line:no-require-imports
6665
const extensions = (require('vscode') as typeof import('vscode')).extensions;
66+
// tslint:disable-next-line:no-non-null-assertion
6767
const extension = extensions.getExtension(extensionId)!;
68+
// tslint:disable-next-line:no-unsafe-any
6869
const extensionVersion = extension.packageJSON.version;
6970

7071
// tslint:disable-next-line:no-require-imports
7172
const reporter = require('vscode-extension-telemetry').default as typeof TelemetryReporter;
72-
return (telemetryReporter = new reporter(extensionId, extensionVersion, AppinsightsKey, true));
73+
return (telemetryReporter = new reporter(extensionId, extensionVersion, AppinsightsKey));
7374
}
7475

7576
export function clearTelemetryReporter() {
@@ -87,46 +88,45 @@ export function sendTelemetryEvent<P extends IEventNamePropertyMapping, E extend
8788
}
8889
const reporter = getTelemetryReporter();
8990
const measures = typeof durationMs === 'number' ? { duration: durationMs } : durationMs ? durationMs : undefined;
90-
let customProperties: Record<string, string> = {};
91-
let eventNameSent = eventName as string;
9291

93-
if (ex) {
94-
// When sending telemetry events for exceptions no need to send custom properties.
92+
if (ex && (eventName as any) !== 'ERROR') {
93+
// When sending `ERROR` telemetry event no need to send custom properties.
9594
// Else we have to review all properties every time as part of GDPR.
9695
// Assume we have 10 events all with their own properties.
9796
// As we have errors for each event, those properties are treated as new data items.
9897
// Hence they need to be classified as part of the GDPR process, and thats unnecessary and onerous.
99-
eventNameSent = 'ERROR';
100-
customProperties = { originalEventName: eventName as string, stackTrace: serializeStackTrace(ex) };
101-
reporter.sendTelemetryErrorEvent(eventNameSent, customProperties, measures, []);
102-
} else {
103-
if (properties) {
104-
const data = properties as any;
105-
Object.getOwnPropertyNames(data).forEach((prop) => {
106-
if (data[prop] === undefined || data[prop] === null) {
107-
return;
108-
}
109-
try {
110-
// If there are any errors in serializing one property, ignore that and move on.
111-
// Else nothing will be sent.
112-
customProperties[prop] =
113-
typeof data[prop] === 'string'
114-
? data[prop]
115-
: typeof data[prop] === 'object'
116-
? 'object'
117-
: data[prop].toString();
118-
} catch (ex) {
119-
traceError(`Failed to serialize ${prop} for ${eventName}`, ex);
120-
}
121-
});
122-
}
123-
124-
reporter.sendTelemetryEvent(eventNameSent, customProperties, measures);
98+
const props: Record<string, string> = {};
99+
props.stackTrace = getStackTrace(ex);
100+
props.originalEventName = (eventName as any) as string;
101+
reporter.sendTelemetryEvent('ERROR', props, measures);
125102
}
126-
103+
const customProperties: Record<string, string> = {};
104+
if (properties) {
105+
// tslint:disable-next-line:prefer-type-cast no-any
106+
const data = properties as any;
107+
Object.getOwnPropertyNames(data).forEach((prop) => {
108+
if (data[prop] === undefined || data[prop] === null) {
109+
return;
110+
}
111+
try {
112+
// If there are any errors in serializing one property, ignore that and move on.
113+
// Else nothign will be sent.
114+
// tslint:disable-next-line:prefer-type-cast no-any no-unsafe-any
115+
(customProperties as any)[prop] =
116+
typeof data[prop] === 'string'
117+
? data[prop]
118+
: typeof data[prop] === 'object'
119+
? 'object'
120+
: data[prop].toString();
121+
} catch (ex) {
122+
traceError(`Failed to serialize ${prop} for ${eventName}`, ex);
123+
}
124+
});
125+
}
126+
reporter.sendTelemetryEvent((eventName as any) as string, customProperties, measures);
127127
if (process.env && process.env.VSC_PYTHON_LOG_TELEMETRY) {
128128
traceInfo(
129-
`Telemetry Event : ${eventNameSent} Measures: ${JSON.stringify(measures)} Props: ${JSON.stringify(
129+
`Telemetry Event : ${eventName} Measures: ${JSON.stringify(measures)} Props: ${JSON.stringify(
130130
customProperties
131131
)} `
132132
);
@@ -246,12 +246,32 @@ export function sendTelemetryWhenDone<P extends IEventNamePropertyMapping, E ext
246246
}
247247
}
248248

249-
function serializeStackTrace(ex: Error): string {
250-
// We aren't showing the error message (ex.message) since it might contain PII.
249+
function sanitizeFilename(filename: string): string {
250+
if (filename.startsWith(EXTENSION_ROOT_DIR)) {
251+
filename = `<pvsc>${filename.substring(EXTENSION_ROOT_DIR.length)}`;
252+
} else {
253+
// We don't really care about files outside our extension.
254+
filename = `<hidden>${pathSep}${pathBasename(filename)}`;
255+
}
256+
return filename;
257+
}
258+
259+
function sanitizeName(name: string): string {
260+
if (name.indexOf('/') === -1 && name.indexOf('\\') === -1) {
261+
return name;
262+
} else {
263+
return '<hidden>';
264+
}
265+
}
266+
267+
function getStackTrace(ex: Error): string {
268+
// We aren't showing the error message (ex.message) since it might
269+
// contain PII.
251270
let trace = '';
252271
for (const frame of stackTrace.parse(ex)) {
253-
const filename = frame.getFileName();
272+
let filename = frame.getFileName();
254273
if (filename) {
274+
filename = sanitizeFilename(filename);
255275
const lineno = frame.getLineNumber();
256276
const colno = frame.getColumnNumber();
257277
trace += `\n\tat ${getCallsite(frame)} ${filename}:${lineno}:${colno}`;
@@ -277,7 +297,7 @@ function getCallsite(frame: stackTrace.StackFrame) {
277297
parts.push(frame.getFunctionName());
278298
}
279299
}
280-
return parts.join('.');
300+
return parts.map(sanitizeName).join('.');
281301
}
282302

283303
// Map all events to their properties

0 commit comments

Comments
 (0)