Skip to content

Commit 61cd8be

Browse files
author
Rachel Macfarlane
committed
Call resolveCommonTelemetryProperties in browser version of telemetry service
1 parent 111b4dc commit 61cd8be

7 files changed

Lines changed: 80 additions & 61 deletions

File tree

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@ export const lastSessionDateStorageKey = 'telemetry.lastSessionDate';
1313
import * as Platform from 'vs/base/common/platform';
1414
import * as uuid from 'vs/base/common/uuid';
1515
import { cleanRemoteAuthority } from 'vs/platform/telemetry/common/telemetryUtils';
16+
import { mixin } from 'vs/base/common/objects';
1617

17-
export async function resolveWorkbenchCommonProperties(storageService: IStorageService, commit: string | undefined, version: string | undefined, machineId: string, remoteAuthority?: string): Promise<{ [name: string]: string | undefined }> {
18+
export async function resolveWorkbenchCommonProperties(
19+
storageService: IStorageService,
20+
commit: string | undefined,
21+
version: string | undefined,
22+
machineId: string,
23+
remoteAuthority?: string,
24+
resolveAdditionalProperties?: () => { [key: string]: any }
25+
): Promise<{ [name: string]: string | undefined }> {
1826
const result: { [name: string]: string | undefined; } = Object.create(null);
1927
const firstSessionDate = storageService.get(firstSessionDateStorageKey, StorageScope.GLOBAL)!;
2028
const lastSessionDate = storageService.get(lastSessionDateStorageKey, StorageScope.GLOBAL)!;
@@ -68,6 +76,10 @@ export async function resolveWorkbenchCommonProperties(storageService: IStorageS
6876
}
6977
});
7078

79+
if (resolveAdditionalProperties) {
80+
mixin(result, resolveAdditionalProperties());
81+
}
82+
7183
return result;
7284
}
7385

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ 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';
1110

1211
export async function resolveCommonProperties(
1312
commit: string | undefined,
1413
version: string | undefined,
1514
machineId: string | undefined,
1615
msftInternalDomains: string[] | undefined,
1716
installSourcePath: string,
18-
product?: string,
19-
resolveAdditionalProperties?: () => { [key: string]: any }
17+
product?: string
2018
): Promise<{ [name: string]: string | boolean | undefined; }> {
2119
const result: { [name: string]: string | boolean | undefined; } = Object.create(null);
2220

@@ -80,10 +78,6 @@ export async function resolveCommonProperties(
8078
// ignore error
8179
}
8280

83-
if (resolveAdditionalProperties) {
84-
mixin(result, resolveAdditionalProperties());
85-
}
86-
8781
return result;
8882
}
8983

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ export async function resolveWorkbenchCommonProperties(
1515
machineId: string,
1616
msftInternalDomains: string[] | undefined,
1717
installSourcePath: string,
18-
remoteAuthority?: string,
19-
resolveAdditionalProperties?: () => { [key: string]: any }
18+
remoteAuthority?: string
2019
): Promise<{ [name: string]: string | boolean | undefined }> {
21-
const result = await resolveCommonProperties(commit, version, machineId, msftInternalDomains, installSourcePath, undefined, resolveAdditionalProperties);
20+
const result = await resolveCommonProperties(commit, version, machineId, msftInternalDomains, installSourcePath, undefined);
2221
const instanceId = storageService.get(instanceStorageKey, StorageScope.GLOBAL)!;
2322
const firstSessionDate = storageService.get(firstSessionDateStorageKey, StorageScope.GLOBAL)!;
2423
const lastSessionDate = storageService.get(lastSessionDateStorageKey, StorageScope.GLOBAL)!;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
import * as assert from 'assert';
6+
import { resolveWorkbenchCommonProperties } from 'vs/platform/telemetry/browser/workbenchCommonProperties';
7+
import { IStorageService, InMemoryStorageService } from 'vs/platform/storage/common/storage';
8+
9+
suite('Browser Telemetry - common properties', function () {
10+
11+
const commit: string = (undefined)!;
12+
const version: string = (undefined)!;
13+
let testStorageService: IStorageService;
14+
15+
setup(() => {
16+
testStorageService = new InMemoryStorageService();
17+
});
18+
19+
test('mixes in additional properties', async function () {
20+
const resolveCommonTelemetryProperties = () => {
21+
return {
22+
'userId': '1'
23+
};
24+
};
25+
26+
const props = await resolveWorkbenchCommonProperties(testStorageService, commit, version, 'someMachineId', undefined, resolveCommonTelemetryProperties);
27+
28+
assert.ok('commitHash' in props);
29+
assert.ok('sessionID' in props);
30+
assert.ok('timestamp' in props);
31+
assert.ok('common.platform' in props);
32+
assert.ok('common.timesincesessionstart' in props);
33+
assert.ok('common.sequence' in props);
34+
assert.ok('version' in props);
35+
assert.ok('common.firstSessionDate' in props, 'firstSessionDate');
36+
assert.ok('common.lastSessionDate' in props, 'lastSessionDate');
37+
assert.ok('common.isNewSession' in props, 'isNewSession');
38+
assert.ok('common.machineId' in props, 'machineId');
39+
40+
assert.equal(props['userId'], '1');
41+
});
42+
43+
test('mixes in additional dyanmic properties', async function () {
44+
let i = 1;
45+
const resolveCommonTelemetryProperties = () => {
46+
return Object.defineProperties({}, {
47+
'userId': {
48+
get: () => {
49+
return i++;
50+
},
51+
enumerable: true
52+
}
53+
});
54+
};
55+
56+
const props = await resolveWorkbenchCommonProperties(testStorageService, commit, version, 'someMachineId', undefined, resolveCommonTelemetryProperties);
57+
assert.equal(props['userId'], '1');
58+
59+
const props2 = await resolveWorkbenchCommonProperties(testStorageService, commit, version, 'someMachineId', undefined, resolveCommonTelemetryProperties);
60+
assert.equal(props2['userId'], '2');
61+
});
62+
});

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

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -81,52 +81,4 @@ 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-
});
13284
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class TelemetryService extends Disposable implements ITelemetryService {
8383
if (!environmentService.isExtensionDevelopment && !environmentService.args['disable-telemetry'] && !!productService.enableTelemetry && !!aiKey) {
8484
const config: ITelemetryServiceConfig = {
8585
appender: combinedAppender(new WebTelemetryAppender(aiKey, logService), new LogAppender(logService)),
86-
commonProperties: resolveWorkbenchCommonProperties(storageService, productService.commit, productService.version, environmentService.configuration.machineId, environmentService.configuration.remoteAuthority),
86+
commonProperties: resolveWorkbenchCommonProperties(storageService, productService.commit, productService.version, environmentService.configuration.machineId, environmentService.configuration.remoteAuthority, environmentService.options && environmentService.options.resolveCommonTelemetryProperties),
8787
piiPaths: [environmentService.appRoot]
8888
};
8989

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, environmentService.options && environmentService.options.resolveCommonTelemetryProperties),
41+
commonProperties: resolveWorkbenchCommonProperties(storageService, productService.commit, productService.version, environmentService.configuration.machineId, productService.msftInternalDomains, environmentService.installSourcePath, environmentService.configuration.remoteAuthority),
4242
piiPaths: environmentService.extensionsPath ? [environmentService.appRoot, environmentService.extensionsPath] : [environmentService.appRoot]
4343
};
4444

0 commit comments

Comments
 (0)