Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send telemetry for addDatabaseSourceToWorkspace setting #3238

Merged
merged 4 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [UNRELEASED]

- Enable collection of telemetry for the `codeQL.addingDatabases.addDatabaseSourceToWorkspace` setting. [#3238](https://github.com/github/vscode-codeql/pull/3238)
- In the CodeQL model editor, you can now select individual method rows and save changes to only the selected rows, instead of having to save the entire library model. [#3156](https://github.com/github/vscode-codeql/pull/3156)
- If you run a query without having selected a database, we show a more intuitive prompt to help you select a database. [#3214](https://github.com/github/vscode-codeql/pull/3214)
- The UI for browsing and running CodeQL tests has moved to use VS Code's built-in test UI. This makes the CodeQL test UI more consistent with the test UIs for other languages.
Expand Down
15 changes: 15 additions & 0 deletions extensions/ql-vscode/src/common/vscode/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,21 @@ export class ExtensionTelemetryListener
this.reporter.sendTelemetryErrorEvent("error", properties, {});
}

sendConfigInformation(config: Record<string, string>): void {
if (!this.reporter) {
return;
}

this.reporter.sendTelemetryEvent(
"config",
{
...config,
cliVersion: this.cliVersionStr,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it also be useful to have the isCanary setting available here to check whether a certain setting is only used by canary users?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me too. We may as well include isCanary here in all the config information events.

},
{},
);
}

/**
* Displays a popup asking the user if they want to enable telemetry
* for this extension.
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ export function allowHttp(): boolean {
);
}

const ADD_DATABASE_SOURCE_TO_WORKSPACE_SETTING = new Setting(
export const ADD_DATABASE_SOURCE_TO_WORKSPACE_SETTING = new Setting(
"addDatabaseSourceToWorkspace",
ADDING_DATABASES_SETTING,
);
Expand Down
12 changes: 12 additions & 0 deletions extensions/ql-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
} from "./common/vscode/archive-filesystem-provider";
import { CliVersionConstraint, CodeQLCliServer } from "./codeql-cli/cli";
import {
ADD_DATABASE_SOURCE_TO_WORKSPACE_SETTING,
addDatabaseSourceToWorkspace,
CliConfigListener,
DistributionConfigListener,
GitHubDatabaseConfigListener,
Expand Down Expand Up @@ -302,6 +304,14 @@ const codeQlVersionRange = DEFAULT_DISTRIBUTION_VERSION_RANGE;
// before silently being refused to upgrade.
const MIN_VERSION = "1.82.0";

function sendConfigTelemetryData() {
const config: Record<string, string> = {};
config[ADD_DATABASE_SOURCE_TO_WORKSPACE_SETTING.qualifiedName] =
addDatabaseSourceToWorkspace().toString();

telemetryListener?.sendConfigInformation(config);
}

/**
* Returns the CodeQLExtensionInterface, or an empty object if the interface is not
* available after activation is complete. This will happen if there is no cli
Expand Down Expand Up @@ -329,6 +339,8 @@ export async function activate(

const app = new ExtensionApp(ctx);

sendConfigTelemetryData();

const quickEvalCodeLensProvider = new QuickEvalCodeLensProvider();
languages.registerCodeLensProvider(
{ scheme: "file", language: "ql" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ describe("telemetry reporting", () => {
expect(showInformationMessageSpy).toBeCalledTimes(1);
});

it("should send a ui-interaction telementry event", async () => {
it("should send a ui-interaction telemetry event", async () => {
await telemetryListener.initialize();

telemetryListener.sendUIInteraction("test");
Expand All @@ -467,7 +467,7 @@ describe("telemetry reporting", () => {
expect(sendTelemetryErrorEventSpy).not.toBeCalled();
});

it("should send a ui-interaction telementry event with a cli version", async () => {
it("should send a ui-interaction telemetry event with a cli version", async () => {
await telemetryListener.initialize();

telemetryListener.cliVersion = new SemVer("1.2.3");
Expand All @@ -485,7 +485,7 @@ describe("telemetry reporting", () => {
expect(sendTelemetryErrorEventSpy).not.toBeCalled();
});

it("should send an error telementry event", async () => {
it("should send an error telemetry event", async () => {
await telemetryListener.initialize();

telemetryListener.sendError(redactableError`test`);
Expand All @@ -503,7 +503,7 @@ describe("telemetry reporting", () => {
);
});

it("should send an error telementry event with a cli version", async () => {
it("should send an error telemetry event with a cli version", async () => {
await telemetryListener.initialize();
telemetryListener.cliVersion = new SemVer("1.2.3");

Expand Down Expand Up @@ -543,6 +543,26 @@ describe("telemetry reporting", () => {
);
});

it("should send config telemetry event", async () => {
await telemetryListener.initialize();

telemetryListener.sendConfigInformation({
testKey: "testValue",
testKey2: "42",
});

expect(sendTelemetryEventSpy).toHaveBeenCalledWith(
"config",
{
testKey: "testValue",
testKey2: "42",
cliVersion: "not-set",
},
{},
);
expect(sendTelemetryErrorEventSpy).not.toHaveBeenCalled();
});

async function enableTelemetry(section: string, value: boolean | undefined) {
await workspace
.getConfiguration(section)
Expand Down
Loading