Merge pull request #2030 from github/robertbrignull/disable-new-telemetry
Don't send new telemetry data unless opted-in
This commit is contained in:
@@ -92,6 +92,15 @@ export const GLOBAL_ENABLE_TELEMETRY = new 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
|
||||
const DISTRIBUTION_SETTING = new Setting("cli", ROOT_SETTING);
|
||||
export const CUSTOM_CODEQL_PATH_SETTING = new Setting(
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
LOG_TELEMETRY,
|
||||
isIntegrationTestMode,
|
||||
isCanary,
|
||||
newTelemetryEnabled,
|
||||
} from "./config";
|
||||
import * as appInsights from "applicationinsights";
|
||||
import { extLogger } from "./common";
|
||||
@@ -172,6 +173,10 @@ export class TelemetryListener extends ConfigListener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!newTelemetryEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.reporter.sendTelemetryEvent(
|
||||
"ui-interaction",
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
} from "../../../src/telemetry";
|
||||
import { UserCancellationException } from "../../../src/commandRunner";
|
||||
import { ENABLE_TELEMETRY } from "../../../src/config";
|
||||
import * as Config from "../../../src/config";
|
||||
import { createMockExtensionContext } from "./index";
|
||||
|
||||
// setting preferences can trigger lots of background activity
|
||||
@@ -388,6 +389,37 @@ describe("telemetry reporting", () => {
|
||||
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) {
|
||||
await workspace
|
||||
.getConfiguration(section)
|
||||
|
||||
Reference in New Issue
Block a user