diff --git a/extensions/git/package.json b/extensions/git/package.json index f091be69379..9ded5549de7 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -7,6 +7,7 @@ "engines": { "vscode": "^1.5.0" }, + "aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217", "enableProposedApi": true, "categories": [ "Other" @@ -588,9 +589,10 @@ } }, "dependencies": { + "vscode-extension-telemetry": "0.0.5", "vscode-nls": "^2.0.1" }, "devDependencies": { "@types/node": "^7.0.4" } -} \ No newline at end of file +} diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 4506b3a339f..f6c27f03e58 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -11,6 +11,7 @@ import { Model, Resource, Status, CommitOptions } from './model'; import * as staging from './staging'; import * as path from 'path'; import * as os from 'os'; +import TelemetryReporter from 'vscode-extension-telemetry'; import * as nls from 'vscode-nls'; const localize = nls.loadMessageBundle(); @@ -95,14 +96,15 @@ export class CommandCenter { constructor( model: Model | undefined, - private outputChannel: OutputChannel + private outputChannel: OutputChannel, + private telemetryReporter: TelemetryReporter ) { if (model) { this.model = model; } this.disposables = Commands - .map(({ commandId, method }) => commands.registerCommand(commandId, this.createCommand(method))); + .map(({ commandId, method }) => commands.registerCommand(commandId, this.createCommand(commandId, method))); } @command('git.refresh') @@ -693,13 +695,15 @@ export class CommandCenter { this.outputChannel.show(); } - private createCommand(method: Function): (...args: any[]) => any { + private createCommand(id: string, method: Function): (...args: any[]) => any { return (...args) => { if (!this.model) { window.showInformationMessage(localize('disabled', "Git is either disabled or not supported in this workspace")); return; } + this.telemetryReporter.sendTelemetryEvent('git.command', { command: id }); + const result = Promise.resolve(method.apply(this, args)); return result.catch(async err => { diff --git a/extensions/git/src/main.ts b/extensions/git/src/main.ts index 31a7ef9d29a..771bebb1e49 100644 --- a/extensions/git/src/main.ts +++ b/extensions/git/src/main.ts @@ -15,11 +15,15 @@ import { GitContentProvider } from './contentProvider'; import { AutoFetcher } from './autofetch'; import { MergeDecorator } from './merge'; import { Askpass } from './askpass'; +import TelemetryReporter from 'vscode-extension-telemetry'; import * as nls from 'vscode-nls'; const localize = nls.config()(); -async function init(disposables: Disposable[]): Promise { +async function init(context: ExtensionContext, disposables: Disposable[]): Promise { + const { name, version, aiKey } = require(context.asAbsolutePath('./package.json')) as { name: string, version: string, aiKey: string }; + const telemetryReporter: TelemetryReporter = new TelemetryReporter(name, version, aiKey); + const outputChannel = window.createOutputChannel('Git'); disposables.push(outputChannel); @@ -28,7 +32,7 @@ async function init(disposables: Disposable[]): Promise { const rootPath = workspace.rootPath; if (!rootPath || !enabled) { - const commandCenter = new CommandCenter(undefined, outputChannel); + const commandCenter = new CommandCenter(undefined, outputChannel, telemetryReporter); disposables.push(commandCenter); return; } @@ -42,7 +46,7 @@ async function init(disposables: Disposable[]): Promise { outputChannel.appendLine(localize('using git', "Using git {0} from {1}", info.version, info.path)); git.onOutput(str => outputChannel.append(str), null, disposables); - const commandCenter = new CommandCenter(model, outputChannel); + const commandCenter = new CommandCenter(model, outputChannel, telemetryReporter); const provider = new GitSCMProvider(model, commandCenter); const contentProvider = new GitContentProvider(model); const checkoutStatusBar = new CheckoutStatusBar(model); @@ -81,6 +85,6 @@ export function activate(context: ExtensionContext): any { const disposables: Disposable[] = []; context.subscriptions.push(new Disposable(() => Disposable.from(...disposables).dispose())); - init(disposables) + init(context, disposables) .catch(err => console.error(err)); } \ No newline at end of file diff --git a/extensions/git/src/typings/vscode-extension-telemetry.d.ts b/extensions/git/src/typings/vscode-extension-telemetry.d.ts new file mode 100644 index 00000000000..f6177ef27a6 --- /dev/null +++ b/extensions/git/src/typings/vscode-extension-telemetry.d.ts @@ -0,0 +1,6 @@ +declare module 'vscode-extension-telemetry' { + export default class TelemetryReporter { + constructor(extensionId: string, extensionVersion: string, key: string); + sendTelemetryEvent(eventName: string, properties?: { [key: string]: string }, measures?: { [key: string]: number }): void; + } +} \ No newline at end of file