Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chat setup - log sign up error code #237475

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/vs/workbench/contrib/chat/browser/chatSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ class ChatSetupRequests extends Disposable {
return this.resolveEntitlement(session, CancellationToken.None);
}

async signUpLimited(session: AuthenticationSession): Promise<true /* signed up */ | false /* already signed up */ | undefined /* error */> {
async signUpLimited(session: AuthenticationSession): Promise<true /* signed up */ | false /* already signed up */ | { errorCode: number } /* error */> {
const body = {
restricted_telemetry: this.telemetryService.telemetryLevel === TelemetryLevel.NONE ? 'disabled' : 'enabled',
public_code_suggestions: 'enabled'
Expand All @@ -600,7 +600,7 @@ class ChatSetupRequests extends Disposable {
const response = await this.request(defaultChat.entitlementSignupLimitedUrl, 'POST', body, session, CancellationToken.None);
if (!response) {
this.onUnknownSignUpError('[chat setup] sign-up: no response');
return undefined;
return { errorCode: 1 };
}

if (response.res.statusCode && response.res.statusCode !== 200) {
Expand All @@ -611,15 +611,15 @@ class ChatSetupRequests extends Disposable {
const responseError: { message: string } = JSON.parse(responseText);
if (typeof responseError.message === 'string' && responseError.message) {
this.onUnprocessableSignUpError(`[chat setup] sign-up: unprocessable entity (${responseError.message})`, responseError.message);
return undefined;
return { errorCode: response.res.statusCode };
}
}
} catch (error) {
// ignore - handled below
}
}
this.onUnknownSignUpError(`[chat setup] sign-up: unexpected status code ${response.res.statusCode}`);
return undefined;
return { errorCode: response.res.statusCode };
}

let responseText: string | null = null;
Expand All @@ -631,7 +631,7 @@ class ChatSetupRequests extends Disposable {

if (!responseText) {
this.onUnknownSignUpError('[chat setup] sign-up: response has no content');
return undefined;
return { errorCode: 2 };
}

let parsedResult: { subscribed: boolean } | undefined = undefined;
Expand All @@ -640,7 +640,7 @@ class ChatSetupRequests extends Disposable {
this.logService.trace(`[chat setup] sign-up: response is ${responseText}`);
} catch (err) {
this.onUnknownSignUpError(`[chat setup] sign-up: error parsing response (${err})`);
return undefined;
return { errorCode: 3 };
}

// We have made it this far, so the user either did sign-up or was signed-up already.
Expand Down Expand Up @@ -690,10 +690,12 @@ type InstallChatClassification = {
comment: 'Provides insight into chat installation.';
installResult: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Whether the extension was installed successfully, cancelled or failed to install.' };
signedIn: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Whether the user did sign in prior to installing the extension.' };
signUpErrorCode: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The error code in case of an error signing up.' };
};
type InstallChatEvent = {
installResult: 'installed' | 'cancelled' | 'failedInstall' | 'failedNotSignedIn' | 'failedSignUp';
signedIn: boolean;
signUpErrorCode: number | undefined;
};

enum ChatSetupStep {
Expand Down Expand Up @@ -824,7 +826,7 @@ class ChatSetupController extends Disposable {
}

if (!session) {
this.telemetryService.publicLog2<InstallChatEvent, InstallChatClassification>('commandCenter.chatInstall', { installResult: 'failedNotSignedIn', signedIn: false });
this.telemetryService.publicLog2<InstallChatEvent, InstallChatClassification>('commandCenter.chatInstall', { installResult: 'failedNotSignedIn', signedIn: false, signUpErrorCode: undefined });
}

return { session, entitlement };
Expand All @@ -835,15 +837,15 @@ class ChatSetupController extends Disposable {

let installResult: 'installed' | 'cancelled' | 'failedInstall' | undefined = undefined;
const wasInstalled = this.context.state.installed;
let didSignUp: boolean | undefined = undefined;
let didSignUp: boolean | { errorCode: number } | undefined = undefined;
try {
showCopilotView(this.viewsService, this.layoutService);

if (entitlement !== ChatEntitlement.Limited && entitlement !== ChatEntitlement.Pro && entitlement !== ChatEntitlement.Unavailable) {
didSignUp = await this.requests.signUpLimited(session);

if (typeof didSignUp === 'undefined' /* error */) {
this.telemetryService.publicLog2<InstallChatEvent, InstallChatClassification>('commandCenter.chatInstall', { installResult: 'failedSignUp', signedIn });
if (typeof didSignUp !== 'boolean' /* error */) {
this.telemetryService.publicLog2<InstallChatEvent, InstallChatClassification>('commandCenter.chatInstall', { installResult: 'failedSignUp', signedIn, signUpErrorCode: didSignUp.errorCode });
}
}

Expand Down Expand Up @@ -873,7 +875,7 @@ class ChatSetupController extends Disposable {
}
}

this.telemetryService.publicLog2<InstallChatEvent, InstallChatClassification>('commandCenter.chatInstall', { installResult, signedIn });
this.telemetryService.publicLog2<InstallChatEvent, InstallChatClassification>('commandCenter.chatInstall', { installResult, signedIn, signUpErrorCode: undefined });
}
}

Expand Down
Loading