Better telemetry adblock check (#157279)

Dynamic adblock check based on telemetry setting
This commit is contained in:
Logan Ramos 2022-08-05 14:20:48 -04:00 committed by GitHub
parent f314f642da
commit 46b6f3eb64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 6 deletions

View file

@ -103,9 +103,9 @@ import { ExtensionsProfileScannerService, IExtensionsProfileScannerService } fro
import { PolicyChannelClient } from 'vs/platform/policy/common/policyIpc';
import { IPolicyService, NullPolicyService } from 'vs/platform/policy/common/policy';
import { UserDataProfilesNativeService } from 'vs/platform/userDataProfile/electron-sandbox/userDataProfile';
import { OneDataSystemWebAppender } from 'vs/platform/telemetry/browser/1dsAppender';
import { DefaultExtensionsProfileInitService } from 'vs/platform/extensionManagement/electron-sandbox/defaultExtensionsProfileInit';
import { SharedProcessRequestService } from 'vs/platform/request/electron-browser/sharedProcessRequestService';
import { OneDataSystemAppender } from 'vs/platform/telemetry/node/1dsAppender';
class SharedProcessMain extends Disposable {
@ -283,7 +283,7 @@ class SharedProcessMain extends Disposable {
appenders.push(logAppender);
const { installSourcePath } = environmentService;
if (productService.aiConfig?.ariaKey) {
const collectorAppender = new OneDataSystemWebAppender(internalTelemetry, 'monacoworkbench', null, productService.aiConfig.ariaKey);
const collectorAppender = new OneDataSystemAppender(internalTelemetry, '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);
}

View file

@ -12,7 +12,7 @@ import { IProductService } from 'vs/platform/product/common/productService';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { OneDataSystemWebAppender } from 'vs/platform/telemetry/browser/1dsAppender';
import { ClassifiedEvent, IGDPRProperty, OmitMetadata, StrictPropertyCheck } from 'vs/platform/telemetry/common/gdprTypings';
import { ITelemetryData, ITelemetryInfo, ITelemetryService, TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
import { ITelemetryData, ITelemetryInfo, ITelemetryService, TelemetryLevel, TELEMETRY_SETTING_ID } from 'vs/platform/telemetry/common/telemetry';
import { TelemetryLogAppender } from 'vs/platform/telemetry/common/telemetryLogAppender';
import { ITelemetryServiceConfig, TelemetryService as BaseTelemetryService } from 'vs/platform/telemetry/common/telemetryService';
import { isInternalTelemetry, ITelemetryAppender, NullTelemetryService, supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
@ -38,6 +38,34 @@ export class TelemetryService extends Disposable implements ITelemetryService {
super();
if (supportsTelemetry(productService, environmentService) && productService.aiConfig?.ariaKey) {
this.impl = this.initializeService(environmentService, loggerService, configurationService, storageService, productService, remoteAgentService);
} else {
this.impl = NullTelemetryService;
}
// When the level changes it could change from off to on and we want to make sure telemetry is properly intialized
this._register(configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(TELEMETRY_SETTING_ID)) {
this.impl = this.initializeService(environmentService, loggerService, configurationService, storageService, productService, remoteAgentService);
}
}));
}
/**
* Initializes the telemetry service to be a full fledged service.
* This is only done once and only when telemetry is enabled as this will also ping the endpoint to
* ensure its not adblocked and we can send telemetry
*/
private initializeService(
environmentService: IBrowserWorkbenchEnvironmentService,
loggerService: ILoggerService,
configurationService: IConfigurationService,
storageService: IStorageService,
productService: IProductService,
remoteAgentService: IRemoteAgentService
) {
const telemetrySupported = supportsTelemetry(productService, environmentService) && productService.aiConfig?.ariaKey;
if (telemetrySupported && this.impl === NullTelemetryService && this.telemetryLevel.value !== TelemetryLevel.NONE) {
// If remote server is present send telemetry through that, else use the client side appender
const appenders = [];
const isInternal = isInternalTelemetry(productService, configurationService);
@ -50,10 +78,9 @@ export class TelemetryService extends Disposable implements ITelemetryService {
sendErrorTelemetry: this.sendErrorTelemetry,
};
this.impl = this._register(new BaseTelemetryService(config, configurationService, productService));
} else {
this.impl = NullTelemetryService;
return this._register(new BaseTelemetryService(config, configurationService, productService));
}
return NullTelemetryService;
}
setExperimentProperty(name: string, value: string): void {