Skip to content

Commit 9a67c9c

Browse files
committed
add basic telemetry for usage and failures
1 parent 9bd009a commit 9a67c9c

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Extension/src/LanguageServer/extension.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,8 @@ export async function preReleaseCheck(): Promise<void> {
13951395
// This uses several workarounds for interacting with the hover feature.
13961396
// A proposal for dynamic hover content would help, such as the one here (https://github.com/microsoft/vscode/issues/195394)
13971397
async function onCopilotHover(): Promise<void> {
1398+
telemetry.logLanguageServerEvent("CopilotHover");
1399+
13981400
// Check if the user has access to vscode language model.
13991401
const vscodelm = (vscode as any).lm;
14001402
if (!vscodelm) {
@@ -1412,8 +1414,6 @@ async function onCopilotHover(): Promise<void> {
14121414
return;
14131415
}
14141416

1415-
const errorMessage = localize("copilot.hover.error", "An error occurred while generating Copilot summary.");
1416-
14171417
// Prep hover with wait message.
14181418
copilotHoverProvider.showWaiting();
14191419

@@ -1430,9 +1430,8 @@ async function onCopilotHover(): Promise<void> {
14301430

14311431
// Gather the content for the query from the client.
14321432
const requestInfo = await copilotHoverProvider.getRequestInfo(hoverDocument, hoverPosition);
1433-
14341433
if (requestInfo.length === 0) {
1435-
await showCopilotContent(copilotHoverProvider, hoverDocument, hoverPosition, errorMessage);
1434+
await reportCopilotFailure(copilotHoverProvider, hoverDocument, hoverPosition, "Failed to receive request info from the client.");
14361435
return;
14371436
}
14381437

@@ -1454,7 +1453,7 @@ async function onCopilotHover(): Promise<void> {
14541453
} catch (err) {
14551454
if (err instanceof vscode.LanguageModelError) {
14561455
console.log(err.message, err.code, err.cause);
1457-
await showCopilotContent(copilotHoverProvider, hoverDocument, hoverPosition, errorMessage);
1456+
await reportCopilotFailure(copilotHoverProvider, hoverDocument, hoverPosition, err.message);
14581457
} else {
14591458
throw err;
14601459
}
@@ -1463,7 +1462,7 @@ async function onCopilotHover(): Promise<void> {
14631462

14641463
// Ensure we have a valid response from Copilot.
14651464
if (!chatResponse) {
1466-
await showCopilotContent(copilotHoverProvider, hoverDocument, hoverPosition, errorMessage);
1465+
await reportCopilotFailure(copilotHoverProvider, hoverDocument, hoverPosition);
14671466
return;
14681467
}
14691468

@@ -1474,18 +1473,29 @@ async function onCopilotHover(): Promise<void> {
14741473
content += fragment;
14751474
}
14761475
} catch (err) {
1477-
await showCopilotContent(copilotHoverProvider, hoverDocument, hoverPosition, errorMessage);
1476+
if (err instanceof Error) {
1477+
console.log(err.message, err.cause);
1478+
await reportCopilotFailure(copilotHoverProvider, hoverDocument, hoverPosition, err.message);
1479+
}
14781480
return;
14791481
}
14801482

14811483
if (content.length === 0) {
1482-
await showCopilotContent(copilotHoverProvider, hoverDocument, hoverPosition, errorMessage);
1484+
await reportCopilotFailure(copilotHoverProvider, hoverDocument, hoverPosition);
14831485
return;
14841486
}
14851487

14861488
await showCopilotContent(copilotHoverProvider, hoverDocument, hoverPosition, content);
14871489
}
14881490

1491+
async function reportCopilotFailure(copilotHoverProvider: CopilotHoverProvider, hoverDocument: vscode.TextDocument, hoverPosition: vscode.Position, customError?: string): Promise<void> {
1492+
const defaultError = "An error occurred while generating Copilot summary.";
1493+
const errorMessage = customError ? customError : defaultError;
1494+
telemetry.logLanguageServerEvent("CopilotHoverError", { errorMessage });
1495+
// Display the localized default failure message in the hover.
1496+
await showCopilotContent(copilotHoverProvider, hoverDocument, hoverPosition, localize("copilot.hover.error", defaultError));
1497+
}
1498+
14891499
async function showCopilotContent(copilotHoverProvider: CopilotHoverProvider, hoverDocument: vscode.TextDocument, hoverPosition: vscode.Position, content?: string): Promise<boolean> {
14901500
// Check if the cursor has been manually moved by the user. If so, exit.
14911501
const currentCursorPosition = vscode.window.activeTextEditor?.selection.active;

0 commit comments

Comments
 (0)