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,
isIntegrationTestMode,
isCanary,
GLOBAL_TELEMETRY_LEVEL,
} from "../../config";
import * as appInsights from "applicationinsights";
import { extLogger } from "../logging/vscode";
@@ -93,7 +94,8 @@ export class ExtensionTelemetryListener
): Promise<void> {
if (
e.affectsConfiguration("codeQL.telemetry.enableTelemetry") ||
e.affectsConfiguration("telemetry.enableTelemetry")
e.affectsConfiguration("telemetry.enableTelemetry") ||
e.affectsConfiguration("telemetry.telemetryLevel")
) {
await this.initialize();
}
@@ -224,7 +226,7 @@ export class ExtensionTelemetryListener
// if global telemetry is disabled, avoid showing the dialog or making any changes
let result = undefined;
if (
GLOBAL_ENABLE_TELEMETRY.getValue() &&
isGlobalTelemetryEnabled() &&
// Avoid showing the dialog if we are in integration test mode.
!isIntegrationTestMode()
) {
@@ -297,3 +299,21 @@ export async function initializeTelemetry(
ctx.subscriptions.push(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",
GLOBAL_TELEMETRY_SETTING,
);
export const GLOBAL_TELEMETRY_LEVEL = new Setting(
"telemetryLevel",
GLOBAL_TELEMETRY_SETTING,
);
// Distribution configuration
const DISTRIBUTION_SETTING = new Setting("cli", ROOT_SETTING);