Skip to content

Commit 978b1f8

Browse files
authored
telemetry(amazonq): add raw accepted token count to code percentage (#5460)
1 parent 1105519 commit 978b1f8

File tree

5 files changed

+10
-122
lines changed

5 files changed

+10
-122
lines changed

package-lock.json

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"generateNonCodeFiles": "npm run generateNonCodeFiles -w packages/ --if-present"
4040
},
4141
"devDependencies": {
42-
"@aws-toolkits/telemetry": "^1.0.239",
42+
"@aws-toolkits/telemetry": "^1.0.240",
4343
"@playwright/browser-chromium": "^1.43.1",
4444
"@types/vscode": "^1.68.0",
4545
"@types/vscode-webview": "^1.57.1",

packages/amazonq/test/unit/codewhisperer/tracker/codewhispererCodeCoverageTracker.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ describe('codewhispererCodecoverageTracker', function () {
538538
codewhispererTotalTokens: 100,
539539
codewhispererLanguage: language,
540540
codewhispererAcceptedTokens: 7,
541+
codewhispererSuggestedTokens: 7,
541542
codewhispererPercentage: 7,
542543
successCount: 1,
543544
codewhispererUserGroup: 'Control',
@@ -566,6 +567,7 @@ describe('codewhispererCodecoverageTracker', function () {
566567
codewhispererTotalTokens: 30,
567568
codewhispererLanguage: 'java',
568569
codewhispererAcceptedTokens: 18,
570+
codewhispererSuggestedTokens: 18,
569571
codewhispererPercentage: 60,
570572
successCount: 2,
571573
codewhispererUserGroup: 'Control',

packages/core/src/codewhisperer/tracker/codewhispererCodeCoverageTracker.ts

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,6 @@ interface CodeWhispererToken {
2424
accepted: number
2525
}
2626

27-
interface UserInputDetail {
28-
count: number
29-
total: number
30-
}
31-
32-
interface UserInputDetails {
33-
lt1: UserInputDetail
34-
lt50: UserInputDetail
35-
lt100: UserInputDetail
36-
lt200: UserInputDetail
37-
lt300: UserInputDetail
38-
lt400: UserInputDetail
39-
lt500: UserInputDetail
40-
lt1000: UserInputDetail
41-
gt1000: UserInputDetail
42-
}
43-
4427
const autoClosingKeystrokeInputs = ['[]', '{}', '()', '""', "''"]
4528

4629
/**
@@ -54,25 +37,12 @@ export class CodeWhispererCodeCoverageTracker {
5437
private _language: CodewhispererLanguage
5538
private _serviceInvocationCount: number
5639

57-
private _userInputDetails: UserInputDetails
58-
5940
private constructor(language: CodewhispererLanguage) {
6041
this._acceptedTokens = {}
6142
this._totalTokens = {}
6243
this._startTime = 0
6344
this._language = language
6445
this._serviceInvocationCount = 0
65-
this._userInputDetails = {
66-
lt1: { count: 0, total: 0 },
67-
lt50: { count: 0, total: 0 },
68-
lt100: { count: 0, total: 0 },
69-
lt200: { count: 0, total: 0 },
70-
lt300: { count: 0, total: 0 },
71-
lt400: { count: 0, total: 0 },
72-
lt500: { count: 0, total: 0 },
73-
lt1000: { count: 0, total: 0 },
74-
gt1000: { count: 0, total: 0 },
75-
}
7646
}
7747

7848
public get serviceInvocationCount(): number {
@@ -150,7 +120,7 @@ export class CodeWhispererCodeCoverageTracker {
150120
}
151121
})
152122
}
153-
const percentCount = ((acceptedTokens / totalTokens) * 100).toFixed(2)
123+
const percentCount = ((unmodifiedAcceptedTokens / totalTokens) * 100).toFixed(2)
154124
const percentage = Math.round(parseInt(percentCount))
155125
const selectedCustomization = getSelectedCustomization()
156126
if (this._serviceInvocationCount <= 0) {
@@ -160,13 +130,13 @@ export class CodeWhispererCodeCoverageTracker {
160130
telemetry.codewhisperer_codePercentage.emit({
161131
codewhispererTotalTokens: totalTokens,
162132
codewhispererLanguage: this._language,
163-
codewhispererAcceptedTokens: acceptedTokens,
133+
codewhispererAcceptedTokens: unmodifiedAcceptedTokens,
134+
codewhispererSuggestedTokens: acceptedTokens,
164135
codewhispererPercentage: percentage ? percentage : 0,
165136
successCount: this._serviceInvocationCount,
166137
codewhispererUserGroup: CodeWhispererUserGroupSettings.getUserGroup().toString(),
167138
codewhispererCustomizationArn: selectedCustomization.arn === '' ? undefined : selectedCustomization.arn,
168139
credentialStartUrl: AuthUtil.instance.startUrl,
169-
codewhispererUserInputDetails: JSON.stringify(this._userInputDetails),
170140
})
171141

172142
client
@@ -237,17 +207,6 @@ export class CodeWhispererCodeCoverageTracker {
237207
this._acceptedTokens = {}
238208
this._startTime = 0
239209
this._serviceInvocationCount = 0
240-
this._userInputDetails = {
241-
lt1: { count: 0, total: 0 },
242-
lt50: { count: 0, total: 0 },
243-
lt100: { count: 0, total: 0 },
244-
lt200: { count: 0, total: 0 },
245-
lt300: { count: 0, total: 0 },
246-
lt400: { count: 0, total: 0 },
247-
lt500: { count: 0, total: 0 },
248-
lt1000: { count: 0, total: 0 },
249-
gt1000: { count: 0, total: 0 },
250-
}
251210
}
252211

253212
private closeTimer() {
@@ -329,14 +288,10 @@ export class CodeWhispererCodeCoverageTracker {
329288
if (this.isFromUserKeystroke(e)) {
330289
this.tryStartTimer()
331290
this.addTotalTokens(e.document.fileName, 1)
332-
this._userInputDetails.lt1.count += 1
333-
this._userInputDetails.lt1.total += 1
334291
} else if (this.getCharacterCountFromComplexEvent(e) !== 0) {
335292
this.tryStartTimer()
336293
const characterIncrease = this.getCharacterCountFromComplexEvent(e)
337294
this.addTotalTokens(e.document.fileName, characterIncrease)
338-
this._userInputDetails.lt1.count += 1
339-
this._userInputDetails.lt1.total += characterIncrease
340295
}
341296
// also include multi character input within 50 characters (not from CWSPR)
342297
else if (
@@ -351,33 +306,6 @@ export class CodeWhispererCodeCoverageTracker {
351306
if (multiCharInputSize < 50 && e.contentChanges[0].text.trim().length > 0) {
352307
this.addTotalTokens(e.document.fileName, multiCharInputSize)
353308
}
354-
355-
// report multiple user input patterns for adjusting the threshold
356-
if (multiCharInputSize < 50) {
357-
this._userInputDetails.lt50.total += multiCharInputSize
358-
this._userInputDetails.lt50.count += 1
359-
} else if (multiCharInputSize < 100) {
360-
this._userInputDetails.lt100.total += multiCharInputSize
361-
this._userInputDetails.lt100.count += 1
362-
} else if (multiCharInputSize < 200) {
363-
this._userInputDetails.lt200.total += multiCharInputSize
364-
this._userInputDetails.lt200.count += 1
365-
} else if (multiCharInputSize < 300) {
366-
this._userInputDetails.lt300.total += multiCharInputSize
367-
this._userInputDetails.lt300.count += 1
368-
} else if (multiCharInputSize < 400) {
369-
this._userInputDetails.lt400.total += multiCharInputSize
370-
this._userInputDetails.lt400.count += 1
371-
} else if (multiCharInputSize < 500) {
372-
this._userInputDetails.lt500.total += multiCharInputSize
373-
this._userInputDetails.lt500.count += 1
374-
} else if (multiCharInputSize < 1000) {
375-
this._userInputDetails.lt1000.total += multiCharInputSize
376-
this._userInputDetails.lt1000.count += 1
377-
} else {
378-
this._userInputDetails.gt1000.total += multiCharInputSize
379-
this._userInputDetails.gt1000.count += 1
380-
}
381309
}
382310
}
383311

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

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,47 +1073,6 @@
10731073
}
10741074
]
10751075
},
1076-
{
1077-
"name": "codewhisperer_codePercentage",
1078-
"description": "Percentage of user tokens against suggestions until 5 mins of time",
1079-
"metadata": [
1080-
{
1081-
"type": "codewhispererAcceptedTokens"
1082-
},
1083-
{
1084-
"type": "codewhispererLanguage"
1085-
},
1086-
{
1087-
"type": "codewhispererPercentage"
1088-
},
1089-
{
1090-
"type": "codewhispererTotalTokens"
1091-
},
1092-
{
1093-
"type": "codewhispererUserInputDetails",
1094-
"required": false
1095-
},
1096-
{
1097-
"type": "codewhispererUserGroup"
1098-
},
1099-
{
1100-
"type": "reason",
1101-
"required": false
1102-
},
1103-
{
1104-
"type": "successCount"
1105-
},
1106-
{
1107-
"type": "codewhispererCustomizationArn",
1108-
"required": false
1109-
},
1110-
{
1111-
"type": "credentialStartUrl",
1112-
"required": false
1113-
}
1114-
],
1115-
"passive": true
1116-
},
11171076
{
11181077
"name": "auth_modifyConnection",
11191078
"description": "An auth connection was modified in some way, e.g. deleted, updated",

0 commit comments

Comments
 (0)