Skip to content

Commit 75d2777

Browse files
committed
add telemetry support for auto debug
1 parent ac1e682 commit 75d2777

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,13 +102,17 @@ 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()
97111
if (!editor) {
98112
return
99113
}
100114
await this.controller.fixSpecificProblems(range, diagnostics)
115+
autoDebugTelemetry.recordCommandSuccess('fixWithQ', problemCount)
101116
},
102117
'Fix with Amazon Q',
103118
'fixWithAmazonQ'
@@ -108,13 +123,16 @@ export class AutoDebugCommands implements vscode.Disposable {
108123
* Fix All with Amazon Q - processes all errors in the current file
109124
*/
110125
private async fixAllWithAmazonQ(): Promise<void> {
126+
autoDebugTelemetry.recordCommandInvocation('fixAllWithQ')
127+
111128
await this.executeWithErrorHandling(
112129
async () => {
113130
const editor = this.checkActiveEditor()
114131
if (!editor) {
115132
return
116133
}
117-
await this.controller.fixAllProblemsInFile(10) // 10 errors per batch
134+
const problemCount = await this.controller.fixAllProblemsInFile(10) // 10 errors per batch
135+
autoDebugTelemetry.recordCommandSuccess('fixAllWithQ', problemCount)
118136
},
119137
'Fix All with Amazon Q',
120138
'fixAllWithAmazonQ'
@@ -125,13 +143,17 @@ export class AutoDebugCommands implements vscode.Disposable {
125143
* Explains the problem using Amazon Q
126144
*/
127145
private async explainProblem(range?: vscode.Range, diagnostics?: vscode.Diagnostic[]): Promise<void> {
146+
const problemCount = diagnostics?.length
147+
autoDebugTelemetry.recordCommandInvocation('explainProblem', problemCount)
148+
128149
await this.executeWithErrorHandling(
129150
async () => {
130151
const editor = this.checkActiveEditor()
131152
if (!editor) {
132153
return
133154
}
134155
await this.controller.explainProblems(range, diagnostics)
156+
autoDebugTelemetry.recordCommandSuccess('explainProblem', problemCount)
135157
},
136158
'Explain Problem',
137159
'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
@@ -238,6 +238,23 @@
238238
"name": "executedCount",
239239
"type": "int",
240240
"description": "The number of executed operations"
241+
},
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"
241258
}
242259
],
243260
"metrics": [
@@ -1257,6 +1274,35 @@
12571274
"required": false
12581275
}
12591276
]
1277+
},
1278+
{
1279+
"name": "amazonq_autoDebugCommand",
1280+
"description": "Tracks usage of Amazon Q auto debug commands (fixWithQ, fixAllWithQ, explainProblem)",
1281+
"metadata": [
1282+
{
1283+
"type": "amazonqAutoDebugCommandType",
1284+
"required": true
1285+
},
1286+
{
1287+
"type": "amazonqAutoDebugAction",
1288+
"required": true
1289+
},
1290+
{
1291+
"type": "amazonqAutoDebugProblemCount",
1292+
"required": false
1293+
},
1294+
{
1295+
"type": "result"
1296+
},
1297+
{
1298+
"type": "reason",
1299+
"required": false
1300+
},
1301+
{
1302+
"type": "reasonDesc",
1303+
"required": false
1304+
}
1305+
]
12601306
}
12611307
]
12621308
}

0 commit comments

Comments
 (0)