Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
Telemetry for Errors and Dialog clicks (#40)
Browse files Browse the repository at this point in the history
PBI: 30429
Task: 30434

* Update button handling for telemetry

* Add error telemetry

* Remove user's stack trace from being sent as telemetry
  • Loading branch information
jonathanwangg authored Jul 11, 2019
1 parent d66ff62 commit af1d630
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
15 changes: 13 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,31 @@ export const CONSTANTS = {
export enum TelemetryEventName {
FAILED_TO_OPEN_SIMULATOR = "SIMULATOR.FAILED_TO_OPEN",

// Extension commands
COMMAND_DEPLOY_DEVICE = "COMMAND.DEPLOY.DEVICE",
COMMAND_NEW_PROJECT = "COMMAND.NEW.PROJECT",
COMMAND_OPEN_SIMULATOR = "COMMAND.OPEN.SIMULATOR",
COMMAND_RUN_SIMULATOR = "COMMAND.RUN.SIMULATOR",

// Simulator interaction
SIMULATOR_BUTTON_A = "SIMULATOR.BUTTON.A",
SIMULATOR_BUTTON_B = "SIMULATOR.BUTTON.B",
SIMULATOR_BUTTON_AB = "SIMULATOR.BUTTON.AB",
SIMULATOR_SWITCH = "SIMULATOR.SWITCH",

// Pop-up dialog
CLICK_DIALOG_DONT_SHOW = "CLICK.DIALOG.DONT.SHOW",
CLICK_DIALOG_EXAMPLE_CODE = "CLICK.DIALOG.EXAMPLE.CODE",
CLICK_DIALOG_TUTORIALS = "CLICK.DIALOG.TUTORIALS"
}
CLICK_DIALOG_HELP_DEPLOY_TO_DEVICE = "CLICK.DIALOG.HELP.DEPLOY.TO.DEVICE",
CLICK_DIALOG_TUTORIALS = "CLICK.DIALOG.TUTORIALS",

ERROR_PYTHON_DEVICE_PROCESS = "ERROR.PYTHON.DEVICE.PROCESS",
ERROR_PYTHON_PROCESS = "ERROR.PYTHON.PROCESS",
ERROR_COMMAND_NEW_PROJECT = "ERROR.COMMAND.NEW.PROJECT",
ERROR_DEPLOY_WITHOUT_DEVICE = "ERROR.DEPLOY.WITHOUT.DEVICE",

SUCCESS_COMMAND_DEPLOY_DEVICE = "SUCCESS.COMMAND.DEPLOY.DEVICE"
}

// tslint:disable-next-line: no-namespace
export namespace DialogResponses {
Expand Down
15 changes: 11 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ export function activate(context: vscode.ExtensionContext) {
};

// Open Simulator on the webview
const openSimulator = vscode.commands.registerCommand(
const openSimulator: vscode.Disposable = vscode.commands.registerCommand(
"pacifica.openSimulator",
() => {
TelemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_OPEN_SIMULATOR);
openWebview();
}
);

const newProject = vscode.commands.registerCommand(
const newProject: vscode.Disposable = vscode.commands.registerCommand(
"pacifica.newProject",
() => {
TelemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_NEW_PROJECT);
Expand Down Expand Up @@ -117,13 +117,14 @@ export function activate(context: vscode.ExtensionContext) {
vscode.window.showTextDocument(template, 1, false);
}),
(error: any) => {
TelemetryAI.trackFeatureUsage(TelemetryEventName.ERROR_COMMAND_NEW_PROJECT);
console.error(`Failed to open a new text document: ${error}`);
};
}
);

// Send message to the webview
const runSimulator = vscode.commands.registerCommand(
const runSimulator: vscode.Disposable = vscode.commands.registerCommand(
"pacifica.runSimulator",
() => {
openWebview();
Expand Down Expand Up @@ -210,6 +211,7 @@ export function activate(context: vscode.ExtensionContext) {
// Std error output
childProcess.stderr.on("data", data => {
console.error(`Error from the Python process through stderr: ${data}`);
TelemetryAI.trackFeatureUsage(TelemetryEventName.ERROR_PYTHON_PROCESS);
logToOutputChannel(outChannel, CONSTANTS.ERROR.STDERR(data), true);
if (currentPanel) {
console.log("Sending clearing state command");
Expand All @@ -229,6 +231,7 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.splice(index, 1);
}
}

// Handle messages from webview
messageListener = currentPanel.webview.onDidReceiveMessage(
message => {
Expand All @@ -254,7 +257,7 @@ export function activate(context: vscode.ExtensionContext) {
);

// Send message to the webview
const runDevice = vscode.commands.registerCommand("pacifica.runDevice", () => {
const runDevice: vscode.Disposable = vscode.commands.registerCommand("pacifica.runDevice", () => {
console.info("Sending code to device");
TelemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_DEPLOY_DEVICE);

Expand Down Expand Up @@ -291,17 +294,20 @@ export function activate(context: vscode.ExtensionContext) {
// Check the JSON is a state
switch (messageToWebview.type) {
case "complete":
TelemetryAI.trackFeatureUsage(TelemetryEventName.SUCCESS_COMMAND_DEPLOY_DEVICE);
logToOutputChannel(outChannel, CONSTANTS.INFO.DEPLOY_SUCCESS);
break;

case "no-device":
TelemetryAI.trackFeatureUsage(TelemetryEventName.ERROR_DEPLOY_WITHOUT_DEVICE);
vscode.window
.showErrorMessage(
CONSTANTS.ERROR.NO_DEVICE,
...[DialogResponses.HELP]
)
.then((selection: vscode.MessageItem | undefined) => {
if (selection === DialogResponses.HELP) {
TelemetryAI.trackFeatureUsage(TelemetryEventName.CLICK_DIALOG_HELP_DEPLOY_TO_DEVICE);
open(CONSTANTS.LINKS.HELP);
}
});
Expand All @@ -322,6 +328,7 @@ export function activate(context: vscode.ExtensionContext) {

// Std error output
deviceProcess.stderr.on("data", data => {
TelemetryAI.trackFeatureUsage(TelemetryEventName.ERROR_PYTHON_DEVICE_PROCESS, { error: `${data}` });
console.error(
`Error from the Python device process through stderr: ${data}`
);
Expand Down
10 changes: 7 additions & 3 deletions src/view/components/Simulator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,13 @@ class Simulator extends React.Component<any, IState> {
newState = this.handleButtonClick(button, active);
} else if (button.id.includes("SWITCH")) {
newState = this.handleSwitchClick(button);
} else return;
} else {
return;
}

if (newState) sendMessage(newState);
if (newState) {
sendMessage(newState);
}
}

private handleButtonClick(button: HTMLElement, active: boolean) {
Expand Down Expand Up @@ -183,7 +187,7 @@ class Simulator extends React.Component<any, IState> {

svg.addClass(switchInner, "sim-slide-switch-inner");

let switchIsOn: boolean = !this.state.switch;
const switchIsOn: boolean = !this.state.switch;

if (switchIsOn) {
svg.addClass(switchInner, "on");
Expand Down

0 comments on commit af1d630

Please sign in to comment.