Skip to content

Commit e835b6c

Browse files
authored
telemetry(amazonq): TransformEvent metric on download ZIP #5905
## Problem Need some more metrics emitted to capture lines of code submitted, lines of code changed, and characters of code changed. ## Solution Emit said metrics after parsing them from the download ZIP.
1 parent 16e8a77 commit e835b6c

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

packages/core/src/codewhisperer/models/model.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ export class TransformByQState {
413413

414414
private metadataPathSQL: string = ''
415415

416+
private linesOfCodeSubmitted: number | undefined = undefined
417+
416418
private planFilePath: string = ''
417419
private summaryFilePath: string = ''
418420
private preBuildLogFilePath: string = ''
@@ -485,6 +487,10 @@ export class TransformByQState {
485487
return this.customBuildCommand
486488
}
487489

490+
public getLinesOfCodeSubmitted() {
491+
return this.linesOfCodeSubmitted
492+
}
493+
488494
public getPreBuildLogFilePath() {
489495
return this.preBuildLogFilePath
490496
}
@@ -645,6 +651,10 @@ export class TransformByQState {
645651
this.customBuildCommand = command
646652
}
647653

654+
public setLinesOfCodeSubmitted(lines: number) {
655+
this.linesOfCodeSubmitted = lines
656+
}
657+
648658
public setStartTime(time: string) {
649659
this.startTime = time
650660
}

packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ export async function getTransformationPlan(jobId: string) {
573573
const linesOfCode = Number(
574574
jobStatistics.find((stat: { name: string; value: string }) => stat.name === 'linesOfCode').value
575575
)
576+
transformByQState.setLinesOfCodeSubmitted(linesOfCode)
576577
if (authType === 'iamIdentityCenter' && linesOfCode > CodeWhispererConstants.codeTransformLocThreshold) {
577578
plan += CodeWhispererConstants.codeTransformBillingText(linesOfCode)
578579
}

packages/core/src/codewhisperer/service/transformByQ/transformationResultsViewProvider.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { parsePatch, applyPatches, ParsedDiff } from 'diff'
1010
import path from 'path'
1111
import vscode from 'vscode'
1212
import { ExportIntent } from '@amzn/codewhisperer-streaming'
13-
import { TransformByQReviewStatus, transformByQState } from '../../models/model'
13+
import { TransformationType, TransformByQReviewStatus, transformByQState } from '../../models/model'
1414
import { ExportResultArchiveStructure, downloadExportResultArchive } from '../../../shared/utilities/download'
1515
import { getLogger } from '../../../shared/logger'
1616
import { telemetry } from '../../../shared/telemetry/telemetry'
@@ -20,6 +20,7 @@ import * as CodeWhispererConstants from '../../models/constants'
2020
import { createCodeWhispererChatStreamingClient } from '../../../shared/clients/codewhispererChatClient'
2121
import { ChatSessionManager } from '../../../amazonqGumby/chat/storages/chatSession'
2222
import { setContext } from '../../../shared/vscode/setContext'
23+
import * as codeWhisperer from '../../client/codewhisperer'
2324

2425
export abstract class ProposedChangeNode {
2526
abstract readonly resourcePath: string
@@ -402,6 +403,33 @@ export class ProposedTransformationExplorer {
402403
`${CodeWhispererConstants.errorDeserializingDiffNotification} ${deserializeErrorMessage}`
403404
)
404405
}
406+
407+
try {
408+
const metricsPath = path.join(pathContainingArchive, ExportResultArchiveStructure.PathToMetrics)
409+
const metricsData = JSON.parse(fs.readFileSync(metricsPath, 'utf8'))
410+
411+
await codeWhisperer.codeWhispererClient.sendTelemetryEvent({
412+
telemetryEvent: {
413+
transformEvent: {
414+
jobId: transformByQState.getJobId(),
415+
timestamp: new Date(),
416+
ideCategory: 'VSCODE',
417+
programmingLanguage: {
418+
languageName:
419+
transformByQState.getTransformationType() === TransformationType.LANGUAGE_UPGRADE
420+
? 'JAVA'
421+
: 'SQL',
422+
},
423+
linesOfCodeChanged: metricsData.linesOfCodeChanged,
424+
charsOfCodeChanged: metricsData.charactersOfCodeChanged,
425+
linesOfCodeSubmitted: transformByQState.getLinesOfCodeSubmitted(), // currently unavailable for SQL conversions
426+
},
427+
},
428+
})
429+
} catch (err: any) {
430+
// log error, but continue to show user diff.patch with results
431+
getLogger().error(`CodeTransformation: SendTelemetryEvent error = ${err.message}`)
432+
}
405433
})
406434

407435
vscode.commands.registerCommand('aws.amazonq.transformationHub.reviewChanges.acceptChanges', async () => {

packages/core/src/shared/utilities/download.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import path from 'path'
76
import { CodeWhispererStreaming, ExportResultArchiveCommandInput } from '@amzn/codewhisperer-streaming'
87
import { ToolkitError } from '../errors'
98
import fs from '../fs/fs'
@@ -12,8 +11,9 @@ import fs from '../fs/fs'
1211
* This class represents the structure of the archive returned by the ExportResultArchive endpoint
1312
*/
1413
export class ExportResultArchiveStructure {
15-
static readonly PathToSummary = path.join('summary', 'summary.md')
16-
static readonly PathToDiffPatch = path.join('patch', 'diff.patch')
14+
static readonly PathToSummary = 'summary/summary.md'
15+
static readonly PathToDiffPatch = 'patch/diff.patch'
16+
static readonly PathToMetrics = 'metrics/metrics.json'
1717
static readonly PathToManifest = 'manifest.json'
1818
}
1919

0 commit comments

Comments
 (0)