Skip to content

Commit ee955d4

Browse files
authored
Add telemetry for bundle init flow (#1117)
Add telemetry for bundle init flow
1 parent c6e9b0e commit ee955d4

File tree

4 files changed

+60
-35
lines changed

4 files changed

+60
-35
lines changed

packages/databricks-vscode/src/bundle/BundleInitWizard.ts

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {CliWrapper} from "../cli/CliWrapper";
1414
import {getSubProjects} from "./BundleFileSet";
1515
import {tmpdir} from "os";
1616
import {ShellUtils} from "../utils";
17+
import {Events, Telemetry} from "../telemetry";
1718
import {OverrideableConfigModel} from "../configuration/models/OverrideableConfigModel";
1819
import {writeFile, mkdir} from "fs/promises";
1920
import path from "path";
@@ -59,48 +60,60 @@ export async function promptToOpenSubProjects(
5960
export class BundleInitWizard {
6061
private logger = logging.NamedLogger.getOrCreate(Loggers.Extension);
6162

62-
constructor(private cli: CliWrapper) {}
63+
constructor(
64+
private cli: CliWrapper,
65+
private telemetry: Telemetry
66+
) {}
6367

6468
public async initNewProject(
6569
workspaceUri?: Uri,
6670
existingAuthProvider?: AuthProvider
6771
) {
68-
const authProvider =
69-
await this.configureAuthForBundleInit(existingAuthProvider);
70-
if (!authProvider) {
71-
this.logger.debug(
72-
"No valid auth providers, can't proceed with bundle init wizard"
73-
);
74-
return;
75-
}
76-
const parentFolder = await this.promptForParentFolder(workspaceUri);
77-
if (!parentFolder) {
78-
this.logger.debug("No parent folder provided");
79-
return;
80-
}
81-
await this.bundleInitInTerminal(parentFolder, authProvider);
82-
this.logger.debug(
83-
"Finished bundle init wizard, detecting projects to initialize or open"
84-
);
85-
const projects = await getSubProjects(parentFolder);
86-
if (projects.length > 0) {
87-
this.logger.debug(
88-
`Detected ${projects.length} sub projects after the init wizard, prompting to open one`
89-
);
90-
await promptToOpenSubProjects(projects, authProvider);
91-
} else {
72+
const recordEvent = this.telemetry.start(Events.BUNDLE_INIT);
73+
try {
74+
const authProvider =
75+
await this.configureAuthForBundleInit(existingAuthProvider);
76+
if (!authProvider) {
77+
this.logger.debug(
78+
"No valid auth providers, can't proceed with bundle init wizard"
79+
);
80+
recordEvent({success: false});
81+
return;
82+
}
83+
const parentFolder = await this.promptForParentFolder(workspaceUri);
84+
if (!parentFolder) {
85+
this.logger.debug("No parent folder provided");
86+
recordEvent({success: false});
87+
return;
88+
}
89+
await this.bundleInitInTerminal(parentFolder, authProvider);
9290
this.logger.debug(
93-
`No projects detected after the init wizard, showing notification to open a folder manually`
94-
);
95-
const choice = await window.showInformationMessage(
96-
`We haven't detected any Databricks projects in "${parentFolder.fsPath}". If you initialized your project somewhere else, please open the folder manually.`,
97-
"Open Folder"
91+
"Finished bundle init wizard, detecting projects to initialize or open"
9892
);
99-
if (choice === "Open Folder") {
100-
await commands.executeCommand("vscode.openFolder");
93+
const projects = await getSubProjects(parentFolder);
94+
recordEvent({success: projects.length > 0});
95+
if (projects.length > 0) {
96+
this.logger.debug(
97+
`Detected ${projects.length} sub projects after the init wizard, prompting to open one`
98+
);
99+
await promptToOpenSubProjects(projects, authProvider);
100+
} else {
101+
this.logger.debug(
102+
`No projects detected after the init wizard, showing notification to open a folder manually`
103+
);
104+
const choice = await window.showInformationMessage(
105+
`We haven't detected any Databricks projects in "${parentFolder.fsPath}". If you initialized your project somewhere else, please open the folder manually.`,
106+
"Open Folder"
107+
);
108+
if (choice === "Open Folder") {
109+
await commands.executeCommand("vscode.openFolder");
110+
}
101111
}
112+
return parentFolder;
113+
} catch (e) {
114+
recordEvent({success: false});
115+
throw e;
102116
}
103-
return parentFolder;
104117
}
105118

106119
private async configureAuthForBundleInit(

packages/databricks-vscode/src/bundle/BundleProjectManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,9 @@ export class BundleProjectManager {
295295
this.logger.debug("Successfully finished bundle migration");
296296
}
297297

298+
@onError({popup: {prefix: "Failed to initialize new Databricks project"}})
298299
public async initNewProject() {
299-
const bundleInitWizard = new BundleInitWizard(this.cli);
300+
const bundleInitWizard = new BundleInitWizard(this.cli, this.telemetry);
300301
const authProvider =
301302
this.connectionManager.databricksWorkspace?.authProvider;
302303
const parentFolder = await bundleInitWizard.initNewProject(

packages/databricks-vscode/src/extension.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ export async function activate(
110110
telemetry.registerCommand(
111111
"databricks.bundle.initNewProject",
112112
async () => {
113-
const bundleInitWizard = new BundleInitWizard(cli);
113+
const bundleInitWizard = new BundleInitWizard(
114+
cli,
115+
telemetry
116+
);
114117
await bundleInitWizard.initNewProject();
115118
}
116119
)

packages/databricks-vscode/src/telemetry/constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export enum Events {
1717
AUTO_MIGRATION = "autoMigration",
1818
MANUAL_MIGRATION = "manualMigration",
1919
BUNDLE_RUN = "bundleRun",
20+
BUNDLE_INIT = "bundleInit",
2021
CONNECTION_STATE_CHANGED = "connectionStateChanged",
2122
}
2223
/* eslint-enable @typescript-eslint/naming-convention */
@@ -127,6 +128,13 @@ export class EventTypes {
127128
> = {
128129
comment: "Execute a bundle resource",
129130
};
131+
[Events.BUNDLE_INIT]: EventType<
132+
{
133+
success: boolean;
134+
} & DurationMeasurement
135+
> = {
136+
comment: "Initialize a new bundle project",
137+
};
130138
[Events.CONNECTION_STATE_CHANGED]: EventType<{
131139
newState: string;
132140
}> = {

0 commit comments

Comments
 (0)