diff --git a/packages/amazonq/src/lsp/chat/autoDebug/commands.ts b/packages/amazonq/src/lsp/chat/autoDebug/commands.ts index 54dfd06a1dc..29003a9c6e8 100644 --- a/packages/amazonq/src/lsp/chat/autoDebug/commands.ts +++ b/packages/amazonq/src/lsp/chat/autoDebug/commands.ts @@ -6,6 +6,7 @@ import * as vscode from 'vscode' import { Commands, getLogger, messages } from 'aws-core-vscode/shared' import { AutoDebugController } from './controller' +import { autoDebugTelemetry } from './telemetry' /** * Auto Debug commands for Amazon Q @@ -72,6 +73,16 @@ export class AutoDebugCommands implements vscode.Disposable { return await action() } catch (error) { this.logger.error(`AutoDebugCommands: Error in ${logContext}: %s`, error) + + // Record telemetry failure based on context + const commandType = + logContext === 'fixWithAmazonQ' + ? 'fixWithQ' + : logContext === 'fixAllWithAmazonQ' + ? 'fixAllWithQ' + : 'explainProblem' + autoDebugTelemetry.recordCommandFailure(commandType, String(error)) + void messages.showMessage('error', 'Amazon Q was not able to fix or explain the problem. Try again shortly') } } @@ -91,6 +102,9 @@ export class AutoDebugCommands implements vscode.Disposable { * Fix with Amazon Q - fixes only the specific issues the user selected */ private async fixWithAmazonQ(range?: vscode.Range, diagnostics?: vscode.Diagnostic[]): Promise { + const problemCount = diagnostics?.length + autoDebugTelemetry.recordCommandInvocation('fixWithQ', problemCount) + await this.executeWithErrorHandling( async () => { const editor = this.checkActiveEditor() @@ -98,6 +112,7 @@ export class AutoDebugCommands implements vscode.Disposable { return } await this.controller.fixSpecificProblems(range, diagnostics) + autoDebugTelemetry.recordCommandSuccess('fixWithQ', problemCount) }, 'Fix with Amazon Q', 'fixWithAmazonQ' @@ -108,13 +123,16 @@ export class AutoDebugCommands implements vscode.Disposable { * Fix All with Amazon Q - processes all errors in the current file */ private async fixAllWithAmazonQ(): Promise { + autoDebugTelemetry.recordCommandInvocation('fixAllWithQ') + await this.executeWithErrorHandling( async () => { const editor = this.checkActiveEditor() if (!editor) { return } - await this.controller.fixAllProblemsInFile(10) // 10 errors per batch + const problemCount = await this.controller.fixAllProblemsInFile(10) // 10 errors per batch + autoDebugTelemetry.recordCommandSuccess('fixAllWithQ', problemCount) }, 'Fix All with Amazon Q', 'fixAllWithAmazonQ' @@ -125,6 +143,9 @@ export class AutoDebugCommands implements vscode.Disposable { * Explains the problem using Amazon Q */ private async explainProblem(range?: vscode.Range, diagnostics?: vscode.Diagnostic[]): Promise { + const problemCount = diagnostics?.length + autoDebugTelemetry.recordCommandInvocation('explainProblem', problemCount) + await this.executeWithErrorHandling( async () => { const editor = this.checkActiveEditor() @@ -132,6 +153,7 @@ export class AutoDebugCommands implements vscode.Disposable { return } await this.controller.explainProblems(range, diagnostics) + autoDebugTelemetry.recordCommandSuccess('explainProblem', problemCount) }, 'Explain Problem', 'explainProblem' diff --git a/packages/amazonq/src/lsp/chat/autoDebug/controller.ts b/packages/amazonq/src/lsp/chat/autoDebug/controller.ts index 0a0f8e10622..66dcc83b21d 100644 --- a/packages/amazonq/src/lsp/chat/autoDebug/controller.ts +++ b/packages/amazonq/src/lsp/chat/autoDebug/controller.ts @@ -110,32 +110,34 @@ export class AutoDebugController implements vscode.Disposable { /** * Fix with Amazon Q - sends up to 15 error messages one time when user clicks the button */ - public async fixAllProblemsInFile(maxProblems: number = 15): Promise { + public async fixAllProblemsInFile(maxProblems: number = 15): Promise { try { const editor = vscode.window.activeTextEditor if (!editor) { void messages.showMessage('warn', 'No active editor found') - return + return 0 } // Get all diagnostics for the current file const allDiagnostics = vscode.languages.getDiagnostics(editor.document.uri) const errorDiagnostics = this.filterErrorDiagnostics(allDiagnostics) if (errorDiagnostics.length === 0) { - return + return 0 } // Take up to maxProblems errors (15 by default) const diagnosticsToFix = errorDiagnostics.slice(0, maxProblems) const result = await this.getProblemsFromDiagnostics(undefined, diagnosticsToFix) if (!result) { - return + return 0 } const fixMessage = this.createFixMessage(result.editor.document.uri.fsPath, result.problems) await this.sendMessageToChat(fixMessage) + return result.problems.length } catch (error) { this.logger.error('AutoDebugController: Error in fix process: %s', error) + throw error } } diff --git a/packages/amazonq/src/lsp/chat/autoDebug/telemetry.ts b/packages/amazonq/src/lsp/chat/autoDebug/telemetry.ts new file mode 100644 index 00000000000..dec3f424c5a --- /dev/null +++ b/packages/amazonq/src/lsp/chat/autoDebug/telemetry.ts @@ -0,0 +1,71 @@ +/*! + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +import { telemetry } from 'aws-core-vscode/telemetry' + +/** + * Auto Debug command types for telemetry tracking + */ +export type AutoDebugCommandType = 'fixWithQ' | 'fixAllWithQ' | 'explainProblem' + +/** + * Telemetry interface for Auto Debug feature + * Tracks usage counts and success rates for the three main commands + */ +export interface AutoDebugTelemetry { + /** + * Record when an auto debug command is invoked + */ + recordCommandInvocation(commandType: AutoDebugCommandType, problemCount?: number): void + + /** + * Record when an auto debug command succeeds + */ + recordCommandSuccess(commandType: AutoDebugCommandType, problemCount?: number): void + + /** + * Record when an auto debug command fails + */ + recordCommandFailure(commandType: AutoDebugCommandType, error?: string, problemCount?: number): void +} + +/** + * Implementation of Auto Debug telemetry tracking + */ +export class AutoDebugTelemetryImpl implements AutoDebugTelemetry { + recordCommandInvocation(commandType: AutoDebugCommandType, problemCount?: number): void { + telemetry.amazonq_autoDebugCommand.emit({ + amazonqAutoDebugCommandType: commandType, + amazonqAutoDebugAction: 'invoked', + amazonqAutoDebugProblemCount: problemCount, + result: 'Succeeded', + }) + } + + recordCommandSuccess(commandType: AutoDebugCommandType, problemCount?: number): void { + telemetry.amazonq_autoDebugCommand.emit({ + amazonqAutoDebugCommandType: commandType, + amazonqAutoDebugAction: 'completed', + amazonqAutoDebugProblemCount: problemCount, + result: 'Succeeded', + }) + } + + recordCommandFailure(commandType: AutoDebugCommandType, error?: string, problemCount?: number): void { + telemetry.amazonq_autoDebugCommand.emit({ + amazonqAutoDebugCommandType: commandType, + amazonqAutoDebugAction: 'completed', + amazonqAutoDebugProblemCount: problemCount, + result: 'Failed', + reason: error ? 'Error' : 'Unknown', + reasonDesc: error?.substring(0, 200), // Truncate to 200 chars as recommended + }) + } +} + +/** + * Global instance of auto debug telemetry + */ +export const autoDebugTelemetry: AutoDebugTelemetry = new AutoDebugTelemetryImpl() diff --git a/packages/core/src/shared/telemetry/vscodeTelemetry.json b/packages/core/src/shared/telemetry/vscodeTelemetry.json index 1128eef8ab6..8cddfb9cba4 100644 --- a/packages/core/src/shared/telemetry/vscodeTelemetry.json +++ b/packages/core/src/shared/telemetry/vscodeTelemetry.json @@ -238,6 +238,23 @@ "name": "executedCount", "type": "int", "description": "The number of executed operations" + }, + { + "name": "amazonqAutoDebugCommandType", + "type": "string", + "allowedValues": ["fixWithQ", "fixAllWithQ", "explainProblem"], + "description": "The type of auto debug command executed" + }, + { + "name": "amazonqAutoDebugAction", + "type": "string", + "allowedValues": ["invoked", "completed"], + "description": "The action performed (invoked or completed)" + }, + { + "name": "amazonqAutoDebugProblemCount", + "type": "int", + "description": "Number of problems being processed" } ], "metrics": [ @@ -1257,6 +1274,35 @@ "required": false } ] + }, + { + "name": "amazonq_autoDebugCommand", + "description": "Tracks usage of Amazon Q auto debug commands (fixWithQ, fixAllWithQ, explainProblem)", + "metadata": [ + { + "type": "amazonqAutoDebugCommandType", + "required": true + }, + { + "type": "amazonqAutoDebugAction", + "required": true + }, + { + "type": "amazonqAutoDebugProblemCount", + "required": false + }, + { + "type": "result" + }, + { + "type": "reason", + "required": false + }, + { + "type": "reasonDesc", + "required": false + } + ] } ] }