Skip to content

Commit 8f88484

Browse files
authored
GitHub - add push error handler telemetry to understand usage (microsoft#185573)
* GitHub - add push error handler telemetry to understand usage * Add yarn.lock file * Pull request feedback
1 parent 2dcfc37 commit 8f88484

File tree

4 files changed

+373
-5
lines changed

4 files changed

+373
-5
lines changed

extensions/github/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"engines": {
99
"vscode": "^1.41.0"
1010
},
11+
"aiKey": "0c6ae279ed8443289764825290e4f9e2-1a736e7c-1324-4338-be46-fc2a58ae4d14-7255",
1112
"icon": "images/icon.png",
1213
"categories": [
1314
"Other"
@@ -181,7 +182,8 @@
181182
"@octokit/graphql": "5.0.5",
182183
"@octokit/graphql-schema": "14.4.0",
183184
"@octokit/rest": "19.0.4",
184-
"tunnel": "^0.0.6"
185+
"tunnel": "^0.0.6",
186+
"@vscode/extension-telemetry": "0.7.5"
185187
},
186188
"devDependencies": {
187189
"@types/node": "16.x"

extensions/github/src/extension.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { commands, Disposable, ExtensionContext, extensions, l10n, LogLevel, LogOutputChannel, window } from 'vscode';
7+
import TelemetryReporter from '@vscode/extension-telemetry';
78
import { GithubRemoteSourceProvider } from './remoteSourceProvider';
89
import { API, GitExtension } from './typings/git';
910
import { registerCommands } from './commands';
@@ -29,8 +30,12 @@ export function activate(context: ExtensionContext): void {
2930
disposables.push(logger.onDidChangeLogLevel(onDidChangeLogLevel));
3031
onDidChangeLogLevel(logger.logLevel);
3132

33+
const { aiKey } = require('../package.json') as { aiKey: string };
34+
const telemetryReporter = new TelemetryReporter(aiKey);
35+
disposables.push(telemetryReporter);
36+
3237
disposables.push(initializeGitBaseExtension());
33-
disposables.push(initializeGitExtension(context, logger));
38+
disposables.push(initializeGitExtension(context, telemetryReporter, logger));
3439
}
3540

3641
function initializeGitBaseExtension(): Disposable {
@@ -78,7 +83,7 @@ function setGitHubContext(gitAPI: API, disposables: DisposableStore) {
7883
}
7984
}
8085

81-
function initializeGitExtension(context: ExtensionContext, logger: LogOutputChannel): Disposable {
86+
function initializeGitExtension(context: ExtensionContext, telemetryReporter: TelemetryReporter, logger: LogOutputChannel): Disposable {
8287
const disposables = new DisposableStore();
8388

8489
let gitExtension = extensions.getExtension<GitExtension>('vscode.git');
@@ -93,7 +98,7 @@ function initializeGitExtension(context: ExtensionContext, logger: LogOutputChan
9398
disposables.add(registerCommands(gitAPI));
9499
disposables.add(new GithubCredentialProviderManager(gitAPI));
95100
disposables.add(new GithubBranchProtectionProviderManager(gitAPI, context.globalState, logger));
96-
disposables.add(gitAPI.registerPushErrorHandler(new GithubPushErrorHandler()));
101+
disposables.add(gitAPI.registerPushErrorHandler(new GithubPushErrorHandler(telemetryReporter)));
97102
disposables.add(gitAPI.registerRemoteSourcePublisher(new GithubRemoteSourcePublisher(gitAPI)));
98103
disposables.add(new GitHubCanonicalUriProvider(gitAPI));
99104
disposables.add(new VscodeDevShareProvider(gitAPI));

extensions/github/src/pushErrorHandler.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { TextDecoder } from 'util';
77
import { commands, env, ProgressLocation, Uri, window, workspace, QuickPickOptions, FileType, l10n, Disposable, TextDocumentContentProvider } from 'vscode';
8+
import TelemetryReporter from '@vscode/extension-telemetry';
89
import { getOctokit } from './auth';
910
import { GitErrorCodes, PushErrorHandler, Remote, Repository } from './typings/git';
1011
import * as path from 'path';
@@ -99,7 +100,7 @@ export class GithubPushErrorHandler implements PushErrorHandler {
99100
private disposables: Disposable[] = [];
100101
private commandErrors = new CommandErrorOutputTextDocumentContentProvider();
101102

102-
constructor() {
103+
constructor(private readonly telemetryReporter: TelemetryReporter) {
103104
this.disposables.push(workspace.registerTextDocumentContentProvider('github-output', this.commandErrors));
104105
}
105106

@@ -126,15 +127,41 @@ export class GithubPushErrorHandler implements PushErrorHandler {
126127

127128
if (error.gitErrorCode === GitErrorCodes.PermissionDenied) {
128129
await this.handlePermissionDeniedError(repository, remote, refspec, owner, repo);
130+
131+
/* __GDPR__
132+
"pushErrorHandler" : {
133+
"owner": "lszomoru",
134+
"handler": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
135+
}
136+
*/
137+
this.telemetryReporter.sendTelemetryEvent('pushErrorHandler', { handler: 'PermissionDenied' });
138+
129139
return true;
130140
}
131141

132142
// Push protection
133143
if (/GH009: Secrets detected!/i.test(error.stderr)) {
134144
await this.handlePushProtectionError(owner, repo, error.stderr);
145+
146+
/* __GDPR__
147+
"pushErrorHandler" : {
148+
"owner": "lszomoru",
149+
"handler": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
150+
}
151+
*/
152+
this.telemetryReporter.sendTelemetryEvent('pushErrorHandler', { handler: 'PushRejected.PushProtection' });
153+
135154
return true;
136155
}
137156

157+
/* __GDPR__
158+
"pushErrorHandler" : {
159+
"owner": "lszomoru",
160+
"handler": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
161+
}
162+
*/
163+
this.telemetryReporter.sendTelemetryEvent('pushErrorHandler', { handler: 'None' });
164+
138165
return false;
139166
}
140167

0 commit comments

Comments
 (0)