Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

telemetry(amazonq): emit TransformEvent metric from download ZIP #5905

Merged
merged 14 commits into from
Nov 13, 2024
10 changes: 10 additions & 0 deletions packages/core/src/codewhisperer/models/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ export class TransformByQState {

private metadataPathSQL: string = ''

private linesOfCodeSubmitted: number | undefined = undefined

private planFilePath: string = ''
private summaryFilePath: string = ''
private preBuildLogFilePath: string = ''
Expand Down Expand Up @@ -485,6 +487,10 @@ export class TransformByQState {
return this.customBuildCommand
}

public getLinesOfCodeSubmitted() {
return this.linesOfCodeSubmitted
}

public getPreBuildLogFilePath() {
return this.preBuildLogFilePath
}
Expand Down Expand Up @@ -645,6 +651,10 @@ export class TransformByQState {
this.customBuildCommand = command
}

public setLinesOfCodeSubmitted(lines: number) {
this.linesOfCodeSubmitted = lines
}

public setStartTime(time: string) {
this.startTime = time
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ export async function getTransformationPlan(jobId: string) {
const linesOfCode = Number(
jobStatistics.find((stat: { name: string; value: string }) => stat.name === 'linesOfCode').value
)
transformByQState.setLinesOfCodeSubmitted(linesOfCode)
if (authType === 'iamIdentityCenter' && linesOfCode > CodeWhispererConstants.codeTransformLocThreshold) {
plan += CodeWhispererConstants.codeTransformBillingText(linesOfCode)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { parsePatch, applyPatches, ParsedDiff } from 'diff'
import path from 'path'
import vscode from 'vscode'
import { ExportIntent } from '@amzn/codewhisperer-streaming'
import { TransformByQReviewStatus, transformByQState } from '../../models/model'
import { TransformationType, TransformByQReviewStatus, transformByQState } from '../../models/model'
import { ExportResultArchiveStructure, downloadExportResultArchive } from '../../../shared/utilities/download'
import { getLogger } from '../../../shared/logger'
import { telemetry } from '../../../shared/telemetry/telemetry'
Expand All @@ -20,6 +20,8 @@ import * as CodeWhispererConstants from '../../models/constants'
import { createCodeWhispererChatStreamingClient } from '../../../shared/clients/codewhispererChatClient'
import { ChatSessionManager } from '../../../amazonqGumby/chat/storages/chatSession'
import { setContext } from '../../../shared/vscode/setContext'
import * as codeWhisperer from '../../client/codewhisperer'
import { getOperatingSystem } from '../../../shared/telemetry/util'

export abstract class ProposedChangeNode {
abstract readonly resourcePath: string
Expand Down Expand Up @@ -402,6 +404,38 @@ export class ProposedTransformationExplorer {
`${CodeWhispererConstants.errorDeserializingDiffNotification} ${deserializeErrorMessage}`
)
}

try {
const metricsPath = path.join(pathContainingArchive, ExportResultArchiveStructure.PathToMetrics)
const metricsData = JSON.parse(fs.readFileSync(metricsPath, 'utf8'))

await codeWhisperer.codeWhispererClient.sendTelemetryEvent({
telemetryEvent: {
transformEvent: {
jobId: transformByQState.getJobId(),
timestamp: new Date(),
ideCategory: 'VSCODE',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any constant value we can extract this VSCODE value from? Same for JAVA and SQL below

Copy link
Contributor

@fangwade007 fangwade007 Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, do we have enum e.g. IdeCategory or constants represent IDE or get it from IDE env ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this no. All other uses in toolkit seem to use VSCODE just like this

programmingLanguage: {
languageName:
transformByQState.getTransformationType() === TransformationType.LANGUAGE_UPGRADE
? 'JAVA'
: 'SQL',
},
linesOfCodeChanged: metricsData.linesOfCodeChanged,
charsOfCodeChanged: metricsData.charactersOfCodeChanged,
linesOfCodeSubmitted: transformByQState.getLinesOfCodeSubmitted(), // currently unavailable for SQL conversions
},
},
userContext: {
ideCategory: 'VSCODE',
operatingSystem: getOperatingSystem(),
product: 'CodeWhisperer',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be AmazonQ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that makes more sense

Copy link
Contributor Author

@dhasani23 dhasani23 Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, I shouldn't even be manually including this userContext here — it's already included in the request, so we should simply use that:

},
})
} catch (err: any) {
// log error, but continue to show user diff.patch with results
getLogger().error(`CodeTransformation: SendTelemetryEvent error = ${err.message}`)
}
})

vscode.commands.registerCommand('aws.amazonq.transformationHub.reviewChanges.acceptChanges', async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/shared/utilities/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

import path from 'path'
import { CodeWhispererStreaming, ExportResultArchiveCommandInput } from '@amzn/codewhisperer-streaming'
import { ToolkitError } from '../errors'
import fs from '../fs/fs'
Expand All @@ -12,8 +11,9 @@ import fs from '../fs/fs'
* This class represents the structure of the archive returned by the ExportResultArchive endpoint
*/
export class ExportResultArchiveStructure {
static readonly PathToSummary = path.join('summary', 'summary.md')
static readonly PathToDiffPatch = path.join('patch', 'diff.patch')
static readonly PathToSummary = 'summary/summary.md'
static readonly PathToDiffPatch = 'patch/diff.patch'
static readonly PathToMetrics = 'metrics/metrics.json'
static readonly PathToManifest = 'manifest.json'
}

Expand Down
Loading