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

Include slashCommand type in chat telemetry #186565

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/vs/workbench/contrib/chat/browser/chatWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ export class ChatWidget extends Disposable implements IChatWidget {
}
this._chatAccessibilityService.acceptRequest();
const input = query ?? editorValue;
const result = await this.chatService.sendRequest(this.viewModel.sessionId, input);
const usedSlashCommand = this.lookupSlashCommand(typeof input === 'string' ? input : input.message);
const result = await this.chatService.sendRequest(this.viewModel.sessionId, input, usedSlashCommand);

if (result) {
this.inputPart.acceptInput(query);
Expand All @@ -416,6 +417,10 @@ export class ChatWidget extends Disposable implements IChatWidget {
}
}

private lookupSlashCommand(input: string): ISlashCommand | undefined {
return this.lastSlashCommands?.find(sc => input.startsWith(`/${sc.command}`));
}

getCodeBlockInfosForResponse(response: IChatResponseViewModel): IChatCodeBlockInfo[] {
return this.renderer.getCodeBlockInfosForResponse(response);
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/chat/common/chatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export interface IChatService {
/**
* Returns whether the request was accepted.
*/
sendRequest(sessionId: string, message: string | IChatReplyFollowup): Promise<{ responseCompletePromise: Promise<void> } | undefined>;
sendRequest(sessionId: string, message: string | IChatReplyFollowup, usedSlashCommand?: ISlashCommand): Promise<{ responseCompletePromise: Promise<void> } | undefined>;
removeRequest(sessionid: string, requestId: string): Promise<void>;
cancelCurrentRequestForSession(sessionId: string): void;
getSlashCommands(sessionId: string, token: CancellationToken): Promise<ISlashCommand[] | undefined>;
Expand Down
14 changes: 9 additions & 5 deletions src/vs/workbench/contrib/chat/common/chatServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type ChatProviderInvokedEvent = {
totalTime: number;
result: 'success' | 'error' | 'errorWithOutput' | 'cancelled' | 'filtered';
requestType: 'string' | 'followup' | 'slashCommand';
slashCommand: string | undefined;
};

type ChatProviderInvokedClassification = {
Expand All @@ -49,6 +50,7 @@ type ChatProviderInvokedClassification = {
totalTime: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; isMeasurement: true; comment: 'The total time it took to run the provider\'s `provideResponseWithProgress`.' };
result: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Whether invoking the ChatProvider resulted in an error.' };
requestType: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The type of request that the user made.' };
slashCommand?: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The type of slashCommand used.' };
owner: 'roblourens';
comment: 'Provides insight into the performance of Chat providers.';
};
Expand Down Expand Up @@ -357,7 +359,7 @@ export class ChatService extends Disposable implements IChatService {
return this._startSession(data.providerId, data, CancellationToken.None);
}

async sendRequest(sessionId: string, request: string | IChatReplyFollowup): Promise<{ responseCompletePromise: Promise<void> } | undefined> {
async sendRequest(sessionId: string, request: string | IChatReplyFollowup, usedSlashCommand?: ISlashCommand): Promise<{ responseCompletePromise: Promise<void> } | undefined> {
const messageText = typeof request === 'string' ? request : request.message;
this.trace('sendRequest', `sessionId: ${sessionId}, message: ${messageText.substring(0, 20)}${messageText.length > 20 ? '[...]' : ''}}`);
if (!messageText.trim()) {
Expand All @@ -382,10 +384,10 @@ export class ChatService extends Disposable implements IChatService {
}

// This method is only returning whether the request was accepted - don't block on the actual request
return { responseCompletePromise: this._sendRequestAsync(model, provider, request) };
return { responseCompletePromise: this._sendRequestAsync(model, provider, request, usedSlashCommand) };
}

private async _sendRequestAsync(model: ChatModel, provider: IChatProvider, message: string | IChatReplyFollowup): Promise<void> {
private async _sendRequestAsync(model: ChatModel, provider: IChatProvider, message: string | IChatReplyFollowup, usedSlashCommand?: ISlashCommand): Promise<void> {
const request = model.addRequest(message);

const resolvedCommand = typeof message === 'string' && message.startsWith('/') ? await this.handleSlashCommand(model.sessionId, message) : message;
Expand Down Expand Up @@ -420,7 +422,8 @@ export class ChatService extends Disposable implements IChatService {
// Normally timings happen inside the EH around the actual provider. For cancellation we can measure how long the user waited before cancelling
totalTime: stopWatch.elapsed(),
result: 'cancelled',
requestType
requestType,
slashCommand: usedSlashCommand?.command
});

model.cancelRequest(request);
Expand All @@ -443,7 +446,8 @@ export class ChatService extends Disposable implements IChatService {
timeToFirstProgress: rawResponse.timings?.firstProgress ?? 0,
totalTime: rawResponse.timings?.totalElapsed ?? 0,
result,
requestType
requestType,
slashCommand: usedSlashCommand?.command
});
model.completeResponse(request, rawResponse);
this.trace('sendRequest', `Provider returned response for session ${model.sessionId}`);
Expand Down