diff --git a/extensions/github-authentication/src/github.ts b/extensions/github-authentication/src/github.ts index 6dc6aceaae9..0588065eacd 100644 --- a/extensions/github-authentication/src/github.ts +++ b/extensions/github-authentication/src/github.ts @@ -110,7 +110,7 @@ export class GitHubAuthenticationProvider implements vscode.AuthenticationProvid // We only want to fire a telemetry if we haven't seen this account yet in this session. if (!this._accountsSeen.has(session.account.id)) { this._accountsSeen.add(session.account.id); - this._githubServer.sendAdditionalTelemetryInfo(session.accessToken); + this._githubServer.sendAdditionalTelemetryInfo(session); } } diff --git a/extensions/github-authentication/src/githubServer.ts b/extensions/github-authentication/src/githubServer.ts index 3662719cfc8..98bb1dd822f 100644 --- a/extensions/github-authentication/src/githubServer.ts +++ b/extensions/github-authentication/src/githubServer.ts @@ -31,7 +31,7 @@ const REDIRECT_URL_INSIDERS = 'https://insiders.vscode.dev/redirect'; export interface IGitHubServer { login(scopes: string): Promise; getUserInfo(token: string): Promise<{ id: string; accountName: string }>; - sendAdditionalTelemetryInfo(token: string): Promise; + sendAdditionalTelemetryInfo(session: vscode.AuthenticationSession): Promise; friendlyName: string; } @@ -48,7 +48,7 @@ async function getScopes(token: string, serverUri: vscode.Uri, logger: Log): Pro const result = await fetching(serverUri.toString(), { headers: { Authorization: `token ${token}`, - 'User-Agent': 'Visual-Studio-Code' + 'User-Agent': `${vscode.env.appName} (${vscode.env.appHost})` } }); @@ -510,7 +510,7 @@ export class GitHubServer implements IGitHubServer { result = await fetching(this.getServerUri('/user').toString(), { headers: { Authorization: `token ${token}`, - 'User-Agent': 'Visual-Studio-Code' + 'User-Agent': `${vscode.env.appName} (${vscode.env.appHost})` } }); } catch (ex) { @@ -543,7 +543,7 @@ export class GitHubServer implements IGitHubServer { } } - public async sendAdditionalTelemetryInfo(token: string): Promise { + public async sendAdditionalTelemetryInfo(session: vscode.AuthenticationSession): Promise { if (!vscode.env.isTelemetryEnabled) { return; } @@ -554,22 +554,22 @@ export class GitHubServer implements IGitHubServer { } if (this._type === AuthProviderType.github) { - return await this.checkUserDetails(token); + return await this.checkUserDetails(session); } // GHES - await this.checkEnterpriseVersion(token); + await this.checkEnterpriseVersion(session.accessToken); } - private async checkUserDetails(token: string): Promise { + private async checkUserDetails(session: vscode.AuthenticationSession): Promise { let edu: string | undefined; try { const result = await fetching('https://education.github.com/api/user', { headers: { - Authorization: `token ${token}`, + Authorization: `token ${session.accessToken}`, 'faculty-check-preview': 'true', - 'User-Agent': 'Visual-Studio-Code' + 'User-Agent': `${vscode.env.appName} (${vscode.env.appHost})` } }); @@ -580,22 +580,11 @@ export class GitHubServer implements IGitHubServer { : json.faculty ? 'faculty' : 'none'; + } else { + edu = 'unknown'; } } catch (e) { - // No-op - } - - let managed: string | undefined; - try { - const user = await this.getUserInfo(token); - // Apparently, this is how you tell if a user is an EMU... - managed = user.accountName.includes('_') ? 'true' : 'false'; - } catch (e) { - // No-op - } - - if (edu === undefined && managed === undefined) { - return; + edu = 'unknown'; } /* __GDPR__ @@ -606,8 +595,9 @@ export class GitHubServer implements IGitHubServer { } */ this._telemetryReporter.sendTelemetryEvent('session', { - isEdu: edu ?? 'unknown', - isManaged: managed ?? 'unknown' + isEdu: edu, + // Apparently, this is how you tell if a user is an EMU... + isManaged: session.account.label.includes('_') ? 'true' : 'false' }); } @@ -618,7 +608,7 @@ export class GitHubServer implements IGitHubServer { const result = await fetching(this.getServerUri('/meta').toString(), { headers: { Authorization: `token ${token}`, - 'User-Agent': 'Visual-Studio-Code' + 'User-Agent': `${vscode.env.appName} (${vscode.env.appHost})` } });