Skip to content

Commit cf00781

Browse files
authored
telemetry(amazonq): emit metrics per finding (#6713)
## Problem Events about findings are always tied to hover, apply fix, etc. Not able to understand the number of findings which never get acted on. ## Solution Emit metrics about findings at the time of scan results. --- - 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.
1 parent a69638f commit cf00781

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

packages/core/src/codewhisperer/commands/startSecurityScan.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,19 @@ export async function startSecurityScan(
263263
scope,
264264
editor
265265
)
266+
for (const issue of securityRecommendationCollection
267+
.flatMap(({ issues }) => issues)
268+
.filter(({ visible, autoDetected }) => visible && !autoDetected)) {
269+
telemetry.codewhisperer_codeScanIssueDetected.emit({
270+
autoDetected: issue.autoDetected,
271+
codewhispererCodeScanJobId: issue.scanJobId,
272+
detectorId: issue.detectorId,
273+
findingId: issue.findingId,
274+
includesFix: issue.suggestedFixes.length > 0,
275+
ruleId: issue.ruleId,
276+
result: 'Succeeded',
277+
})
278+
}
266279
const { total, withFixes } = securityRecommendationCollection.reduce(
267280
(accumulator, current) => ({
268281
total: accumulator.total + current.issues.length,

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,34 @@
14851485
{
14861486
"name": "docdb_addRegion",
14871487
"description": "User clicked on add region command"
1488+
},
1489+
{
1490+
"name": "codewhisperer_codeScanIssueDetected",
1491+
"description": "Called when a code scan issue is returned from the service",
1492+
"metadata": [
1493+
{
1494+
"type": "autoDetected",
1495+
"required": false
1496+
},
1497+
{
1498+
"type": "codewhispererCodeScanJobId",
1499+
"required": false
1500+
},
1501+
{
1502+
"type": "detectorId"
1503+
},
1504+
{
1505+
"type": "findingId"
1506+
},
1507+
{
1508+
"type": "includesFix",
1509+
"required": false
1510+
},
1511+
{
1512+
"type": "ruleId",
1513+
"required": false
1514+
}
1515+
]
14881516
}
14891517
]
14901518
}

packages/core/src/test/codewhisperer/startSecurityScan.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ describe('startSecurityScan', function () {
232232
codewhispererCodeScanScope: 'PROJECT',
233233
passive: false,
234234
})
235+
assertTelemetry('codewhisperer_codeScanIssueDetected', {
236+
autoDetected: false,
237+
detectorId: 'detectorId',
238+
findingId: 'findingId',
239+
})
235240
})
236241

237242
it('Should cancel a scan if a newer one has started', async function () {

0 commit comments

Comments
 (0)