Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no common properties when logging error by aligning 'properties' contract #193208

Closed
wants to merge 7 commits into from
20 changes: 9 additions & 11 deletions src/vs/workbench/api/common/extHostTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,13 @@ export class ExtHostTelemetryLogger {
}

mixInCommonPropsAndCleanData(data: Record<string, any>): Record<string, any> {
// Some telemetry modules prefer to break properties and measurmements up
// Some telemetry modules prefer to break properties and measurements up
// We mix common properties into the properties tab.
let updatedData = 'properties' in data ? (data.properties ?? {}) : data;
const { properties = {}, ...restData } = data;

// We don't clean measurements since they are just numbers
updatedData = cleanData(updatedData, []);
// cleanData() only cleans string now
let updatedData = cleanData(properties, []);
const sanitizedRestData = cleanData(restData, []);

if (this._additionalCommonProperties) {
updatedData = mixin(updatedData, this._additionalCommonProperties);
Expand All @@ -234,13 +235,10 @@ export class ExtHostTelemetryLogger {
updatedData = mixin(updatedData, this._commonProperties);
}

if ('properties' in data) {
data.properties = updatedData;
} else {
data = updatedData;
}

return data;
return {
...sanitizedRestData,
properties: updatedData
};
}

private logEvent(eventName: string, data?: Record<string, any>): void {
Expand Down
6 changes: 5 additions & 1 deletion src/vs/workbench/api/test/browser/extHostTelemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ suite('ExtHostTelemetry', function () {
assert.strictEqual(functionSpy.dataArr.length, 1);
assert.strictEqual(functionSpy.dataArr[0].eventName, `${mockExtensionIdentifier.name}/test-event`);
assert.strictEqual(functionSpy.dataArr[0].data['test-data'], 'test-data');
assert.strictEqual(functionSpy.dataArr[0].data['common.foo'], 'bar');
assert.strictEqual(functionSpy.dataArr[0].data.properties['common.foo'], 'bar');
Joouis marked this conversation as resolved.
Show resolved Hide resolved

logger.logUsage('test-event', { 'test-data': 'test-data' });
assert.strictEqual(functionSpy.dataArr.length, 2);
Expand Down Expand Up @@ -218,6 +218,9 @@ suite('ExtHostTelemetry', function () {
'fake-token': 'token=123',
'fake-slack-token': 'xoxp-123',
'fake-path': '/Users/username/.vscode/extensions',
properties: {
'deep-fake-password': 'pwd=123'
}
});

assert.strictEqual(functionSpy.dataArr.length, 1);
Expand All @@ -227,6 +230,7 @@ suite('ExtHostTelemetry', function () {
assert.strictEqual(functionSpy.dataArr[0].data['fake-token'], '<REDACTED: Generic Secret>');
assert.strictEqual(functionSpy.dataArr[0].data['fake-slack-token'], '<REDACTED: Slack Token>');
assert.strictEqual(functionSpy.dataArr[0].data['fake-path'], '<REDACTED: user-file-path>');
assert.strictEqual(functionSpy.dataArr[0].data.properties['deep-fake-password'], '<REDACTED: Generic Secret>');
});

test('Ensure output channel is logged to', function () {
Expand Down
Loading