Check both telemetry.telemetryLevel and telemetry.enableTelemetry

This commit is contained in:
Robert
2023-09-15 15:13:46 +01:00
parent 90093fb9f5
commit 9c76ba35f1
2 changed files with 26 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ import {
LOG_TELEMETRY, LOG_TELEMETRY,
isIntegrationTestMode, isIntegrationTestMode,
isCanary, isCanary,
GLOBAL_TELEMETRY_LEVEL,
} from "../../config"; } from "../../config";
import * as appInsights from "applicationinsights"; import * as appInsights from "applicationinsights";
import { extLogger } from "../logging/vscode"; import { extLogger } from "../logging/vscode";
@@ -93,7 +94,8 @@ export class ExtensionTelemetryListener
): Promise<void> { ): Promise<void> {
if ( if (
e.affectsConfiguration("codeQL.telemetry.enableTelemetry") || e.affectsConfiguration("codeQL.telemetry.enableTelemetry") ||
e.affectsConfiguration("telemetry.enableTelemetry") e.affectsConfiguration("telemetry.enableTelemetry") ||
e.affectsConfiguration("telemetry.telemetryLevel")
) { ) {
await this.initialize(); await this.initialize();
} }
@@ -224,7 +226,7 @@ export class ExtensionTelemetryListener
// if global telemetry is disabled, avoid showing the dialog or making any changes // if global telemetry is disabled, avoid showing the dialog or making any changes
let result = undefined; let result = undefined;
if ( if (
GLOBAL_ENABLE_TELEMETRY.getValue() && isGlobalTelemetryEnabled() &&
// Avoid showing the dialog if we are in integration test mode. // Avoid showing the dialog if we are in integration test mode.
!isIntegrationTestMode() !isIntegrationTestMode()
) { ) {
@@ -297,3 +299,21 @@ export async function initializeTelemetry(
ctx.subscriptions.push(telemetryListener); ctx.subscriptions.push(telemetryListener);
return telemetryListener; return telemetryListener;
} }
function isGlobalTelemetryEnabled(): boolean {
// If "enableTelemetry" is set to false, no telemetry will be sent regardless of the value of "telemetryLevel"
const enableTelemetry: boolean | undefined =
GLOBAL_ENABLE_TELEMETRY.getValue();
if (enableTelemetry === false) {
return false;
}
// If a value for "telemetry.telemetryLevel" is provided, then use that
const telemetryLevel: string | undefined = GLOBAL_TELEMETRY_LEVEL.getValue();
if (telemetryLevel !== undefined) {
return telemetryLevel === "error" || telemetryLevel === "on";
}
// Otherwise fall back to the deprecated "telemetry.enableTelemetry" setting
return !!enableTelemetry;
}

View File

@@ -86,6 +86,10 @@ export const GLOBAL_ENABLE_TELEMETRY = new Setting(
"enableTelemetry", "enableTelemetry",
GLOBAL_TELEMETRY_SETTING, GLOBAL_TELEMETRY_SETTING,
); );
export const GLOBAL_TELEMETRY_LEVEL = new Setting(
"telemetryLevel",
GLOBAL_TELEMETRY_SETTING,
);
// Distribution configuration // Distribution configuration
const DISTRIBUTION_SETTING = new Setting("cli", ROOT_SETTING); const DISTRIBUTION_SETTING = new Setting("cli", ROOT_SETTING);