centralize telemetry level (#131919)

* centralize telemetry level

* add comments and const enum
This commit is contained in:
SteVen Batten
2021-08-30 10:38:42 -07:00
committed by GitHub
parent 9c6b9f0bf5
commit 9525d0e1ed
7 changed files with 46 additions and 13 deletions

View File

@@ -65,7 +65,7 @@ import { ICustomEndpointTelemetryService, ITelemetryService } from 'vs/platform/
import { TelemetryAppenderChannel } from 'vs/platform/telemetry/common/telemetryIpc';
import { TelemetryLogAppender } from 'vs/platform/telemetry/common/telemetryLogAppender';
import { TelemetryService } from 'vs/platform/telemetry/common/telemetryService';
import { combinedAppender, ITelemetryAppender, NullAppender, NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { combinedAppender, getTelemetryLevel, ITelemetryAppender, NullAppender, NullTelemetryService, TelemetryLevel } from 'vs/platform/telemetry/common/telemetryUtils';
import { AppInsightsAppender } from 'vs/platform/telemetry/node/appInsightsAppender';
import { CustomEndpointTelemetryService } from 'vs/platform/telemetry/node/customEndpointTelemetryService';
import { LocalReconnectConstants, TerminalIpcChannels, TerminalSettingId } from 'vs/platform/terminal/common/terminal';
@@ -211,13 +211,14 @@ class SharedProcessMain extends Disposable {
// Telemetry
let telemetryService: ITelemetryService;
let telemetryAppender: ITelemetryAppender;
if (!environmentService.isExtensionDevelopment && !environmentService.disableTelemetry && productService.enableTelemetry) {
let telemetryLevel = getTelemetryLevel(productService, environmentService);
if (telemetryLevel !== TelemetryLevel.NONE) {
telemetryAppender = new TelemetryLogAppender(loggerService, environmentService);
const { appRoot, extensionsPath, isBuilt, installSourcePath } = environmentService;
const { appRoot, extensionsPath, installSourcePath } = environmentService;
// Application Insights
if (productService.aiConfig && productService.aiConfig.asimovKey && isBuilt) {
if (productService.aiConfig && productService.aiConfig.asimovKey && telemetryLevel === TelemetryLevel.USER) {
const appInsightsAppender = new AppInsightsAppender('monacoworkbench', null, productService.aiConfig.asimovKey);
this._register(toDisposable(() => appInsightsAppender.flush())); // Ensure the AI appender is disposed so that it flushes remaining data
telemetryAppender = combinedAppender(appInsightsAppender, telemetryAppender);

View File

@@ -68,7 +68,7 @@ import { resolveCommonProperties } from 'vs/platform/telemetry/common/commonProp
import { ITelemetryService, machineIdKey } from 'vs/platform/telemetry/common/telemetry';
import { TelemetryAppenderClient } from 'vs/platform/telemetry/common/telemetryIpc';
import { ITelemetryServiceConfig, TelemetryService } from 'vs/platform/telemetry/common/telemetryService';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { NullTelemetryService, getTelemetryLevel, TelemetryLevel } from 'vs/platform/telemetry/common/telemetryUtils';
import { IUpdateService } from 'vs/platform/update/common/update';
import { UpdateChannel } from 'vs/platform/update/common/updateIpc';
import { DarwinUpdateService } from 'vs/platform/update/electron-main/updateService.darwin';
@@ -531,7 +531,7 @@ export class CodeApplication extends Disposable {
services.set(IURLService, new SyncDescriptor(NativeURLService));
// Telemetry
if (!this.environmentMainService.isExtensionDevelopment && !this.environmentMainService.args['disable-telemetry'] && !!this.productService.enableTelemetry) {
if (getTelemetryLevel(this.productService, this.environmentMainService) === TelemetryLevel.USER) {
const channel = getDelayedChannel(sharedProcessReady.then(client => client.getChannel('telemetryAppender')));
const appender = new TelemetryAppenderClient(channel);
const commonProperties = resolveCommonProperties(this.fileService, release(), hostname(), process.arch, this.productService.commit, this.productService.version, machineId, this.productService.msftInternalDomains, this.environmentMainService.installSourcePath);

View File

@@ -43,7 +43,7 @@ import { RequestService } from 'vs/platform/request/node/requestService';
import { resolveCommonProperties } from 'vs/platform/telemetry/common/commonProperties';
import { ITelemetryService, machineIdKey } from 'vs/platform/telemetry/common/telemetry';
import { ITelemetryServiceConfig, TelemetryService } from 'vs/platform/telemetry/common/telemetryService';
import { combinedAppender, NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { combinedAppender, getTelemetryLevel, NullTelemetryService, TelemetryLevel } from 'vs/platform/telemetry/common/telemetryUtils';
import { AppInsightsAppender } from 'vs/platform/telemetry/node/appInsightsAppender';
import { buildTelemetryMessage } from 'vs/platform/telemetry/node/telemetry';
@@ -143,7 +143,7 @@ class CliMain extends Disposable {
// Telemetry
const appenders: AppInsightsAppender[] = [];
if (environmentService.isBuilt && !environmentService.isExtensionDevelopment && !environmentService.disableTelemetry && productService.enableTelemetry) {
if (getTelemetryLevel(productService, environmentService) === TelemetryLevel.USER) {
if (productService.aiConfig && productService.aiConfig.asimovKey) {
appenders.push(new AppInsightsAppender('monacoworkbench', null, productService.aiConfig.asimovKey));
}

View File

@@ -8,6 +8,8 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import { safeStringify } from 'vs/base/common/objects';
import { isObject } from 'vs/base/common/types';
import { ConfigurationTarget, ConfigurationTargetToString, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IProductService } from 'vs/platform/product/common/productService';
import { ClassifiedEvent, GDPRClassification, StrictPropertyCheck } from 'vs/platform/telemetry/common/gdprTypings';
import { ICustomEndpointTelemetryService, ITelemetryData, ITelemetryEndpoint, ITelemetryInfo, ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
@@ -102,6 +104,34 @@ export function configurationTelemetry(telemetryService: ITelemetryService, conf
});
}
export const enum TelemetryLevel {
NONE,
LOG,
USER
}
/**
* Determines how telemetry is handled based on the current running configuration.
* To log telemetry locally, the client must not disable telemetry via the CLI
* If client is a built product and telemetry is enabled via the product.json, defer to user setting
* Note that when running from sources, we log telemetry locally but do not send it
*
* @param productService
* @param environmentService
* @returns NONE - telemetry is completely disabled, LOG - telemetry is logged locally but not sent, USER - verify with user setting
*/
export function getTelemetryLevel(productService: IProductService, environmentService: IEnvironmentService): TelemetryLevel {
if (environmentService.disableTelemetry || !productService.enableTelemetry) {
return TelemetryLevel.NONE;
}
if (!environmentService.isBuilt) {
return TelemetryLevel.LOG;
}
return TelemetryLevel.USER;
}
export interface Properties {
[key: string]: string;
}

View File

@@ -11,6 +11,7 @@ import { Disposable } from 'vs/base/common/lifecycle';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IProductService } from 'vs/platform/product/common/productService';
import { getTelemetryLevel, TelemetryLevel } from 'vs/platform/telemetry/common/telemetryUtils';
@extHostNamedCustomer(MainContext.MainThreadTelemetry)
export class MainThreadTelemetry extends Disposable implements MainThreadTelemetryShape {
@@ -29,7 +30,7 @@ export class MainThreadTelemetry extends Disposable implements MainThreadTelemet
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostTelemetry);
if (!this._environmenService.disableTelemetry && this._productService.enableTelemetry) {
if (getTelemetryLevel(this._productService, this._environmenService) !== TelemetryLevel.NONE) {
this._register(this._configurationService.onDidChangeConfiguration(e => {
if (e.affectedKeys.includes('telemetry.enableTelemetry')) {
this._proxy.$onDidChangeTelemetryEnabled(this.telemetryEnabled);
@@ -41,7 +42,7 @@ export class MainThreadTelemetry extends Disposable implements MainThreadTelemet
}
private get telemetryEnabled(): boolean {
if (this._environmenService.disableTelemetry || !this._productService.enableTelemetry) {
if (getTelemetryLevel(this._productService, this._environmenService) !== TelemetryLevel.USER) {
return false;
}

View File

@@ -29,6 +29,7 @@ import { IWebviewWorkbenchService } from 'vs/workbench/contrib/webviewPanel/brow
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { ACTIVE_GROUP, IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { getTelemetryLevel } from 'vs/platform/telemetry/common/telemetryUtils';
export class ReleaseNotesManager {
@@ -194,7 +195,7 @@ export class ReleaseNotesManager {
}
private async addGAParameters(uri: URI, origin: string, experiment = '1'): Promise<URI> {
if (this._environmentService.isBuilt && !this._environmentService.isExtensionDevelopment && !this._environmentService.disableTelemetry && !!this._productService.enableTelemetry) {
if (getTelemetryLevel(this._productService, this._environmentService)) {
if (uri.scheme === 'https' && uri.authority === 'code.visualstudio.com') {
const info = await this._telemetryService.getTelemetryInfo();

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { ITelemetryService, ITelemetryInfo, ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { getTelemetryLevel, NullTelemetryService, TelemetryLevel } from 'vs/platform/telemetry/common/telemetryUtils';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { Disposable } from 'vs/base/common/lifecycle';
import { INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-sandbox/environmentService';
@@ -35,7 +35,7 @@ export class TelemetryService extends Disposable implements ITelemetryService {
) {
super();
if (!environmentService.isExtensionDevelopment && !environmentService.disableTelemetry && !!productService.enableTelemetry) {
if (getTelemetryLevel(productService, environmentService) === TelemetryLevel.LOG) {
const channel = sharedProcessService.getChannel('telemetryAppender');
const config: ITelemetryServiceConfig = {
appender: new TelemetryAppenderClient(channel),