Skip to content

Commit 4e03bf4

Browse files
committed
Send machineId to main process (fixes microsoft#22169)
1 parent 4795fc4 commit 4e03bf4

4 files changed

Lines changed: 32 additions & 14 deletions

File tree

src/vs/base/node/id.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,12 @@ export function _futureMachineIdExperiment(): string {
9999

100100
let machineId: TPromise<string>;
101101
export function getMachineId(): TPromise<string> {
102-
return machineId || (machineId = getStableMachineId()
102+
return machineId || (machineId = getMacMachineId()
103103
.then(id => id || uuid.generateUuid())); // fallback, generate a UUID
104104
}
105105

106-
let stableMachineId: TPromise<string>;
107-
export function getStableMachineId(): TPromise<string> {
108-
return stableMachineId || (stableMachineId = new TPromise<string>(resolve => {
106+
function getMacMachineId(): TPromise<string> {
107+
return new TPromise<string>(resolve => {
109108
try {
110109
getmac.getMac((error, macAddress) => {
111110
if (!error) {
@@ -118,5 +117,5 @@ export function getStableMachineId(): TPromise<string> {
118117
errors.onUnexpectedError(err);
119118
resolve(undefined);
120119
}
121-
}));
120+
});
122121
}

src/vs/code/electron-main/main.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
5252
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
5353
import { ITelemetryAppenderChannel, TelemetryAppenderClient } from 'vs/platform/telemetry/common/telemetryIpc';
5454
import { TelemetryService, ITelemetryServiceConfig } from 'vs/platform/telemetry/common/telemetryService';
55-
import { resolveCommonProperties } from 'vs/platform/telemetry/node/commonProperties';
55+
import { resolveCommonProperties, machineIdStorageKey, machineIdIpcChannel } from 'vs/platform/telemetry/node/commonProperties';
5656
import { getDelayedChannel } from 'vs/base/parts/ipc/common/ipc';
5757
import product from 'vs/platform/node/product';
5858
import pkg from 'vs/platform/node/package';
@@ -94,6 +94,7 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
9494
const environmentService = accessor.get(IEnvironmentService);
9595
const lifecycleService = accessor.get(ILifecycleService);
9696
const configurationService = accessor.get(IConfigurationService) as ConfigurationService<any>;
97+
const storageService = accessor.get(IStorageService);
9798
let windowsMainService: IWindowsMainService;
9899

99100
// We handle uncaught exceptions here to prevent electron from opening a dialog to the user
@@ -118,6 +119,11 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
118119
}
119120
});
120121

122+
ipc.on(machineIdIpcChannel, (event, machineId: string) => {
123+
logService.log('IPC#vscode-machineId');
124+
storageService.setItem(machineIdStorageKey, machineId);
125+
});
126+
121127
logService.log('Starting VS Code in verbose mode');
122128
logService.log(`from: ${environmentService.appRoot}`);
123129
logService.log('args:', environmentService.args);
@@ -159,7 +165,11 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
159165
if (environmentService.isBuilt && !environmentService.isExtensionDevelopment && !!product.enableTelemetry) {
160166
const channel = getDelayedChannel<ITelemetryAppenderChannel>(sharedProcessClient.then(c => c.getChannel('telemetryAppender')));
161167
const appender = new TelemetryAppenderClient(channel);
162-
const commonProperties = resolveCommonProperties(product.commit, pkg.version);
168+
const commonProperties = resolveCommonProperties(product.commit, pkg.version)
169+
.then(result => Object.defineProperty(result, 'common.machineId', {
170+
get: () => storageService.getItem(machineIdStorageKey),
171+
enumerable: true
172+
}));
163173
const piiPaths = [environmentService.appRoot, environmentService.extensionsPath];
164174
const config: ITelemetryServiceConfig = { appender, commonProperties, piiPaths };
165175
services.set(ITelemetryService, new SyncDescriptor(TelemetryService, config));

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import * as Platform from 'vs/base/common/platform';
77
import * as os from 'os';
88
import { TPromise } from 'vs/base/common/winjs.base';
99
import * as uuid from 'vs/base/common/uuid';
10-
import { getStableMachineId } from 'vs/base/node/id';
10+
11+
export const machineIdStorageKey = 'telemetry.machineId';
12+
export const machineIdIpcChannel = 'vscode:machineId';
1113

1214
export function resolveCommonProperties(commit: string, version: string): TPromise<{ [name: string]: string; }> {
1315
const result: { [name: string]: string; } = Object.create(null);
@@ -17,7 +19,6 @@ export function resolveCommonProperties(commit: string, version: string): TPromi
1719
result['version'] = version;
1820
result['common.osVersion'] = os.release();
1921
result['common.platform'] = Platform.Platform[Platform.platform];
20-
const promise = getStableMachineId().then(value => result['common.mainProcess.machineId'] = value);
2122

2223
// dynamic properties which value differs on each call
2324
let seq = 0;
@@ -37,5 +38,5 @@ export function resolveCommonProperties(commit: string, version: string): TPromi
3738
}
3839
});
3940

40-
return promise.then(() => result);
41+
return TPromise.as(result);
4142
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import * as errors from 'vs/base/common/errors';
1010
import * as uuid from 'vs/base/common/uuid';
1111
import { IStorageService } from 'vs/platform/storage/common/storage';
1212
import { getMachineId, virtualMachineHint } from 'vs/base/node/id';
13-
import { resolveCommonProperties } from '../node/commonProperties';
13+
import { resolveCommonProperties, machineIdStorageKey, machineIdIpcChannel } from '../node/commonProperties';
14+
import { ipcRenderer as ipc } from 'electron';
1415

1516
const SQM_KEY: string = '\\Software\\Microsoft\\SQMClient';
1617

@@ -50,15 +51,22 @@ function getOrCreateInstanceId(storageService: IStorageService): TPromise<string
5051
}
5152

5253
function getOrCreateMachineId(storageService: IStorageService): TPromise<string> {
53-
const key = 'telemetry.machineId';
54-
let result = storageService.get(key);
54+
return _getOrCreateMachineId(storageService)
55+
.then(value => {
56+
ipc.send(machineIdIpcChannel, value);
57+
return value;
58+
});
59+
}
60+
61+
function _getOrCreateMachineId(storageService: IStorageService): TPromise<string> {
62+
let result = storageService.get(machineIdStorageKey);
5563

5664
if (result) {
5765
return TPromise.as(result);
5866
}
5967

6068
return getMachineId().then(result => {
61-
storageService.store(key, result);
69+
storageService.store(machineIdStorageKey, result);
6270
return result;
6371
});
6472
}

0 commit comments

Comments
 (0)