Skip to content

Commit 92d25e3

Browse files
authored
Update UTC flags properly for 1DS (microsoft#154187)
Ensure internal flag isn't applied to non internal data
1 parent 2932e29 commit 92d25e3

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class SharedProcessMain extends Disposable {
283283
const { installSourcePath } = environmentService;
284284
const internalTesting = configurationService.getValue<boolean>('telemetry.internalTesting');
285285
if (internalTesting && productService.aiConfig?.ariaKey) {
286-
const collectorAppender = new OneDataSystemWebAppender('monacoworkbench', null, productService.aiConfig.ariaKey);
286+
const collectorAppender = new OneDataSystemWebAppender(configurationService, 'monacoworkbench', null, productService.aiConfig.ariaKey);
287287
this._register(toDisposable(() => collectorAppender.flush())); // Ensure the 1DS appender is disposed so that it flushes remaining data
288288
appenders.push(collectorAppender);
289289
} else if (productService.aiConfig && productService.aiConfig.asimovKey) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
*--------------------------------------------------------------------------------------------*/
55

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

910

1011
export class OneDataSystemWebAppender extends AbstractOneDataSystemAppender {
1112
constructor(
13+
configurationService: IConfigurationService,
1214
eventPrefix: string,
1315
defaultData: { [key: string]: any } | null,
1416
iKeyOrClientFactory: string | (() => AppInsightsCore), // allow factory function for testing
1517
) {
16-
super(eventPrefix, defaultData, iKeyOrClientFactory);
18+
super(configurationService, eventPrefix, defaultData, iKeyOrClientFactory);
1719

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

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ 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';
1011
import { ITelemetryAppender, validateTelemetryData } from 'vs/platform/telemetry/common/telemetryUtils';
1112

1213
const endpointUrl = 'https://mobile.events.data.microsoft.com/OneCollector/1.0';
1314

14-
async function getClient(instrumentationKey: string, xhrOverride?: IXHROverride): Promise<AppInsightsCore> {
15+
async function getClient(instrumentationKey: string, addInternalFlag?: boolean, xhrOverride?: IXHROverride): Promise<AppInsightsCore> {
1516
const oneDs = await import('@microsoft/1ds-core-js');
1617
const postPlugin = await import('@microsoft/1ds-post-js');
1718
const appInsightsCore = new oneDs.AppInsightsCore();
@@ -43,10 +44,12 @@ async function getClient(instrumentationKey: string, xhrOverride?: IXHROverride)
4344
appInsightsCore.initialize(coreConfig, []);
4445

4546
appInsightsCore.addTelemetryInitializer((envelope) => {
46-
envelope['ext'] = envelope['ext'] ?? {};
47-
envelope['ext']['utc'] = envelope['ext']['utc'] ?? {};
48-
// Sets it to be internal only based on Windows UTC flagging
49-
envelope['ext']['utc']['flags'] = 0x0000811ECD;
47+
if (addInternalFlag) {
48+
envelope['ext'] = envelope['ext'] ?? {};
49+
envelope['ext']['utc'] = envelope['ext']['utc'] ?? {};
50+
// Sets it to be internal only based on Windows UTC flagging
51+
envelope['ext']['utc']['flags'] = 0x0000811ECD;
52+
}
5053
});
5154

5255
return appInsightsCore;
@@ -60,6 +63,7 @@ export abstract class AbstractOneDataSystemAppender implements ITelemetryAppende
6063
protected readonly endPointUrl = endpointUrl;
6164

6265
constructor(
66+
private readonly _configurationService: IConfigurationService,
6367
private _eventPrefix: string,
6468
private _defaultData: { [key: string]: any } | null,
6569
iKeyOrClientFactory: string | (() => AppInsightsCore), // allow factory function for testing
@@ -88,7 +92,8 @@ export abstract class AbstractOneDataSystemAppender implements ITelemetryAppende
8892
}
8993

9094
if (!this._asyncAiCore) {
91-
this._asyncAiCore = getClient(this._aiCoreOrKey, this._xhrOverride);
95+
const isInternal = this._configurationService.getValue<boolean>('telemetry.internalTesting');
96+
this._asyncAiCore = getClient(this._aiCoreOrKey, isInternal, this._xhrOverride);
9297
}
9398

9499
this._asyncAiCore.then(

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
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';
910
import { AbstractOneDataSystemAppender } from 'vs/platform/telemetry/common/1dsAppender';
1011

1112

1213
export class OneDataSystemAppender extends AbstractOneDataSystemAppender {
1314

1415
constructor(
16+
configurationService: IConfigurationService,
1517
eventPrefix: string,
1618
defaultData: { [key: string]: any } | null,
1719
iKeyOrClientFactory: string | (() => AppInsightsCore), // allow factory function for testing
@@ -46,6 +48,6 @@ export class OneDataSystemAppender extends AbstractOneDataSystemAppender {
4648
}
4749
};
4850

49-
super(eventPrefix, defaultData, iKeyOrClientFactory, customHttpXHROverride);
51+
super(configurationService, eventPrefix, defaultData, iKeyOrClientFactory, customHttpXHROverride);
5052
}
5153
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class TelemetryService extends Disposable implements ITelemetryService {
4343
const internalTesting = configurationService.getValue<boolean>('telemetry.internalTesting');
4444
const appenders = [];
4545
if (internalTesting || productService.aiConfig?.preferAria) {
46-
const telemetryProvider: ITelemetryAppender = remoteAgentService.getConnection() !== null ? { log: remoteAgentService.logTelemetry.bind(remoteAgentService), flush: remoteAgentService.flushTelemetry.bind(remoteAgentService) } : new OneDataSystemWebAppender('monacoworkbench', null, productService.aiConfig?.ariaKey);
46+
const telemetryProvider: ITelemetryAppender = remoteAgentService.getConnection() !== null ? { log: remoteAgentService.logTelemetry.bind(remoteAgentService), flush: remoteAgentService.flushTelemetry.bind(remoteAgentService) } : new OneDataSystemWebAppender(configurationService, 'monacoworkbench', null, productService.aiConfig?.ariaKey);
4747
appenders.push(telemetryProvider);
4848
} else {
4949
const telemetryProvider: ITelemetryAppender = remoteAgentService.getConnection() !== null ? { log: remoteAgentService.logTelemetry.bind(remoteAgentService), flush: remoteAgentService.flushTelemetry.bind(remoteAgentService) } : new WebAppInsightsAppender('monacoworkbench', productService.aiConfig?.asimovKey);

0 commit comments

Comments
 (0)