Skip to content

Commit 1019661

Browse files
Add walkthrough telemetry command (#4138)
This exposes a command that could be used in a walkthrough to send a level (presumably 1, 2, or 3) indicating satisfaction. It also refactors slightly to de-duplicate checking the extension mode before sending telemetry.
1 parent a310fd8 commit 1019661

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@
266266
"title": "Invoke Registered Editor Command",
267267
"category": "PowerShell"
268268
},
269+
{
270+
"command": "PowerShell.WalkthroughTelemetry",
271+
"title": "Walkthrough Telemetry",
272+
"category": "PowerShell"
273+
},
269274
{
270275
"command": "PowerShell.ClosePanel",
271276
"title": "Close panel",

src/session.ts

+18-12
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import net = require("net");
77
import path = require("path");
88
import * as semver from "semver";
99
import vscode = require("vscode");
10-
import TelemetryReporter from "@vscode/extension-telemetry";
10+
import TelemetryReporter, { TelemetryEventProperties, TelemetryEventMeasurements } from "@vscode/extension-telemetry";
1111
import { Message } from "vscode-jsonrpc";
1212
import { Logger } from "./logging";
1313
import { PowerShellProcess } from "./process";
@@ -505,6 +505,11 @@ Type 'help' to get help.
505505
vscode.workspace.onDidChangeConfiguration(async () => { await this.onConfigurationUpdated(); }),
506506
vscode.commands.registerCommand(
507507
"PowerShell.ShowSessionConsole", (isExecute?: boolean) => { this.showSessionConsole(isExecute); }),
508+
vscode.commands.registerCommand(
509+
"PowerShell.WalkthroughTelemetry", (satisfaction: number) => {
510+
this.sendTelemetryEvent("powershellWalkthroughSatisfaction", null, { level: satisfaction });
511+
}
512+
)
508513
];
509514
}
510515

@@ -571,6 +576,12 @@ Type 'help' to get help.
571576
}
572577
}
573578

579+
private async sendTelemetryEvent(eventName: string, properties?: TelemetryEventProperties, measures?: TelemetryEventMeasurements) {
580+
if (this.extensionContext.extensionMode === vscode.ExtensionMode.Production) {
581+
this.telemetryReporter.sendTelemetryEvent(eventName, properties, measures);
582+
}
583+
}
584+
574585
private async startLanguageClient(sessionDetails: IEditorServicesSessionDetails) {
575586
this.log.write(`Connecting to language service on pipe: ${sessionDetails.languageServicePipeName}`);
576587
this.log.write("Session details: " + JSON.stringify(sessionDetails));
@@ -622,13 +633,11 @@ Type 'help' to get help.
622633
// This enables handling Semantic Highlighting messages in PowerShell Editor Services
623634
this.languageClient.registerProposedFeatures();
624635

625-
if (this.extensionContext.extensionMode === vscode.ExtensionMode.Production) {
626-
this.languageClient.onTelemetry((event) => {
627-
const eventName: string = event.eventName ? event.eventName : "PSESEvent";
628-
const data: any = event.data ? event.data : event
629-
this.telemetryReporter.sendTelemetryEvent(eventName, data);
630-
});
631-
}
636+
this.languageClient.onTelemetry((event) => {
637+
const eventName: string = event.eventName ? event.eventName : "PSESEvent";
638+
const data: any = event.data ? event.data : event
639+
this.sendTelemetryEvent(eventName, data);
640+
});
632641

633642
// Send the new LanguageClient to extension features
634643
// so that they can register their message handlers
@@ -661,10 +670,7 @@ Type 'help' to get help.
661670

662671
this.versionDetails = await this.languageClient.sendRequest(PowerShellVersionRequestType);
663672

664-
if (this.extensionContext.extensionMode === vscode.ExtensionMode.Production) {
665-
this.telemetryReporter.sendTelemetryEvent("powershellVersionCheck",
666-
{ powershellVersion: this.versionDetails.version });
667-
}
673+
this.sendTelemetryEvent("powershellVersionCheck", { powershellVersion: this.versionDetails.version });
668674

669675
this.setSessionVersion(this.versionDetails.architecture === "x86"
670676
? `${this.versionDetails.displayVersion} (${this.versionDetails.architecture})`

0 commit comments

Comments
 (0)