Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Ensure internal flag isn't applied to non internal data
  • Loading branch information
lramos15 committed Jul 5, 2022
commit 0a910ba3c143c86f914f5c767844e13ce86521d3
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class SharedProcessMain extends Disposable {
const { installSourcePath } = environmentService;
const internalTesting = configurationService.getValue<boolean>('telemetry.internalTesting');
if (internalTesting && productService.aiConfig?.ariaKey) {
const collectorAppender = new OneDataSystemWebAppender('monacoworkbench', null, productService.aiConfig.ariaKey);
const collectorAppender = new OneDataSystemWebAppender(configurationService, 'monacoworkbench', null, productService.aiConfig.ariaKey);
this._register(toDisposable(() => collectorAppender.flush())); // Ensure the 1DS appender is disposed so that it flushes remaining data
appenders.push(collectorAppender);
} else if (productService.aiConfig && productService.aiConfig.asimovKey) {
Expand Down
4 changes: 3 additions & 1 deletion src/vs/platform/telemetry/browser/1dsAppender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
*--------------------------------------------------------------------------------------------*/

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


export class OneDataSystemWebAppender extends AbstractOneDataSystemAppender {
constructor(
configurationService: IConfigurationService,
eventPrefix: string,
defaultData: { [key: string]: any } | null,
iKeyOrClientFactory: string | (() => AppInsightsCore), // allow factory function for testing
) {
super(eventPrefix, defaultData, iKeyOrClientFactory);
super(configurationService, eventPrefix, defaultData, iKeyOrClientFactory);

// If we cannot fetch the endpoint it means it is down and we should not send any telemetry.
// This is most likely due to ad blockers
Expand Down
17 changes: 11 additions & 6 deletions src/vs/platform/telemetry/common/1dsAppender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import type { AppInsightsCore, IExtendedConfiguration } from '@microsoft/1ds-cor
import type { IChannelConfiguration, IXHROverride, PostChannel } from '@microsoft/1ds-post-js';
import { onUnexpectedError } from 'vs/base/common/errors';
import { mixin } from 'vs/base/common/objects';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ITelemetryAppender, validateTelemetryData } from 'vs/platform/telemetry/common/telemetryUtils';

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

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

appInsightsCore.addTelemetryInitializer((envelope) => {
envelope['ext'] = envelope['ext'] ?? {};
envelope['ext']['utc'] = envelope['ext']['utc'] ?? {};
// Sets it to be internal only based on Windows UTC flagging
envelope['ext']['utc']['flags'] = 0x0000811ECD;
if (addInternalFlag) {
envelope['ext'] = envelope['ext'] ?? {};
envelope['ext']['utc'] = envelope['ext']['utc'] ?? {};
// Sets it to be internal only based on Windows UTC flagging
envelope['ext']['utc']['flags'] = 0x0000811ECD;
}
});

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

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

if (!this._asyncAiCore) {
this._asyncAiCore = getClient(this._aiCoreOrKey, this._xhrOverride);
const isInternal = this._configurationService.getValue<boolean>('telemetry.internalTesting');
this._asyncAiCore = getClient(this._aiCoreOrKey, isInternal, this._xhrOverride);
}

this._asyncAiCore.then(
Expand Down
4 changes: 3 additions & 1 deletion src/vs/platform/telemetry/node/1dsAppender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import type { AppInsightsCore } from '@microsoft/1ds-core-js';
import type { IPayloadData, IXHROverride } from '@microsoft/1ds-post-js';
import * as https from 'https';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { AbstractOneDataSystemAppender } from 'vs/platform/telemetry/common/1dsAppender';


export class OneDataSystemAppender extends AbstractOneDataSystemAppender {

constructor(
configurationService: IConfigurationService,
eventPrefix: string,
defaultData: { [key: string]: any } | null,
iKeyOrClientFactory: string | (() => AppInsightsCore), // allow factory function for testing
Expand Down Expand Up @@ -46,6 +48,6 @@ export class OneDataSystemAppender extends AbstractOneDataSystemAppender {
}
};

super(eventPrefix, defaultData, iKeyOrClientFactory, customHttpXHROverride);
super(configurationService, eventPrefix, defaultData, iKeyOrClientFactory, customHttpXHROverride);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class TelemetryService extends Disposable implements ITelemetryService {
const internalTesting = configurationService.getValue<boolean>('telemetry.internalTesting');
const appenders = [];
if (internalTesting || productService.aiConfig?.preferAria) {
const telemetryProvider: ITelemetryAppender = remoteAgentService.getConnection() !== null ? { log: remoteAgentService.logTelemetry.bind(remoteAgentService), flush: remoteAgentService.flushTelemetry.bind(remoteAgentService) } : new OneDataSystemWebAppender('monacoworkbench', null, productService.aiConfig?.ariaKey);
const telemetryProvider: ITelemetryAppender = remoteAgentService.getConnection() !== null ? { log: remoteAgentService.logTelemetry.bind(remoteAgentService), flush: remoteAgentService.flushTelemetry.bind(remoteAgentService) } : new OneDataSystemWebAppender(configurationService, 'monacoworkbench', null, productService.aiConfig?.ariaKey);
appenders.push(telemetryProvider);
} else {
const telemetryProvider: ITelemetryAppender = remoteAgentService.getConnection() !== null ? { log: remoteAgentService.logTelemetry.bind(remoteAgentService), flush: remoteAgentService.flushTelemetry.bind(remoteAgentService) } : new WebAppInsightsAppender('monacoworkbench', productService.aiConfig?.asimovKey);
Expand Down