Skip to content

Commit ebbf2eb

Browse files
MarcoWang3ashishrp-awslaileni-aws
authored
fix(amazonq):Add telemetry support for Auto Debug feature (aws#7835)
## Problem Currently there is no telemetry support for auto debug feature. ## Solution Add telemetry support for auto debug feature. --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: invictus <[email protected]> Co-authored-by: Ashish Reddy Podduturi <[email protected]> Co-authored-by: Laxman Reddy <[email protected]>
1 parent 4a8db6d commit ebbf2eb

File tree

4 files changed

+146
-5
lines changed

4 files changed

+146
-5
lines changed

packages/amazonq/src/lsp/chat/autoDebug/commands.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import * as vscode from 'vscode'
77
import { Commands, getLogger, messages } from 'aws-core-vscode/shared'
88
import { AutoDebugController } from './controller'
9+
import { autoDebugTelemetry } from './telemetry'
910

1011
/**
1112
* Auto Debug commands for Amazon Q
@@ -72,6 +73,16 @@ export class AutoDebugCommands implements vscode.Disposable {
7273
return await action()
7374
} catch (error) {
7475
this.logger.error(`AutoDebugCommands: Error in ${logContext}: %s`, error)
76+
77+
// Record telemetry failure based on context
78+
const commandType =
79+
logContext === 'fixWithAmazonQ'
80+
? 'fixWithQ'
81+
: logContext === 'fixAllWithAmazonQ'
82+
? 'fixAllWithQ'
83+
: 'explainProblem'
84+
autoDebugTelemetry.recordCommandFailure(commandType, String(error))
85+
7586
void messages.showMessage('error', 'Amazon Q was not able to fix or explain the problem. Try again shortly')
7687
}
7788
}
@@ -91,6 +102,9 @@ export class AutoDebugCommands implements vscode.Disposable {
91102
* Fix with Amazon Q - fixes only the specific issues the user selected
92103
*/
93104
private async fixWithAmazonQ(range?: vscode.Range, diagnostics?: vscode.Diagnostic[]): Promise<void> {
105+
const problemCount = diagnostics?.length
106+
autoDebugTelemetry.recordCommandInvocation('fixWithQ', problemCount)
107+
94108
await this.executeWithErrorHandling(
95109
async () => {
96110
const editor = this.checkActiveEditor()
@@ -102,6 +116,7 @@ export class AutoDebugCommands implements vscode.Disposable {
102116
throw new Error('Failed to save document')
103117
}
104118
await this.controller.fixSpecificProblems(range, diagnostics)
119+
autoDebugTelemetry.recordCommandSuccess('fixWithQ', problemCount)
105120
},
106121
'Fix with Amazon Q',
107122
'fixWithAmazonQ'
@@ -112,6 +127,8 @@ export class AutoDebugCommands implements vscode.Disposable {
112127
* Fix All with Amazon Q - processes all errors in the current file
113128
*/
114129
private async fixAllWithAmazonQ(): Promise<void> {
130+
autoDebugTelemetry.recordCommandInvocation('fixAllWithQ')
131+
115132
await this.executeWithErrorHandling(
116133
async () => {
117134
const editor = this.checkActiveEditor()
@@ -122,7 +139,8 @@ export class AutoDebugCommands implements vscode.Disposable {
122139
if (!saved) {
123140
throw new Error('Failed to save document')
124141
}
125-
await this.controller.fixAllProblemsInFile(10) // 10 errors per batch
142+
const problemCount = await this.controller.fixAllProblemsInFile(10) // 10 errors per batch
143+
autoDebugTelemetry.recordCommandSuccess('fixAllWithQ', problemCount)
126144
},
127145
'Fix All with Amazon Q',
128146
'fixAllWithAmazonQ'
@@ -133,13 +151,17 @@ export class AutoDebugCommands implements vscode.Disposable {
133151
* Explains the problem using Amazon Q
134152
*/
135153
private async explainProblem(range?: vscode.Range, diagnostics?: vscode.Diagnostic[]): Promise<void> {
154+
const problemCount = diagnostics?.length
155+
autoDebugTelemetry.recordCommandInvocation('explainProblem', problemCount)
156+
136157
await this.executeWithErrorHandling(
137158
async () => {
138159
const editor = this.checkActiveEditor()
139160
if (!editor) {
140161
return
141162
}
142163
await this.controller.explainProblems(range, diagnostics)
164+
autoDebugTelemetry.recordCommandSuccess('explainProblem', problemCount)
143165
},
144166
'Explain Problem',
145167
'explainProblem'

packages/amazonq/src/lsp/chat/autoDebug/controller.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,32 +110,34 @@ export class AutoDebugController implements vscode.Disposable {
110110
/**
111111
* Fix with Amazon Q - sends up to 15 error messages one time when user clicks the button
112112
*/
113-
public async fixAllProblemsInFile(maxProblems: number = 15): Promise<void> {
113+
public async fixAllProblemsInFile(maxProblems: number = 15): Promise<number> {
114114
try {
115115
const editor = vscode.window.activeTextEditor
116116
if (!editor) {
117117
void messages.showMessage('warn', 'No active editor found')
118-
return
118+
return 0
119119
}
120120

121121
// Get all diagnostics for the current file
122122
const allDiagnostics = vscode.languages.getDiagnostics(editor.document.uri)
123123
const errorDiagnostics = this.filterErrorDiagnostics(allDiagnostics)
124124
if (errorDiagnostics.length === 0) {
125-
return
125+
return 0
126126
}
127127

128128
// Take up to maxProblems errors (15 by default)
129129
const diagnosticsToFix = errorDiagnostics.slice(0, maxProblems)
130130
const result = await this.getProblemsFromDiagnostics(undefined, diagnosticsToFix)
131131
if (!result) {
132-
return
132+
return 0
133133
}
134134

135135
const fixMessage = this.createFixMessage(result.editor.document.uri.fsPath, result.problems)
136136
await this.sendMessageToChat(fixMessage)
137+
return result.problems.length
137138
} catch (error) {
138139
this.logger.error('AutoDebugController: Error in fix process: %s', error)
140+
throw error
139141
}
140142
}
141143

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { telemetry } from 'aws-core-vscode/telemetry'
7+
8+
/**
9+
* Auto Debug command types for telemetry tracking
10+
*/
11+
export type AutoDebugCommandType = 'fixWithQ' | 'fixAllWithQ' | 'explainProblem'
12+
13+
/**
14+
* Telemetry interface for Auto Debug feature
15+
* Tracks usage counts and success rates for the three main commands
16+
*/
17+
export interface AutoDebugTelemetry {
18+
/**
19+
* Record when an auto debug command is invoked
20+
*/
21+
recordCommandInvocation(commandType: AutoDebugCommandType, problemCount?: number): void
22+
23+
/**
24+
* Record when an auto debug command succeeds
25+
*/
26+
recordCommandSuccess(commandType: AutoDebugCommandType, problemCount?: number): void
27+
28+
/**
29+
* Record when an auto debug command fails
30+
*/
31+
recordCommandFailure(commandType: AutoDebugCommandType, error?: string, problemCount?: number): void
32+
}
33+
34+
/**
35+
* Implementation of Auto Debug telemetry tracking
36+
*/
37+
export class AutoDebugTelemetryImpl implements AutoDebugTelemetry {
38+
recordCommandInvocation(commandType: AutoDebugCommandType, problemCount?: number): void {
39+
telemetry.amazonq_autoDebugCommand.emit({
40+
amazonqAutoDebugCommandType: commandType,
41+
amazonqAutoDebugAction: 'invoked',
42+
amazonqAutoDebugProblemCount: problemCount,
43+
result: 'Succeeded',
44+
})
45+
}
46+
47+
recordCommandSuccess(commandType: AutoDebugCommandType, problemCount?: number): void {
48+
telemetry.amazonq_autoDebugCommand.emit({
49+
amazonqAutoDebugCommandType: commandType,
50+
amazonqAutoDebugAction: 'completed',
51+
amazonqAutoDebugProblemCount: problemCount,
52+
result: 'Succeeded',
53+
})
54+
}
55+
56+
recordCommandFailure(commandType: AutoDebugCommandType, error?: string, problemCount?: number): void {
57+
telemetry.amazonq_autoDebugCommand.emit({
58+
amazonqAutoDebugCommandType: commandType,
59+
amazonqAutoDebugAction: 'completed',
60+
amazonqAutoDebugProblemCount: problemCount,
61+
result: 'Failed',
62+
reason: error ? 'Error' : 'Unknown',
63+
reasonDesc: error?.substring(0, 200), // Truncate to 200 chars as recommended
64+
})
65+
}
66+
}
67+
68+
/**
69+
* Global instance of auto debug telemetry
70+
*/
71+
export const autoDebugTelemetry: AutoDebugTelemetry = new AutoDebugTelemetryImpl()

packages/core/src/shared/telemetry/vscodeTelemetry.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,23 @@
239239
"type": "int",
240240
"description": "The number of executed operations"
241241
},
242+
{
243+
"name": "amazonqAutoDebugCommandType",
244+
"type": "string",
245+
"allowedValues": ["fixWithQ", "fixAllWithQ", "explainProblem"],
246+
"description": "The type of auto debug command executed"
247+
},
248+
{
249+
"name": "amazonqAutoDebugAction",
250+
"type": "string",
251+
"allowedValues": ["invoked", "completed"],
252+
"description": "The action performed (invoked or completed)"
253+
},
254+
{
255+
"name": "amazonqAutoDebugProblemCount",
256+
"type": "int",
257+
"description": "Number of problems being processed"
258+
},
242259
{
243260
"name": "smusDomainId",
244261
"type": "string",
@@ -1306,6 +1323,35 @@
13061323
}
13071324
]
13081325
},
1326+
{
1327+
"name": "amazonq_autoDebugCommand",
1328+
"description": "Tracks usage of Amazon Q auto debug commands (fixWithQ, fixAllWithQ, explainProblem)",
1329+
"metadata": [
1330+
{
1331+
"type": "amazonqAutoDebugCommandType",
1332+
"required": true
1333+
},
1334+
{
1335+
"type": "amazonqAutoDebugAction",
1336+
"required": true
1337+
},
1338+
{
1339+
"type": "amazonqAutoDebugProblemCount",
1340+
"required": false
1341+
},
1342+
{
1343+
"type": "result"
1344+
},
1345+
{
1346+
"type": "reason",
1347+
"required": false
1348+
},
1349+
{
1350+
"type": "reasonDesc",
1351+
"required": false
1352+
}
1353+
]
1354+
},
13091355
{
13101356
"name": "smus_login",
13111357
"description": "Emitted whenever a user signin to SMUS",

0 commit comments

Comments
 (0)