mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
Add github session telemetry event
This commit is contained in:
parent
1a4c9ac9f2
commit
2f277cb41e
|
@ -14,7 +14,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
const telemetryReporter = new TelemetryReporter(name, version, aiKey);
|
||||
|
||||
context.subscriptions.push(vscode.window.registerUriHandler(uriHandler));
|
||||
const loginService = new GitHubAuthenticationProvider(context);
|
||||
const loginService = new GitHubAuthenticationProvider(context, telemetryReporter);
|
||||
|
||||
await loginService.initialize(context);
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import { Keychain } from './common/keychain';
|
|||
import { GitHubServer, NETWORK_ERROR } from './githubServer';
|
||||
import Logger from './common/logger';
|
||||
import { arrayEquals } from './common/utils';
|
||||
import TelemetryReporter from 'vscode-extension-telemetry';
|
||||
|
||||
export const onDidChangeSessions = new vscode.EventEmitter<vscode.AuthenticationProviderAuthenticationSessionsChangeEvent>();
|
||||
|
||||
|
@ -25,12 +26,13 @@ interface SessionData {
|
|||
|
||||
export class GitHubAuthenticationProvider {
|
||||
private _sessions: vscode.AuthenticationSession[] = [];
|
||||
private _githubServer = new GitHubServer();
|
||||
private _githubServer: GitHubServer;
|
||||
|
||||
private _keychain: Keychain;
|
||||
|
||||
constructor(context: vscode.ExtensionContext) {
|
||||
constructor(context: vscode.ExtensionContext, telemetryReporter: TelemetryReporter) {
|
||||
this._keychain = new Keychain(context);
|
||||
this._githubServer = new GitHubServer(telemetryReporter);
|
||||
}
|
||||
|
||||
public async initialize(context: vscode.ExtensionContext): Promise<void> {
|
||||
|
@ -55,6 +57,7 @@ export class GitHubAuthenticationProvider {
|
|||
const verificationPromises = this._sessions.map(async session => {
|
||||
try {
|
||||
await this._githubServer.getUserInfo(session.accessToken);
|
||||
this._githubServer.checkIsEdu(session.accessToken);
|
||||
verifiedSessions.push(session);
|
||||
} catch (e) {
|
||||
// Remove sessions that return unauthorized response
|
||||
|
@ -163,6 +166,7 @@ export class GitHubAuthenticationProvider {
|
|||
public async createSession(scopes: string): Promise<vscode.AuthenticationSession> {
|
||||
const token = await this._githubServer.login(scopes);
|
||||
const session = await this.tokenToSession(token, scopes.split(' '));
|
||||
this._githubServer.checkIsEdu(token);
|
||||
await this.setToken(session);
|
||||
return session;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import fetch, { Response } from 'node-fetch';
|
|||
import { v4 as uuid } from 'uuid';
|
||||
import { PromiseAdapter, promiseFromEvent } from './common/utils';
|
||||
import Logger from './common/logger';
|
||||
import TelemetryReporter from 'vscode-extension-telemetry';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
|
@ -41,6 +42,8 @@ export class GitHubServer {
|
|||
private _pendingStates = new Map<string, string[]>();
|
||||
private _codeExchangePromises = new Map<string, Promise<string>>();
|
||||
|
||||
constructor(private readonly telemetryReporter: TelemetryReporter) { }
|
||||
|
||||
private isTestEnvironment(url: vscode.Uri): boolean {
|
||||
return url.authority === 'vscode-web-test-playground.azurewebsites.net' || url.authority.startsWith('localhost:');
|
||||
}
|
||||
|
@ -210,4 +213,36 @@ export class GitHubServer {
|
|||
throw new Error(result.statusText);
|
||||
}
|
||||
}
|
||||
|
||||
public async checkIsEdu(token: string): Promise<void> {
|
||||
try {
|
||||
const result = await fetch('https://education.github.com/api/user', {
|
||||
headers: {
|
||||
Authorization: `token ${token}`,
|
||||
'faculty-check-preview': 'true',
|
||||
'User-Agent': 'Visual-Studio-Code'
|
||||
}
|
||||
});
|
||||
|
||||
if (result.ok) {
|
||||
const json: { student: boolean, faculty: boolean } = await result.json();
|
||||
|
||||
/* __GDPR__
|
||||
"session" : {
|
||||
"isEdu": { "classification": "PublicNonPersonalData", "purpose": "FeatureInsight" }
|
||||
}
|
||||
*/
|
||||
this.telemetryReporter.sendTelemetryEvent('session', {
|
||||
isEdu: json.student
|
||||
? 'student'
|
||||
: json.faculty
|
||||
? 'faculty'
|
||||
: 'none'
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// No-op
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue