Skip to content

Commit 9c76ba3

Browse files
Check both telemetry.telemetryLevel and telemetry.enableTelemetry
1 parent 90093fb commit 9c76ba3

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

extensions/ql-vscode/src/common/vscode/telemetry.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
LOG_TELEMETRY,
1414
isIntegrationTestMode,
1515
isCanary,
16+
GLOBAL_TELEMETRY_LEVEL,
1617
} from "../../config";
1718
import * as appInsights from "applicationinsights";
1819
import { extLogger } from "../logging/vscode";
@@ -93,7 +94,8 @@ export class ExtensionTelemetryListener
9394
): Promise<void> {
9495
if (
9596
e.affectsConfiguration("codeQL.telemetry.enableTelemetry") ||
96-
e.affectsConfiguration("telemetry.enableTelemetry")
97+
e.affectsConfiguration("telemetry.enableTelemetry") ||
98+
e.affectsConfiguration("telemetry.telemetryLevel")
9799
) {
98100
await this.initialize();
99101
}
@@ -224,7 +226,7 @@ export class ExtensionTelemetryListener
224226
// if global telemetry is disabled, avoid showing the dialog or making any changes
225227
let result = undefined;
226228
if (
227-
GLOBAL_ENABLE_TELEMETRY.getValue() &&
229+
isGlobalTelemetryEnabled() &&
228230
// Avoid showing the dialog if we are in integration test mode.
229231
!isIntegrationTestMode()
230232
) {
@@ -297,3 +299,21 @@ export async function initializeTelemetry(
297299
ctx.subscriptions.push(telemetryListener);
298300
return telemetryListener;
299301
}
302+
303+
function isGlobalTelemetryEnabled(): boolean {
304+
// If "enableTelemetry" is set to false, no telemetry will be sent regardless of the value of "telemetryLevel"
305+
const enableTelemetry: boolean | undefined =
306+
GLOBAL_ENABLE_TELEMETRY.getValue();
307+
if (enableTelemetry === false) {
308+
return false;
309+
}
310+
311+
// If a value for "telemetry.telemetryLevel" is provided, then use that
312+
const telemetryLevel: string | undefined = GLOBAL_TELEMETRY_LEVEL.getValue();
313+
if (telemetryLevel !== undefined) {
314+
return telemetryLevel === "error" || telemetryLevel === "on";
315+
}
316+
317+
// Otherwise fall back to the deprecated "telemetry.enableTelemetry" setting
318+
return !!enableTelemetry;
319+
}

extensions/ql-vscode/src/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ export const GLOBAL_ENABLE_TELEMETRY = new Setting(
8686
"enableTelemetry",
8787
GLOBAL_TELEMETRY_SETTING,
8888
);
89+
export const GLOBAL_TELEMETRY_LEVEL = new Setting(
90+
"telemetryLevel",
91+
GLOBAL_TELEMETRY_SETTING,
92+
);
8993

9094
// Distribution configuration
9195
const DISTRIBUTION_SETTING = new Setting("cli", ROOT_SETTING);

0 commit comments

Comments
 (0)