Skip to content

Commit 5c4923b

Browse files
committed
git: telemetry events
1 parent 9ae2575 commit 5c4923b

4 files changed

Lines changed: 24 additions & 8 deletions

File tree

extensions/git/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"engines": {
88
"vscode": "^1.5.0"
99
},
10+
"aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
1011
"enableProposedApi": true,
1112
"categories": [
1213
"Other"
@@ -588,9 +589,10 @@
588589
}
589590
},
590591
"dependencies": {
592+
"vscode-extension-telemetry": "0.0.5",
591593
"vscode-nls": "^2.0.1"
592594
},
593595
"devDependencies": {
594596
"@types/node": "^7.0.4"
595597
}
596-
}
598+
}

extensions/git/src/commands.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Model, Resource, Status, CommitOptions } from './model';
1111
import * as staging from './staging';
1212
import * as path from 'path';
1313
import * as os from 'os';
14+
import TelemetryReporter from 'vscode-extension-telemetry';
1415
import * as nls from 'vscode-nls';
1516

1617
const localize = nls.loadMessageBundle();
@@ -95,14 +96,15 @@ export class CommandCenter {
9596

9697
constructor(
9798
model: Model | undefined,
98-
private outputChannel: OutputChannel
99+
private outputChannel: OutputChannel,
100+
private telemetryReporter: TelemetryReporter
99101
) {
100102
if (model) {
101103
this.model = model;
102104
}
103105

104106
this.disposables = Commands
105-
.map(({ commandId, method }) => commands.registerCommand(commandId, this.createCommand(method)));
107+
.map(({ commandId, method }) => commands.registerCommand(commandId, this.createCommand(commandId, method)));
106108
}
107109

108110
@command('git.refresh')
@@ -693,13 +695,15 @@ export class CommandCenter {
693695
this.outputChannel.show();
694696
}
695697

696-
private createCommand(method: Function): (...args: any[]) => any {
698+
private createCommand(id: string, method: Function): (...args: any[]) => any {
697699
return (...args) => {
698700
if (!this.model) {
699701
window.showInformationMessage(localize('disabled', "Git is either disabled or not supported in this workspace"));
700702
return;
701703
}
702704

705+
this.telemetryReporter.sendTelemetryEvent('git.command', { command: id });
706+
703707
const result = Promise.resolve(method.apply(this, args));
704708

705709
return result.catch(async err => {

extensions/git/src/main.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ import { GitContentProvider } from './contentProvider';
1515
import { AutoFetcher } from './autofetch';
1616
import { MergeDecorator } from './merge';
1717
import { Askpass } from './askpass';
18+
import TelemetryReporter from 'vscode-extension-telemetry';
1819
import * as nls from 'vscode-nls';
1920

2021
const localize = nls.config()();
2122

22-
async function init(disposables: Disposable[]): Promise<void> {
23+
async function init(context: ExtensionContext, disposables: Disposable[]): Promise<void> {
24+
const { name, version, aiKey } = require(context.asAbsolutePath('./package.json')) as { name: string, version: string, aiKey: string };
25+
const telemetryReporter: TelemetryReporter = new TelemetryReporter(name, version, aiKey);
26+
2327
const outputChannel = window.createOutputChannel('Git');
2428
disposables.push(outputChannel);
2529

@@ -28,7 +32,7 @@ async function init(disposables: Disposable[]): Promise<void> {
2832
const rootPath = workspace.rootPath;
2933

3034
if (!rootPath || !enabled) {
31-
const commandCenter = new CommandCenter(undefined, outputChannel);
35+
const commandCenter = new CommandCenter(undefined, outputChannel, telemetryReporter);
3236
disposables.push(commandCenter);
3337
return;
3438
}
@@ -42,7 +46,7 @@ async function init(disposables: Disposable[]): Promise<void> {
4246
outputChannel.appendLine(localize('using git', "Using git {0} from {1}", info.version, info.path));
4347
git.onOutput(str => outputChannel.append(str), null, disposables);
4448

45-
const commandCenter = new CommandCenter(model, outputChannel);
49+
const commandCenter = new CommandCenter(model, outputChannel, telemetryReporter);
4650
const provider = new GitSCMProvider(model, commandCenter);
4751
const contentProvider = new GitContentProvider(model);
4852
const checkoutStatusBar = new CheckoutStatusBar(model);
@@ -81,6 +85,6 @@ export function activate(context: ExtensionContext): any {
8185
const disposables: Disposable[] = [];
8286
context.subscriptions.push(new Disposable(() => Disposable.from(...disposables).dispose()));
8387

84-
init(disposables)
88+
init(context, disposables)
8589
.catch(err => console.error(err));
8690
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare module 'vscode-extension-telemetry' {
2+
export default class TelemetryReporter {
3+
constructor(extensionId: string, extensionVersion: string, key: string);
4+
sendTelemetryEvent(eventName: string, properties?: { [key: string]: string }, measures?: { [key: string]: number }): void;
5+
}
6+
}

0 commit comments

Comments
 (0)