Skip to content

Add powershell version telemetry #1908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"onView:PowerShellCommands"
],
"dependencies": {
"vscode-extension-telemetry": "~0.1.1",
"vscode-languageclient": "~5.2.1"
},
"devDependencies": {
Expand Down
56 changes: 23 additions & 33 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import path = require("path");
import vscode = require("vscode");
import TelemetryReporter from "vscode-extension-telemetry";
import { DocumentSelector } from "vscode-languageclient";
import { IFeature } from "./feature";
import { CodeActionsFeature } from "./features/CodeActions";
Expand Down Expand Up @@ -35,24 +36,39 @@ import Settings = require("./settings");
import { PowerShellLanguageId } from "./utils";
import utils = require("./utils");

// The most reliable way to get the name and version of the current extension.
// tslint:disable-next-line: no-var-requires
const PackageJSON: any = require("../../package.json");

// NOTE: We will need to find a better way to deal with the required
// PS Editor Services version...
const requiredEditorServicesVersion = "2.0.0";

// the application insights key (also known as instrumentation key) used for telemetry.
const AI_KEY: string = "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217";

let logger: Logger;
let sessionManager: SessionManager;
let extensionFeatures: IFeature[] = [];
let telemetryReporter: TelemetryReporter;

const documentSelector: DocumentSelector = [
{ language: "powershell", scheme: "file" },
{ language: "powershell", scheme: "untitled" },
];

export function activate(context: vscode.ExtensionContext): void {
// create telemetry reporter on extension activation
telemetryReporter = new TelemetryReporter(PackageJSON.name, PackageJSON.version, AI_KEY);

const version = getCurrentVersion(context);
// If both extensions are enabled, this will cause unexpected behavior since both register the same commands
if (PackageJSON.name.toLowerCase() === "powerShell-preview"
&& vscode.extensions.getExtension("ms-vscode.powershell")) {
vscode.window.showWarningMessage(
"'PowerShell' and 'PowerShell Preview' are both enabled. Please disable one for best performance.");
}

checkForUpdatedVersion(context, version);
checkForUpdatedVersion(context, PackageJSON.version);

vscode.languages.setLanguageConfiguration(
PowerShellLanguageId,
Expand Down Expand Up @@ -119,7 +135,8 @@ export function activate(context: vscode.ExtensionContext): void {
requiredEditorServicesVersion,
logger,
documentSelector,
version);
PackageJSON.version,
telemetryReporter);

// Create features
extensionFeatures = [
Expand Down Expand Up @@ -153,36 +170,6 @@ export function activate(context: vscode.ExtensionContext): void {
}
}

// Until VSCode offers an easier way to grab the extension name,
// we have this function as a workaround to grab the version
function getCurrentVersion(context: vscode.ExtensionContext) {
// sometimes storagePath is null. This happens when an Untitled workspace is opened
let pathToCheck: string;
if (context.storagePath) {
pathToCheck = context.storagePath;
} else if (context.extensionPath) {
pathToCheck = context.extensionPath;
} else {
pathToCheck = __dirname;
}

const extensionName = pathToCheck.toLowerCase().includes("ms-vscode.powershell-preview") ?
"ms-vscode.PowerShell-Preview" : "ms-vscode.PowerShell";

// If both extensions are enabled, this will cause unexpected behavior since both register the same commands
if (extensionName === "ms-vscode.PowerShell-Preview"
&& vscode.extensions.getExtension("ms-vscode.PowerShell")) {
vscode.window.showWarningMessage(
"'PowerShell' and 'PowerShell Preview' are both enabled. Please disable one for best performance.");
}

return vscode
.extensions
.getExtension(extensionName)
.packageJSON
.version;
}

function checkForUpdatedVersion(context: vscode.ExtensionContext, version: string) {

const showReleaseNotes = "Show Release Notes";
Expand Down Expand Up @@ -223,4 +210,7 @@ export function deactivate(): void {

// Dispose of the logger
logger.dispose();

// Dispose of telemetry reporter
telemetryReporter.dispose();
}
11 changes: 10 additions & 1 deletion src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import os = require("os");
import path = require("path");
import { StringDecoder } from "string_decoder";
import vscode = require("vscode");
import TelemetryReporter from "vscode-extension-telemetry";
import { Message } from "vscode-jsonrpc";
import { IFeature } from "./feature";
import { Logger } from "./logging";
Expand Down Expand Up @@ -55,6 +56,7 @@ export class SessionManager implements Middleware {
private sessionSettings: Settings.ISettings = undefined;
private sessionDetails: utils.IEditorServicesSessionDetails;
private bundledModulesPath: string;
private telemetryReporter: TelemetryReporter;

// When in development mode, VS Code's session ID is a fake
// value of "someValue.machineId". Use that to detect dev
Expand All @@ -66,10 +68,12 @@ export class SessionManager implements Middleware {
private requiredEditorServicesVersion: string,
private log: Logger,
private documentSelector: DocumentSelector,
private version: string) {
private version: string,
private reporter: TelemetryReporter) {

this.platformDetails = getPlatformDetails();
this.HostVersion = version;
this.telemetryReporter = reporter;

const osBitness = this.platformDetails.isOS64Bit ? "64-bit" : "32-bit";
const procBitness = this.platformDetails.isProcess64Bit ? "64-bit" : "32-bit";
Expand Down Expand Up @@ -108,6 +112,11 @@ export class SessionManager implements Middleware {
this.createStatusBarItem();

this.powerShellExePath = this.getPowerShellExePath();
cp.exec(`${this.powerShellExePath} -v`, (error: cp.ExecException, stdout: string, stderr: string) => {
if (!error && !stderr) {
this.telemetryReporter.sendTelemetryEvent("powershellVersionCheck", { powershellVersion: stdout });
}
});

// Check for OpenSSL dependency on macOS when running PowerShell Core alpha. Look for the default
// Homebrew installation path and if that fails check the system-wide library path.
Expand Down