Skip to content

Commit d537aeb

Browse files
committed
Report telemetry data from the project generation wizard.
- Fixes #405 - Add boolean option to registerCommandWithTelemetry that delegates telemetry reporting to the command - perform telemetry directly in the project generation wizard. Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
1 parent cce4f90 commit d537aeb

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

USAGE_DATA.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ vscode-quarkus has opt-in telemetry collection, provided by [vscode-redhat-telem
1515
* "Quarkus: Debug current Quarkus project"
1616
* "Quarkus: Deploy current Quarkus project to OpenShift (odo)"
1717
* "Quarkus: Generate a Quarkus project"
18+
* The project type (eg. Maven, Gradle, etc.)
19+
* Whether sample code is to be included
20+
* The list of Quarkus extensions selected
1821
* "Quarkus: Welcome"
1922
* "Quarkus: Build executable"
2023

src/commands/registerCommands.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { commands, ExtensionContext, window } from "vscode";
22
import { VSCodeCommands } from "../definitions/constants";
33
import { ProjectLabelInfo } from "../definitions/ProjectLabelInfo";
44
import { requestStandardMode } from "../utils/requestStandardMode";
5-
import { sendCommandFailedTelemetry, sendCommandSucceededTelemetry } from "../utils/telemetryUtils";
5+
import { sendCommandFailedTelemetry, sendCommandSucceededTelemetry, sendTelemetry } from "../utils/telemetryUtils";
66
import { WelcomeWebview } from "../webviews/WelcomeWebview";
77
import { addExtensionsWizard } from "../wizards/addExtensions/addExtensionsWizard";
88
import { buildBinary } from "../wizards/binary/buildBinary";
@@ -23,7 +23,7 @@ export function registerVSCodeCommands(context: ExtensionContext): void {
2323
/**
2424
* Command for creating a Quarkus project
2525
*/
26-
registerCommandWithTelemetry(context, VSCodeCommands.CREATE_PROJECT, generateProjectWizard);
26+
registerCommandWithTelemetry(context, VSCodeCommands.CREATE_PROJECT, generateProjectWizard, true);
2727

2828
/**
2929
* Command for adding Quarkus extensions to current Quarkus Maven project
@@ -63,12 +63,15 @@ export function registerVSCodeCommands(context: ExtensionContext): void {
6363
* @param context the extension context
6464
* @param commandName the name of the command to register
6565
* @param commandAction the async function to run when the command is called
66+
* @param skipSuccess whether the success of the command should be reported
6667
*/
67-
async function registerCommandWithTelemetry(context: ExtensionContext, commandName: string, commandAction: () => Promise<any>): Promise<void> {
68+
async function registerCommandWithTelemetry(context: ExtensionContext, commandName: string, commandAction: () => Promise<any>, skipSuccess?: boolean): Promise<void> {
6869
context.subscriptions.push(commands.registerCommand(commandName, async () => {
6970
try {
7071
await commandAction();
71-
sendCommandSucceededTelemetry(commandName);
72+
if (!skipSuccess) {
73+
sendCommandSucceededTelemetry(commandName);
74+
}
7275
} catch (e) {
7376
const msg = (e instanceof Error) ? e.message : e;
7477
window.showErrorMessage(msg);

src/utils/telemetryUtils.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getRedHatService, TelemetryService } from "@redhat-developer/vscode-redhat-telemetry/lib";
22
import { ExtensionContext } from "vscode";
33

4-
const CMD_SUCCEED_VALUE = "succeeded";
4+
export const CMD_SUCCEED_VALUE = "succeeded";
55
const CMD_FAIL_VALUE = "failed";
66

77
let telemetryService: TelemetryService;
@@ -43,7 +43,6 @@ export async function sendCommandFailedTelemetry(commandName: string, msg?: stri
4343
* Send a telemetry event related to a given vscode-quarkus command
4444
*
4545
* @param commandName the name of the command that was run
46-
* @param suffix the suffix to add to the command to get the event name
4746
* @throws if the telemetry service has not been initialized yet
4847
* @returns when the telemetry event has been sent
4948
*/
@@ -59,3 +58,20 @@ async function sendCommandTelemetry(commandName: string, succeeded: boolean, msg
5958
}
6059
});
6160
}
61+
62+
/**
63+
* Send a telemetry event related to a given vscode-quarkus command
64+
*
65+
* @param commandName the name of the command that was run
66+
* @throws if the telemetry service has not been initialized yet
67+
* @returns when the telemetry event has been sent
68+
*/
69+
export async function sendTelemetry(commandName: string, data: any): Promise<void> {
70+
if (!isTelemetryInit) {
71+
throw new Error('Telemetry has not been initialized yet');
72+
}
73+
await telemetryService.send({
74+
name: commandName,
75+
properties: data
76+
});
77+
}

src/wizards/generateProject/generationWizard.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import * as fse from 'fs-extra';
88
import * as path from 'path';
99
import { commands, OpenDialogOptions, QuickPickItem, Uri, window, workspace } from 'vscode';
1010
import { ZipFile } from 'yauzl';
11-
import { BuildToolName, INPUT_TITLE } from '../../definitions/constants';
11+
import { BuildToolName, INPUT_TITLE, VSCodeCommands } from '../../definitions/constants';
1212
import { ProjectGenState } from '../../definitions/inputState';
1313
import { QExtension } from '../../definitions/QExtension';
1414
import { QuarkusContext } from '../../QuarkusContext';
1515
import { CodeQuarkusFunctionality, PlatformVersionPickItem, getCodeQuarkusApiFunctionality, getDefaultFunctionality, getCodeQuarkusApiPlatforms } from '../../utils/codeQuarkusApiUtils';
1616
import { MultiStepInput, QuickPickParameters } from '../../utils/multiStepUtils';
1717
import { downloadProject } from '../../utils/requestUtils';
18+
import { CMD_SUCCEED_VALUE, sendTelemetry } from '../../utils/telemetryUtils';
1819
import { ExtensionsPicker } from './ExtensionsPicker';
1920
import { validateArtifactId, validateGroupId, validatePackageName, validateResourceName, validateVersion } from './validateInput';
2021

@@ -23,7 +24,7 @@ import { validateArtifactId, validateGroupId, validatePackageName, validateResou
2324
*
2425
* This first part uses the helper class `MultiStepInput` that wraps the API for the multi-step case.
2526
*/
26-
export async function generateProjectWizard() {
27+
export async function generateProjectWizard(): Promise<any> {
2728

2829
let apiCapabilities: CodeQuarkusFunctionality;
2930
try {
@@ -202,6 +203,12 @@ export async function generateProjectWizard() {
202203
state.targetDir = await getTargetDirectory(state.artifactId);
203204

204205
const projectGenState: ProjectGenState = state as ProjectGenState;
206+
await sendTelemetry(VSCodeCommands.CREATE_PROJECT, {
207+
status: CMD_SUCCEED_VALUE,
208+
buildTool: projectGenState.buildTool,
209+
shouldGenerateCode: projectGenState.shouldGenerateCode,
210+
extensions: projectGenState.extensions.map(e => `${e.groupId}:${e.artifactId}`).join(',')
211+
});
205212
saveDefaults(projectGenState);
206213
deleteFolderIfExists(getNewProjectDirectory(projectGenState));
207214
await downloadAndSetupProject(projectGenState, apiCapabilities);

0 commit comments

Comments
 (0)