From 62818d5867ec58c64609ff9b97948dccb883d5c3 Mon Sep 17 00:00:00 2001 From: Andy Jordan Date: Tue, 16 Aug 2022 14:56:41 -0700 Subject: [PATCH] Add walkthrough telemetry command 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. --- package.json | 5 +++++ src/session.ts | 30 ++++++++++++++++++------------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 49d1bba323..d5b1739a8e 100644 --- a/package.json +++ b/package.json @@ -260,6 +260,11 @@ "title": "Invoke Registered Editor Command", "category": "PowerShell" }, + { + "command": "PowerShell.WalkthroughTelemetry", + "title": "Walkthrough Telemetry", + "category": "PowerShell" + }, { "command": "PowerShell.ClosePanel", "title": "Close panel", diff --git a/src/session.ts b/src/session.ts index 127eaaa5cd..1976887082 100644 --- a/src/session.ts +++ b/src/session.ts @@ -7,7 +7,7 @@ import net = require("net"); import path = require("path"); import * as semver from "semver"; import vscode = require("vscode"); -import TelemetryReporter from "@vscode/extension-telemetry"; +import TelemetryReporter, { TelemetryEventProperties, TelemetryEventMeasurements } from "@vscode/extension-telemetry"; import { Message } from "vscode-jsonrpc"; import { Logger } from "./logging"; import { PowerShellProcess } from "./process"; @@ -505,6 +505,11 @@ Type 'help' to get help. vscode.workspace.onDidChangeConfiguration(async () => { await this.onConfigurationUpdated(); }), vscode.commands.registerCommand( "PowerShell.ShowSessionConsole", (isExecute?: boolean) => { this.showSessionConsole(isExecute); }), + vscode.commands.registerCommand( + "PowerShell.WalkthroughTelemetry", (satisfaction: number) => { + this.sendTelemetryEvent("powershellWalkthroughSatisfaction", null, { level: satisfaction }); + } + ) ]; } @@ -571,6 +576,12 @@ Type 'help' to get help. } } + private async sendTelemetryEvent(eventName: string, properties?: TelemetryEventProperties, measures?: TelemetryEventMeasurements) { + if (this.extensionContext.extensionMode === vscode.ExtensionMode.Production) { + this.telemetryReporter.sendTelemetryEvent(eventName, properties, measures); + } + } + private async startLanguageClient(sessionDetails: IEditorServicesSessionDetails) { this.log.write(`Connecting to language service on pipe: ${sessionDetails.languageServicePipeName}`); this.log.write("Session details: " + JSON.stringify(sessionDetails)); @@ -622,13 +633,11 @@ Type 'help' to get help. // This enables handling Semantic Highlighting messages in PowerShell Editor Services this.languageClient.registerProposedFeatures(); - if (this.extensionContext.extensionMode === vscode.ExtensionMode.Production) { - this.languageClient.onTelemetry((event) => { - const eventName: string = event.eventName ? event.eventName : "PSESEvent"; - const data: any = event.data ? event.data : event - this.telemetryReporter.sendTelemetryEvent(eventName, data); - }); - } + this.languageClient.onTelemetry((event) => { + const eventName: string = event.eventName ? event.eventName : "PSESEvent"; + const data: any = event.data ? event.data : event + this.sendTelemetryEvent(eventName, data); + }); // Send the new LanguageClient to extension features // so that they can register their message handlers @@ -661,10 +670,7 @@ Type 'help' to get help. this.versionDetails = await this.languageClient.sendRequest(PowerShellVersionRequestType); - if (this.extensionContext.extensionMode === vscode.ExtensionMode.Production) { - this.telemetryReporter.sendTelemetryEvent("powershellVersionCheck", - { powershellVersion: this.versionDetails.version }); - } + this.sendTelemetryEvent("powershellVersionCheck", { powershellVersion: this.versionDetails.version }); this.setSessionVersion(this.versionDetails.architecture === "x86" ? `${this.versionDetails.displayVersion} (${this.versionDetails.architecture})`