Skip to content

Commit cc098fa

Browse files
authored
Allow msftInternal to be setting toggled (microsoft#156198)
1 parent 8f10b21 commit cc098fa

File tree

17 files changed

+64
-44
lines changed

17 files changed

+64
-44
lines changed

src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import { ICustomEndpointTelemetryService, ITelemetryService } from 'vs/platform/
6262
import { TelemetryAppenderChannel } from 'vs/platform/telemetry/common/telemetryIpc';
6363
import { TelemetryLogAppender } from 'vs/platform/telemetry/common/telemetryLogAppender';
6464
import { TelemetryService } from 'vs/platform/telemetry/common/telemetryService';
65-
import { supportsTelemetry, ITelemetryAppender, NullAppender, NullTelemetryService, getPiiPathsFromEnvironment } from 'vs/platform/telemetry/common/telemetryUtils';
65+
import { supportsTelemetry, ITelemetryAppender, NullAppender, NullTelemetryService, getPiiPathsFromEnvironment, isInternalTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
6666
import { CustomEndpointTelemetryService } from 'vs/platform/telemetry/node/customEndpointTelemetryService';
6767
import { LocalReconnectConstants, TerminalIpcChannels, TerminalSettingId } from 'vs/platform/terminal/common/terminal';
6868
import { ILocalPtyService } from 'vs/platform/terminal/electron-sandbox/terminal';
@@ -277,19 +277,20 @@ class SharedProcessMain extends Disposable {
277277
// Telemetry
278278
let telemetryService: ITelemetryService;
279279
const appenders: ITelemetryAppender[] = [];
280+
const internalTelemetry = isInternalTelemetry(productService, configurationService);
280281
if (supportsTelemetry(productService, environmentService)) {
281282
const logAppender = new TelemetryLogAppender(loggerService, environmentService);
282283
appenders.push(logAppender);
283284
const { installSourcePath } = environmentService;
284285
if (productService.aiConfig?.ariaKey) {
285-
const collectorAppender = new OneDataSystemWebAppender(configurationService, 'monacoworkbench', null, productService.aiConfig.ariaKey);
286+
const collectorAppender = new OneDataSystemWebAppender(internalTelemetry, 'monacoworkbench', null, productService.aiConfig.ariaKey);
286287
this._register(toDisposable(() => collectorAppender.flush())); // Ensure the 1DS appender is disposed so that it flushes remaining data
287288
appenders.push(collectorAppender);
288289
}
289290

290291
telemetryService = new TelemetryService({
291292
appenders,
292-
commonProperties: resolveCommonProperties(fileService, release(), hostname(), process.arch, productService.commit, productService.version, this.configuration.machineId, productService.msftInternalDomains, installSourcePath),
293+
commonProperties: resolveCommonProperties(fileService, release(), hostname(), process.arch, productService.commit, productService.version, this.configuration.machineId, internalTelemetry, installSourcePath),
293294
sendErrorTelemetry: true,
294295
piiPaths: getPiiPathsFromEnvironment(environmentService),
295296
}, configurationService, productService);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import { resolveCommonProperties } from 'vs/platform/telemetry/common/commonProp
7575
import { ITelemetryService, machineIdKey, TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
7676
import { TelemetryAppenderClient } from 'vs/platform/telemetry/common/telemetryIpc';
7777
import { ITelemetryServiceConfig, TelemetryService } from 'vs/platform/telemetry/common/telemetryService';
78-
import { getPiiPathsFromEnvironment, getTelemetryLevel, NullTelemetryService, supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
78+
import { getPiiPathsFromEnvironment, getTelemetryLevel, isInternalTelemetry, NullTelemetryService, supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
7979
import { IUpdateService } from 'vs/platform/update/common/update';
8080
import { UpdateChannel } from 'vs/platform/update/common/updateIpc';
8181
import { DarwinUpdateService } from 'vs/platform/update/electron-main/updateService.darwin';
@@ -680,9 +680,10 @@ export class CodeApplication extends Disposable {
680680

681681
// Telemetry
682682
if (supportsTelemetry(this.productService, this.environmentMainService)) {
683+
const isInternal = isInternalTelemetry(this.productService, this.configurationService);
683684
const channel = getDelayedChannel(sharedProcessReady.then(client => client.getChannel('telemetryAppender')));
684685
const appender = new TelemetryAppenderClient(channel);
685-
const commonProperties = resolveCommonProperties(this.fileService, release(), hostname(), process.arch, this.productService.commit, this.productService.version, machineId, this.productService.msftInternalDomains, this.environmentMainService.installSourcePath);
686+
const commonProperties = resolveCommonProperties(this.fileService, release(), hostname(), process.arch, this.productService.commit, this.productService.version, machineId, isInternal, this.environmentMainService.installSourcePath);
686687
const piiPaths = getPiiPathsFromEnvironment(this.environmentMainService);
687688
const config: ITelemetryServiceConfig = { appenders: [appender], commonProperties, piiPaths, sendErrorTelemetry: true };
688689

src/vs/code/node/cliProcessMain.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import { StateService } from 'vs/platform/state/node/stateService';
5252
import { resolveCommonProperties } from 'vs/platform/telemetry/common/commonProperties';
5353
import { ITelemetryService, machineIdKey } from 'vs/platform/telemetry/common/telemetry';
5454
import { ITelemetryServiceConfig, TelemetryService } from 'vs/platform/telemetry/common/telemetryService';
55-
import { supportsTelemetry, NullTelemetryService, getPiiPathsFromEnvironment } from 'vs/platform/telemetry/common/telemetryUtils';
55+
import { supportsTelemetry, NullTelemetryService, getPiiPathsFromEnvironment, isInternalTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
5656
import { OneDataSystemAppender } from 'vs/platform/telemetry/node/1dsAppender';
5757
import { buildTelemetryMessage } from 'vs/platform/telemetry/node/telemetry';
5858
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
@@ -187,9 +187,10 @@ class CliMain extends Disposable {
187187

188188
// Telemetry
189189
const appenders: OneDataSystemAppender[] = [];
190+
const isInternal = isInternalTelemetry(productService, configurationService);
190191
if (supportsTelemetry(productService, environmentService)) {
191192
if (productService.aiConfig && productService.aiConfig.ariaKey) {
192-
appenders.push(new OneDataSystemAppender(configurationService, 'monacoworkbench', null, productService.aiConfig.ariaKey));
193+
appenders.push(new OneDataSystemAppender(isInternal, 'monacoworkbench', null, productService.aiConfig.ariaKey));
193194
}
194195

195196
const { installSourcePath } = environmentService;
@@ -208,7 +209,7 @@ class CliMain extends Disposable {
208209
}
209210
}
210211

211-
return resolveCommonProperties(fileService, release(), hostname(), process.arch, productService.commit, productService.version, machineId, productService.msftInternalDomains, installSourcePath);
212+
return resolveCommonProperties(fileService, release(), hostname(), process.arch, productService.commit, productService.version, machineId, isInternal, installSourcePath);
212213
})(),
213214
piiPaths: getPiiPathsFromEnvironment(environmentService)
214215
};

src/vs/platform/telemetry/browser/1dsAppender.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import type { AppInsightsCore } from '@microsoft/1ds-core-js';
7-
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
87
import { AbstractOneDataSystemAppender } from 'vs/platform/telemetry/common/1dsAppender';
98

109

1110
export class OneDataSystemWebAppender extends AbstractOneDataSystemAppender {
1211
constructor(
13-
configurationService: IConfigurationService | undefined,
12+
isInternalTelemetry: boolean,
1413
eventPrefix: string,
1514
defaultData: { [key: string]: any } | null,
1615
iKeyOrClientFactory: string | (() => AppInsightsCore), // allow factory function for testing
1716
) {
18-
super(configurationService, eventPrefix, defaultData, iKeyOrClientFactory);
17+
super(isInternalTelemetry, eventPrefix, defaultData, iKeyOrClientFactory);
1918

2019
// If we cannot fetch the endpoint it means it is down and we should not send any telemetry.
2120
// This is most likely due to ad blockers

src/vs/platform/telemetry/common/1dsAppender.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type { AppInsightsCore, IExtendedConfiguration } from '@microsoft/1ds-cor
77
import type { IChannelConfiguration, IXHROverride, PostChannel } from '@microsoft/1ds-post-js';
88
import { onUnexpectedError } from 'vs/base/common/errors';
99
import { mixin } from 'vs/base/common/objects';
10-
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1110
import { ITelemetryAppender, validateTelemetryData } from 'vs/platform/telemetry/common/telemetryUtils';
1211

1312
const endpointUrl = 'https://mobile.events.data.microsoft.com/OneCollector/1.0';
@@ -63,7 +62,7 @@ export abstract class AbstractOneDataSystemAppender implements ITelemetryAppende
6362
protected readonly endPointUrl = endpointUrl;
6463

6564
constructor(
66-
private readonly _configurationService: IConfigurationService | undefined,
65+
private readonly _isInternalTelemetry: boolean,
6766
private _eventPrefix: string,
6867
private _defaultData: { [key: string]: any } | null,
6968
iKeyOrClientFactory: string | (() => AppInsightsCore), // allow factory function for testing
@@ -92,8 +91,7 @@ export abstract class AbstractOneDataSystemAppender implements ITelemetryAppende
9291
}
9392

9493
if (!this._asyncAiCore) {
95-
const isInternal = this._configurationService?.getValue<boolean>('telemetry.internalTesting');
96-
this._asyncAiCore = getClient(this._aiCoreOrKey, isInternal, this._xhrOverride);
94+
this._asyncAiCore = getClient(this._aiCoreOrKey, this._isInternalTelemetry, this._xhrOverride);
9795
}
9896

9997
this._asyncAiCore.then(

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export async function resolveCommonProperties(
2525
commit: string | undefined,
2626
version: string | undefined,
2727
machineId: string | undefined,
28-
msftInternalDomains: string[] | undefined,
28+
isInternalTelemetry: boolean,
2929
installSourcePath: string,
3030
product?: string
3131
): Promise<{ [name: string]: string | boolean | undefined }> {
@@ -50,10 +50,9 @@ export async function resolveCommonProperties(
5050
// __GDPR__COMMON__ "common.product" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
5151
result['common.product'] = product || 'desktop';
5252

53-
const msftInternal = verifyMicrosoftInternalDomain(msftInternalDomains || []);
54-
if (msftInternal) {
53+
if (isInternalTelemetry) {
5554
// __GDPR__COMMON__ "common.msftInternal" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
56-
result['common.msftInternal'] = msftInternal;
55+
result['common.msftInternal'] = isInternalTelemetry;
5756
}
5857

5958
// dynamic properties which value differs on each call

src/vs/platform/telemetry/common/telemetryUtils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { URI } from 'vs/base/common/uri';
1111
import { ConfigurationTarget, ConfigurationTargetToString, IConfigurationService } from 'vs/platform/configuration/common/configuration';
1212
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1313
import { IProductService } from 'vs/platform/product/common/productService';
14+
import { verifyMicrosoftInternalDomain } from 'vs/platform/telemetry/common/commonProperties';
1415
import { ClassifiedEvent, GDPRClassification, StrictPropertyCheck } from 'vs/platform/telemetry/common/gdprTypings';
1516
import { ICustomEndpointTelemetryService, ITelemetryData, ITelemetryEndpoint, ITelemetryInfo, ITelemetryService, TelemetryConfiguration, TelemetryLevel, TELEMETRY_OLD_SETTING_ID, TELEMETRY_SETTING_ID } from 'vs/platform/telemetry/common/telemetry';
1617

@@ -252,6 +253,18 @@ function flatKeys(result: string[], prefix: string, value: { [key: string]: any
252253
}
253254
}
254255

256+
/**
257+
* Whether or not this is an internal user
258+
* @param productService The product service
259+
* @param configService The config servivce
260+
* @returns true if internal, false otherwise
261+
*/
262+
export function isInternalTelemetry(productService: IProductService, configService: IConfigurationService) {
263+
const msftInternalDomains = productService.msftInternalDomains || [];
264+
const internalTesting = configService.getValue<boolean>('telemetry.internalTesting');
265+
return verifyMicrosoftInternalDomain(msftInternalDomains) || internalTesting;
266+
}
267+
255268
interface IPathEnvironment {
256269
appRoot: string;
257270
extensionsPath: string;

src/vs/platform/telemetry/node/1dsAppender.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
import type { AppInsightsCore } from '@microsoft/1ds-core-js';
77
import type { IPayloadData, IXHROverride } from '@microsoft/1ds-post-js';
88
import * as https from 'https';
9-
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
109
import { AbstractOneDataSystemAppender } from 'vs/platform/telemetry/common/1dsAppender';
1110

1211

1312
export class OneDataSystemAppender extends AbstractOneDataSystemAppender {
1413

1514
constructor(
16-
configurationService: IConfigurationService | undefined,
15+
isInternalTelemetry: boolean,
1716
eventPrefix: string,
1817
defaultData: { [key: string]: any } | null,
1918
iKeyOrClientFactory: string | (() => AppInsightsCore), // allow factory function for testing
@@ -48,6 +47,6 @@ export class OneDataSystemAppender extends AbstractOneDataSystemAppender {
4847
}
4948
};
5049

51-
super(configurationService, eventPrefix, defaultData, iKeyOrClientFactory, customHttpXHROverride);
50+
super(isInternalTelemetry, eventPrefix, defaultData, iKeyOrClientFactory, customHttpXHROverride);
5251
}
5352
}

src/vs/platform/telemetry/test/browser/1dsAppender.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ suite('AIAdapter', () => {
3333

3434
setup(() => {
3535
appInsightsMock = new AppInsightsCoreMock();
36-
adapter = new OneDataSystemWebAppender(undefined, prefix, undefined!, () => appInsightsMock);
36+
adapter = new OneDataSystemWebAppender(false, prefix, undefined!, () => appInsightsMock);
3737
});
3838

3939
teardown(() => {
@@ -48,7 +48,7 @@ suite('AIAdapter', () => {
4848
});
4949

5050
test('addional data', () => {
51-
adapter = new OneDataSystemWebAppender(undefined, prefix, { first: '1st', second: 2, third: true }, () => appInsightsMock);
51+
adapter = new OneDataSystemWebAppender(false, prefix, { first: '1st', second: 2, third: true }, () => appInsightsMock);
5252
adapter.log('testEvent');
5353

5454
assert.strictEqual(appInsightsMock.events.length, 1);

src/vs/server/node/serverServices.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { RequestService } from 'vs/platform/request/node/requestService';
4949
import { resolveCommonProperties } from 'vs/platform/telemetry/common/commonProperties';
5050
import { ITelemetryService, TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
5151
import { ITelemetryServiceConfig } from 'vs/platform/telemetry/common/telemetryService';
52-
import { getPiiPathsFromEnvironment, ITelemetryAppender, NullAppender, supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
52+
import { getPiiPathsFromEnvironment, isInternalTelemetry, ITelemetryAppender, NullAppender, supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
5353
import ErrorTelemetry from 'vs/platform/telemetry/node/errorTelemetry';
5454
import { IPtyService, TerminalSettingId } from 'vs/platform/terminal/common/terminal';
5555
import { PtyHostService } from 'vs/platform/terminal/node/ptyHostService';
@@ -131,15 +131,16 @@ export async function setupServerServices(connectionToken: ServerConnectionToken
131131

132132
let oneDsAppender: ITelemetryAppender = NullAppender;
133133
const machineId = await getMachineId();
134+
const isInternal = isInternalTelemetry(productService, configurationService);
134135
if (supportsTelemetry(productService, environmentService)) {
135136
if (productService.aiConfig && productService.aiConfig.ariaKey) {
136-
oneDsAppender = new OneDataSystemAppender(configurationService, eventPrefix, null, productService.aiConfig.ariaKey);
137+
oneDsAppender = new OneDataSystemAppender(isInternal, eventPrefix, null, productService.aiConfig.ariaKey);
137138
disposables.add(toDisposable(() => oneDsAppender?.flush())); // Ensure the AI appender is disposed so that it flushes remaining data
138139
}
139140

140141
const config: ITelemetryServiceConfig = {
141142
appenders: [oneDsAppender],
142-
commonProperties: resolveCommonProperties(fileService, release(), hostname(), process.arch, productService.commit, productService.version + '-remote', machineId, productService.msftInternalDomains, environmentService.installSourcePath, 'remoteAgent'),
143+
commonProperties: resolveCommonProperties(fileService, release(), hostname(), process.arch, productService.commit, productService.version + '-remote', machineId, isInternal, environmentService.installSourcePath, 'remoteAgent'),
143144
piiPaths: getPiiPathsFromEnvironment(environmentService)
144145
};
145146
const initialTelemetryLevelArg = environmentService.args['telemetry-level'];

0 commit comments

Comments
 (0)