Don't send new telemetry data unless opted-in

This commit is contained in:
Robert
2023-02-01 11:15:51 +00:00
parent fa8def3c8c
commit d780c24994
3 changed files with 46 additions and 0 deletions

View File

@@ -92,6 +92,15 @@ export const GLOBAL_ENABLE_TELEMETRY = new Setting(
GLOBAL_TELEMETRY_SETTING, GLOBAL_TELEMETRY_SETTING,
); );
const ENABLE_NEW_TELEMETRY = new Setting(
"enableNewTelemetry",
TELEMETRY_SETTING,
);
export function newTelemetryEnabled(): boolean {
return ENABLE_NEW_TELEMETRY.getValue<boolean>();
}
// Distribution configuration // Distribution configuration
const DISTRIBUTION_SETTING = new Setting("cli", ROOT_SETTING); const DISTRIBUTION_SETTING = new Setting("cli", ROOT_SETTING);
export const CUSTOM_CODEQL_PATH_SETTING = new Setting( export const CUSTOM_CODEQL_PATH_SETTING = new Setting(

View File

@@ -13,6 +13,7 @@ import {
LOG_TELEMETRY, LOG_TELEMETRY,
isIntegrationTestMode, isIntegrationTestMode,
isCanary, isCanary,
newTelemetryEnabled,
} from "./config"; } from "./config";
import * as appInsights from "applicationinsights"; import * as appInsights from "applicationinsights";
import { extLogger } from "./common"; import { extLogger } from "./common";
@@ -172,6 +173,10 @@ export class TelemetryListener extends ConfigListener {
return; return;
} }
if (!newTelemetryEnabled()) {
return;
}
this.reporter.sendTelemetryEvent( this.reporter.sendTelemetryEvent(
"ui-interaction", "ui-interaction",
{ {

View File

@@ -11,6 +11,7 @@ import {
} from "../../../src/telemetry"; } from "../../../src/telemetry";
import { UserCancellationException } from "../../../src/commandRunner"; import { UserCancellationException } from "../../../src/commandRunner";
import { ENABLE_TELEMETRY } from "../../../src/config"; import { ENABLE_TELEMETRY } from "../../../src/config";
import * as Config from "../../../src/config";
import { createMockExtensionContext } from "./index"; import { createMockExtensionContext } from "./index";
// setting preferences can trigger lots of background activity // setting preferences can trigger lots of background activity
@@ -388,6 +389,37 @@ describe("telemetry reporting", () => {
expect(showInformationMessageSpy).toBeCalledTimes(1); expect(showInformationMessageSpy).toBeCalledTimes(1);
}); });
describe("when new telementry is not enabled", () => {
it("should not send a telementry event", async () => {
await telemetryListener.initialize();
telemetryListener.sendUIInteraction("test");
expect(sendTelemetryEventSpy).not.toBeCalled();
});
});
describe("when new telementry is enabled", () => {
beforeEach(async () => {
jest.spyOn(Config, "newTelemetryEnabled").mockReturnValue(true);
});
it("should not send a telementry event", async () => {
await telemetryListener.initialize();
telemetryListener.sendUIInteraction("test");
expect(sendTelemetryEventSpy).toHaveBeenCalledWith(
"ui-interaction",
{
name: "test",
isCanary,
},
{},
);
});
});
async function enableTelemetry(section: string, value: boolean | undefined) { async function enableTelemetry(section: string, value: boolean | undefined) {
await workspace await workspace
.getConfiguration(section) .getConfiguration(section)