Skip to content

Commit f45aa1f

Browse files
author
Rachel Macfarlane
committed
Add resolveCommonTelemetryProperties option
1 parent 4a44dd5 commit f45aa1f

5 files changed

Lines changed: 80 additions & 4 deletions

File tree

src/vs/platform/telemetry/node/commonProperties.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,17 @@ import * as Platform from 'vs/base/common/platform';
77
import * as os from 'os';
88
import * as uuid from 'vs/base/common/uuid';
99
import { readFile } from 'vs/base/node/pfs';
10+
import { mixin } from 'vs/base/common/objects';
1011

11-
export async function resolveCommonProperties(commit: string | undefined, version: string | undefined, machineId: string | undefined, msftInternalDomains: string[] | undefined, installSourcePath: string, product?: string): Promise<{ [name: string]: string | boolean | undefined; }> {
12+
export async function resolveCommonProperties(
13+
commit: string | undefined,
14+
version: string | undefined,
15+
machineId: string | undefined,
16+
msftInternalDomains: string[] | undefined,
17+
installSourcePath: string,
18+
product?: string,
19+
resolveAdditionalProperties?: () => { [key: string]: any }
20+
): Promise<{ [name: string]: string | boolean | undefined; }> {
1221
const result: { [name: string]: string | boolean | undefined; } = Object.create(null);
1322

1423
// __GDPR__COMMON__ "common.machineId" : { "endPoint": "MacAddressHash", "classification": "EndUserPseudonymizedInformation", "purpose": "FeatureInsight" }
@@ -71,6 +80,10 @@ export async function resolveCommonProperties(commit: string | undefined, versio
7180
// ignore error
7281
}
7382

83+
if (resolveAdditionalProperties) {
84+
mixin(result, resolveAdditionalProperties());
85+
}
86+
7487
return result;
7588
}
7689

src/vs/platform/telemetry/node/workbenchCommonProperties.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ import { resolveCommonProperties } from 'vs/platform/telemetry/node/commonProper
88
import { instanceStorageKey, firstSessionDateStorageKey, lastSessionDateStorageKey } from 'vs/platform/telemetry/common/telemetry';
99
import { cleanRemoteAuthority } from 'vs/platform/telemetry/common/telemetryUtils';
1010

11-
export async function resolveWorkbenchCommonProperties(storageService: IStorageService, commit: string | undefined, version: string | undefined, machineId: string, msftInternalDomains: string[] | undefined, installSourcePath: string, remoteAuthority?: string): Promise<{ [name: string]: string | boolean | undefined }> {
12-
const result = await resolveCommonProperties(commit, version, machineId, msftInternalDomains, installSourcePath);
11+
export async function resolveWorkbenchCommonProperties(
12+
storageService: IStorageService,
13+
commit: string | undefined,
14+
version: string | undefined,
15+
machineId: string,
16+
msftInternalDomains: string[] | undefined,
17+
installSourcePath: string,
18+
remoteAuthority?: string,
19+
resolveAdditionalProperties?: () => { [key: string]: any }
20+
): Promise<{ [name: string]: string | boolean | undefined }> {
21+
const result = await resolveCommonProperties(commit, version, machineId, msftInternalDomains, installSourcePath, undefined, resolveAdditionalProperties);
1322
const instanceId = storageService.get(instanceStorageKey, StorageScope.GLOBAL)!;
1423
const firstSessionDate = storageService.get(firstSessionDateStorageKey, StorageScope.GLOBAL)!;
1524
const lastSessionDate = storageService.get(lastSessionDateStorageKey, StorageScope.GLOBAL)!;

src/vs/platform/telemetry/test/electron-browser/commonProperties.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,52 @@ suite('Telemetry - common properties', function () {
8181
value2 = props['common.timesincesessionstart'];
8282
assert.ok(value1 !== value2, 'timesincesessionstart');
8383
});
84+
85+
test('mixes in additional properties', async function () {
86+
const resolveCommonTelemetryProperties = () => {
87+
return {
88+
'userId': '1'
89+
};
90+
};
91+
92+
const props = await resolveWorkbenchCommonProperties(testStorageService, commit, version, 'someMachineId', undefined, installSource, undefined, resolveCommonTelemetryProperties);
93+
94+
assert.ok('commitHash' in props);
95+
assert.ok('sessionID' in props);
96+
assert.ok('timestamp' in props);
97+
assert.ok('common.platform' in props);
98+
assert.ok('common.nodePlatform' in props);
99+
assert.ok('common.nodeArch' in props);
100+
assert.ok('common.timesincesessionstart' in props);
101+
assert.ok('common.sequence' in props);
102+
assert.ok('common.platformVersion' in props, 'platformVersion');
103+
assert.ok('version' in props);
104+
assert.ok('common.firstSessionDate' in props, 'firstSessionDate');
105+
assert.ok('common.lastSessionDate' in props, 'lastSessionDate');
106+
assert.ok('common.isNewSession' in props, 'isNewSession');
107+
assert.ok('common.instanceId' in props, 'instanceId');
108+
assert.ok('common.machineId' in props, 'machineId');
109+
110+
assert.equal(props['userId'], '1');
111+
});
112+
113+
test('mixes in additional dyanmic properties', async function () {
114+
let i = 1;
115+
const resolveCommonTelemetryProperties = () => {
116+
return Object.defineProperties({}, {
117+
'userId': {
118+
get: () => {
119+
return i++;
120+
},
121+
enumerable: true
122+
}
123+
});
124+
};
125+
126+
const props = await resolveWorkbenchCommonProperties(testStorageService, commit, version, 'someMachineId', undefined, installSource, undefined, resolveCommonTelemetryProperties);
127+
assert.equal(props['userId'], '1');
128+
129+
const props2 = await resolveWorkbenchCommonProperties(testStorageService, commit, version, 'someMachineId', undefined, installSource, undefined, resolveCommonTelemetryProperties);
130+
assert.equal(props2['userId'], '2');
131+
});
84132
});

src/vs/workbench/services/telemetry/electron-browser/telemetryService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class TelemetryService extends Disposable implements ITelemetryService {
3838
const channel = sharedProcessService.getChannel('telemetryAppender');
3939
const config: ITelemetryServiceConfig = {
4040
appender: combinedAppender(new TelemetryAppenderClient(channel), new LogAppender(logService)),
41-
commonProperties: resolveWorkbenchCommonProperties(storageService, productService.commit, productService.version, environmentService.configuration.machineId, productService.msftInternalDomains, environmentService.installSourcePath, environmentService.configuration.remoteAuthority),
41+
commonProperties: resolveWorkbenchCommonProperties(storageService, productService.commit, productService.version, environmentService.configuration.machineId, productService.msftInternalDomains, environmentService.installSourcePath, environmentService.configuration.remoteAuthority, environmentService.options && environmentService.options.resolveCommonTelemetryProperties),
4242
piiPaths: environmentService.extensionsPath ? [environmentService.appRoot, environmentService.extensionsPath] : [environmentService.appRoot]
4343
};
4444

src/vs/workbench/workbench.web.api.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ interface IWorkbenchConstructionOptions {
9191
*/
9292
updateProvider?: IUpdateProvider;
9393

94+
95+
/**
96+
* Experimental: Support adding additional properties to telemetry.
97+
*/
98+
resolveCommonTelemetryProperties?: () => { [key: string]: any };
99+
94100
/**
95101
* Experimental: Resolves an external uri before it is opened.
96102
*/

0 commit comments

Comments
 (0)