Skip to content

Commit

Permalink
chore: use telemetry logger for counting requests, and unhelpful feed…
Browse files Browse the repository at this point in the history
…back, to be able to compute success metric
  • Loading branch information
gargadobe committed Aug 5, 2024
1 parent 7846be0 commit 5e1cfa6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"version": "0.0.5",
"engines": {
"vscode": "^1.90.0"
"vscode": "^1.92.0"
},
"extensionDependencies": [
"github.copilot-chat"
Expand Down
36 changes: 34 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,21 @@ export function activate(context: vscode.ExtensionContext) {
try {
if (request.command === commands.INFO) {
cmdResult = await infoCmdHandler(request, stream, token);
logger.logUsage('request', { kind: commands.INFO });
} else if (request.command === commands.CREATE) {
cmdResult = await createCmdHandler(request, stream, token);
logger.logUsage('request', { kind: commands.CREATE });
} else if (request.command === commands.COLLECION) {
cmdResult = await fetchBlock(request, stream, token, context);
logger.logUsage('request', { kind: commands.COLLECION });
} else if (request.command === commands.ISSUES) {
cmdResult = await handleIssueManagement(request, stream, token);
logger.logUsage('request', { kind: commands.ISSUES });
} else {
cmdResult = await handleDocsCommand(request, stream, token);
}
} catch (err) {
handleError(err, stream);
handleError(logger, err, stream);
}

return {
Expand Down Expand Up @@ -76,6 +80,28 @@ export function activate(context: vscode.ExtensionContext) {
},
};

const logger = vscode.env.createTelemetryLogger({
sendEventData(eventName, data) {
// Capture event telemetry
console.log(`Event: ${eventName}`);
console.log(`Data: ${JSON.stringify(data)}`);
},
sendErrorData(error, data) {
// Capture error telemetry
console.error(`Error: ${error}`);
console.error(`Data: ${JSON.stringify(data)}`);
}
});


context.subscriptions.push(aem.onDidReceiveFeedback((feedback: vscode.ChatResultFeedback) => {
// Log chat result feedback to be able to compute the success matric of the participant
// unhelpful / totalRequests is a good success metric
logger.logUsage('chatResultFeedback', {
kind: feedback.kind
});
}));

context.subscriptions.push(
aem,
vscode.commands.registerCommand(
Expand All @@ -91,11 +117,17 @@ export function activate(context: vscode.ExtensionContext) {
}


function handleError(err: any, stream: vscode.ChatResponseStream): void {


function handleError(logger: vscode.TelemetryLogger, err: any, stream: vscode.ChatResponseStream): void {
// making the chat request might fail because
// - model does not exist
// - user consent not given
// - quote limits exceeded
if (logger.isErrorsEnabled) {
logger.logError(err);
}

if (err instanceof vscode.LanguageModelError) {
console.log(err.message, err.code, err.cause);
if (err.cause instanceof Error && err.cause.message.includes('off_topic')) {
Expand Down

0 comments on commit 5e1cfa6

Please sign in to comment.