Skip to content

Commit 68dc220

Browse files
authored
Include slashCommand type in chat telemetry (microsoft#186565)
1 parent 4000c1d commit 68dc220

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/vs/workbench/contrib/chat/browser/chatWidget.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,8 @@ export class ChatWidget extends Disposable implements IChatWidget {
401401
}
402402
this._chatAccessibilityService.acceptRequest();
403403
const input = query ?? editorValue;
404-
const result = await this.chatService.sendRequest(this.viewModel.sessionId, input);
404+
const usedSlashCommand = this.lookupSlashCommand(typeof input === 'string' ? input : input.message);
405+
const result = await this.chatService.sendRequest(this.viewModel.sessionId, input, usedSlashCommand);
405406

406407
if (result) {
407408
this.inputPart.acceptInput(query);
@@ -416,6 +417,10 @@ export class ChatWidget extends Disposable implements IChatWidget {
416417
}
417418
}
418419

420+
private lookupSlashCommand(input: string): ISlashCommand | undefined {
421+
return this.lastSlashCommands?.find(sc => input.startsWith(`/${sc.command}`));
422+
}
423+
419424
getCodeBlockInfosForResponse(response: IChatResponseViewModel): IChatCodeBlockInfo[] {
420425
return this.renderer.getCodeBlockInfosForResponse(response);
421426
}

src/vs/workbench/contrib/chat/common/chatService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export interface IChatService {
187187
/**
188188
* Returns whether the request was accepted.
189189
*/
190-
sendRequest(sessionId: string, message: string | IChatReplyFollowup): Promise<{ responseCompletePromise: Promise<void> } | undefined>;
190+
sendRequest(sessionId: string, message: string | IChatReplyFollowup, usedSlashCommand?: ISlashCommand): Promise<{ responseCompletePromise: Promise<void> } | undefined>;
191191
removeRequest(sessionid: string, requestId: string): Promise<void>;
192192
cancelCurrentRequestForSession(sessionId: string): void;
193193
getSlashCommands(sessionId: string, token: CancellationToken): Promise<ISlashCommand[] | undefined>;

src/vs/workbench/contrib/chat/common/chatServiceImpl.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type ChatProviderInvokedEvent = {
4141
totalTime: number;
4242
result: 'success' | 'error' | 'errorWithOutput' | 'cancelled' | 'filtered';
4343
requestType: 'string' | 'followup' | 'slashCommand';
44+
slashCommand: string | undefined;
4445
};
4546

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

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

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

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

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

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

0 commit comments

Comments
 (0)