Add bindings telemetry (#18851)

* add bindings telemetry

* add exitReasons
This commit is contained in:
Vasu Bhog
2022-03-31 16:29:15 -07:00
committed by GitHub
parent 80db3a492f
commit 0a43ed84e3
6 changed files with 167 additions and 55 deletions

View File

@@ -11,6 +11,10 @@ import { TelemetryActions, TelemetryReporter, TelemetryViews } from '../common/t
import { addSqlBinding, getAzureFunctions } from '../services/azureFunctionsService';
export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined): Promise<void> {
let quickPickStep: string = '';
let exitReason: string = 'cancelled';
let propertyBag: { [key: string]: string } = {};
TelemetryReporter.sendActionEvent(TelemetryViews.SqlBindingsQuickPick, TelemetryActions.startAddSqlBinding);
if (!uri) {
// this command only shows in the command palette when the active editor is a .cs file, so we can safely assume that's the scenario
@@ -45,60 +49,89 @@ export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined):
return;
}
// 1. select Azure function from the current file
const azureFunctionName = (await vscode.window.showQuickPick(azureFunctions, {
canPickMany: false,
title: constants.selectAzureFunction,
ignoreFocusOut: true
}));
if (!azureFunctionName) {
return;
}
// 2. select input or output binding
const selectedBinding = await azureFunctionsUtils.promptForBindingType();
if (!selectedBinding) {
return;
}
// 3. ask for object name for the binding
const objectName = await azureFunctionsUtils.promptForObjectName(selectedBinding.type);
if (!objectName) {
return;
}
// 4. ask for connection string setting name
let projectUri: vscode.Uri | undefined;
try {
projectUri = await azureFunctionsUtils.getAFProjectContainingFile(uri);
} catch (e) {
// continue even if there's no AF project found. The binding should still be able to be added as long as there was an azure function found in the file earlier
}
// 1. select Azure function from the current file
quickPickStep = 'getAzureFunctionProject';
const azureFunctionName = (await vscode.window.showQuickPick(azureFunctions, {
canPickMany: false,
title: constants.selectAzureFunction,
ignoreFocusOut: true
}));
let connectionStringSettingName = await azureFunctionsUtils.promptAndUpdateConnectionStringSetting(projectUri);
if (!connectionStringSettingName) {
return;
}
// 5. insert binding
try {
const result = await addSqlBinding(selectedBinding.type, uri.fsPath, azureFunctionName, objectName, connectionStringSettingName);
if (!result.success) {
void vscode.window.showErrorMessage(result.errorMessage);
TelemetryReporter.sendErrorEvent(TelemetryViews.SqlBindingsQuickPick, TelemetryActions.finishAddSqlBinding);
if (!azureFunctionName) {
return;
}
TelemetryReporter.createActionEvent(TelemetryViews.SqlBindingsQuickPick, TelemetryActions.getAzureFunctionProject)
.withAdditionalProperties(propertyBag).send();
TelemetryReporter.createActionEvent(TelemetryViews.SqlBindingsQuickPick, TelemetryActions.finishAddSqlBinding)
.withAdditionalProperties({ bindingType: selectedBinding.label })
.send();
// 2. select input or output binding
quickPickStep = 'getBindingType';
const selectedBinding = await azureFunctionsUtils.promptForBindingType();
if (!selectedBinding) {
return;
}
propertyBag.bindingType = selectedBinding.type;
TelemetryReporter.createActionEvent(TelemetryViews.SqlBindingsQuickPick, TelemetryActions.getBindingType)
.withAdditionalProperties(propertyBag).send();
// 3. ask for object name for the binding
quickPickStep = 'getObjectName';
const objectName = await azureFunctionsUtils.promptForObjectName(selectedBinding.type);
if (!objectName) {
return;
}
TelemetryReporter.createActionEvent(TelemetryViews.SqlBindingsQuickPick, TelemetryActions.getObjectName)
.withAdditionalProperties(propertyBag).send();
// 4. ask for connection string setting name
let projectUri: vscode.Uri | undefined;
try {
projectUri = await azureFunctionsUtils.getAFProjectContainingFile(uri);
} catch (e) {
// continue even if there's no AF project found. The binding should still be able to be added as long as there was an azure function found in the file earlier
}
quickPickStep = 'updateConnectionString';
let connectionStringSettingName = await azureFunctionsUtils.promptAndUpdateConnectionStringSetting(projectUri);
if (!connectionStringSettingName) {
return;
}
TelemetryReporter.createActionEvent(TelemetryViews.SqlBindingsQuickPick, TelemetryActions.updateConnectionString)
.withAdditionalProperties(propertyBag).send();
// 5. insert binding
try {
quickPickStep = 'insertBinding';
const result = await addSqlBinding(selectedBinding.type, uri.fsPath, azureFunctionName, objectName, connectionStringSettingName);
if (!result.success) {
void vscode.window.showErrorMessage(result.errorMessage);
TelemetryReporter.createErrorEvent(TelemetryViews.SqlBindingsQuickPick, TelemetryActions.finishAddSqlBinding)
.withAdditionalProperties(propertyBag).send();
return;
}
exitReason = 'done';
TelemetryReporter.createActionEvent(TelemetryViews.SqlBindingsQuickPick, TelemetryActions.finishAddSqlBinding)
.withAdditionalProperties(propertyBag).send();
} catch (e) {
void vscode.window.showErrorMessage(utils.getErrorMessage(e));
TelemetryReporter.createErrorEvent(TelemetryViews.SqlBindingsQuickPick, TelemetryActions.finishAddSqlBinding, undefined, utils.getErrorType(e))
.withAdditionalProperties(propertyBag).send();
return;
}
} catch (e) {
propertyBag.quickPickStep = quickPickStep;
exitReason = 'error';
void vscode.window.showErrorMessage(utils.getErrorMessage(e));
TelemetryReporter.sendErrorEvent(TelemetryViews.SqlBindingsQuickPick, TelemetryActions.finishAddSqlBinding);
return;
TelemetryReporter.createErrorEvent(TelemetryViews.SqlBindingsQuickPick, TelemetryActions.exitSqlBindingsQuickpick, undefined, utils.getErrorType(e))
.withAdditionalProperties(propertyBag).send();
} finally {
propertyBag.quickPickStep = quickPickStep;
propertyBag.exitReason = exitReason;
TelemetryReporter.createActionEvent(TelemetryViews.SqlBindingsQuickPick, TelemetryActions.exitSqlBindingsQuickpick)
.withAdditionalProperties(propertyBag).send();
}
}