Skip to content

Commit

Permalink
Add telemetry support for the Go extension
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Jan 4, 2017
1 parent 2cc981c commit 2328f31
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Go",
"version": "0.6.51",
"version": "0.6.52",
"publisher": "lukehoban",
"description": "Rich Go language support for Visual Studio Code",
"author": {
Expand Down Expand Up @@ -36,7 +36,8 @@
"diff": "~3.0.0",
"json-rpc2": "^1.0.2",
"vscode-debugadapter": "^1.11.0",
"vscode-debugprotocol": "^1.11.0"
"vscode-debugprotocol": "^1.11.0",
"vscode-extension-telemetry": "0.0.5"
},
"devDependencies": {
"fs-extra": "^0.30.0",
Expand Down
5 changes: 4 additions & 1 deletion src/goFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import path = require('path');
import { isDiffToolAvailable, getEdits, getEditsFromUnifiedDiffStr } from '../src/diffUtils';
import { getBinPath } from './goPath';
import { promptForMissingTool } from './goInstallTools';
import { sendTelemetryEvent } from './util';

export class Formatter {
private formatCommand = 'goreturns';
Expand All @@ -36,7 +37,7 @@ export class Formatter {
if (formatFlags.indexOf('-w') > -1) {
formatFlags.splice(formatFlags.indexOf('-w'), 1);
}

let t0 = Date.now();
cp.execFile(formatCommandBinPath, [...formatFlags, filename], {}, (err, stdout, stderr) => {
try {
if (err && (<any>err).code === 'ENOENT') {
Expand All @@ -55,6 +56,8 @@ export class Formatter {
textEdits.push(edit.apply());
});

let timeTaken = Date.now() - t0;
sendTelemetryEvent('format', { tool: this.formatCommand}, {timeTaken});
return resolve(textEdits);
} catch (e) {
reject('Internal issues while getting diff from formatted content');
Expand Down
17 changes: 17 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import vscode = require('vscode');
import path = require('path');
import { getGoRuntimePath } from './goPath';
import cp = require('child_process');
import TelemetryReporter from 'vscode-extension-telemetry';

const extensionId: string = 'lukehoban.Go';
const extensionVersion: string = vscode.extensions.getExtension(extensionId).packageJSON.version;
const aiKey: string = 'AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217';

export interface SemVersion {
major: number;
Expand All @@ -15,6 +20,7 @@ export interface SemVersion {

let goVersion: SemVersion = null;
let vendorSupport: boolean = null;
let telemtryReporter: TelemetryReporter;

export function byteOffsetAt(document: vscode.TextDocument, position: vscode.Position): number {
let offset = document.offsetAt(position);
Expand Down Expand Up @@ -133,6 +139,7 @@ export function getGoVersion(): Promise<SemVersion> {
}
return new Promise<SemVersion>((resolve, reject) => {
cp.execFile(goRuntimePath, ['version'], {}, (err, stdout, stderr) => {
sendTelemetryEvent('getGoVersion', {version: stdout});
let matches = /go version go(\d).(\d).*/.exec(stdout);
if (matches) {
goVersion = {
Expand Down Expand Up @@ -188,4 +195,14 @@ export function isGoPathSet(): boolean {
}

return true;
}

export function sendTelemetryEvent(eventName: string, properties?: {
[key: string]: string;
}, measures?: {
[key: string]: number;
}): void {

telemtryReporter = telemtryReporter ? telemtryReporter : new TelemetryReporter(extensionId, extensionVersion, aiKey);
telemtryReporter.sendTelemetryEvent(eventName, properties, measures);
}
36 changes: 36 additions & 0 deletions typings/vscode-extension-telemetry.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
declare module "vscode-extension-telemetry" {
export default class TelemetryReporter {
private extensionId;
private extensionVersion;
private appInsightsClient;
private commonProperties;
private static SQM_KEY;
private static REGISTRY_USERID_VALUE;
private static REGISTRY_MACHINEID_VALUE;

/**
* Constructs a new telemetry reporter
* @param {string} extensionId All events will be prefixed with this event name
* @param {string} extensionVersion Extension version to be reported with each event
* @param {string} key The application insights key
*/
constructor(extensionId: string, extensionVersion: string, key: string);
private setupAIClient(client);
private loadVSCodeCommonProperties(machineId, sessionId, version);
private loadCommonProperties();
private addCommonProperties(properties);
private getWinRegKeyData(key, name, hive, callback);

/**
* Sends a telemetry event
* @param {string} eventName The event name
* @param {object} properties An associative array of strings
* @param {object} measures An associative array of numbers
*/
sendTelemetryEvent(eventName: string, properties?: {
[key: string]: string;
}, measures?: {
[key: string]: number;
}): void;
}
}

0 comments on commit 2328f31

Please sign in to comment.