From 5073cc8575684156a53c1d6991d092229e4c84aa Mon Sep 17 00:00:00 2001 From: David <60020664+dhasani23@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:08:43 -0700 Subject: [PATCH] telemetry(amazonq): telemetry updates (#5522) ## Problem Need to update telemetry to reflect that we are no longer emitting a metric for API errors or latency, and to reflect the latest common telemetry updates. ## Solution Update telemetry as described. --- License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: David Hasani --- package-lock.json | 8 +- package.json | 2 +- .../commands/startTransformByQ.ts | 2 +- .../transformByQ/transformApiHandler.ts | 80 ------------------- .../transformProjectValidationHandler.ts | 2 +- .../core/src/shared/utilities/download.ts | 16 ---- 6 files changed, 7 insertions(+), 103 deletions(-) diff --git a/package-lock.json b/package-lock.json index 25d8788a69f..b9808400ef7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "vscode-nls-dev": "^4.0.4" }, "devDependencies": { - "@aws-toolkits/telemetry": "^1.0.247", + "@aws-toolkits/telemetry": "^1.0.250", "@playwright/browser-chromium": "^1.43.1", "@types/vscode": "^1.68.0", "@types/vscode-webview": "^1.57.1", @@ -5792,9 +5792,9 @@ } }, "node_modules/@aws-toolkits/telemetry": { - "version": "1.0.247", - "resolved": "https://registry.npmjs.org/@aws-toolkits/telemetry/-/telemetry-1.0.247.tgz", - "integrity": "sha512-jL0S3lnouiNfyYorOHQHZyJ6Uk+Ed1Vtes9294IOksIb8pWB4ATd+XnAsFjddDIM4d8DtqFBp3tbxyznQgIGAQ==", + "version": "1.0.250", + "resolved": "https://registry.npmjs.org/@aws-toolkits/telemetry/-/telemetry-1.0.250.tgz", + "integrity": "sha512-ElP5C0uHAmj6Y3khT2HgQofmHBrkJ+r0hcI1mA8n6X4Ob85jdoavJYKdmhynUUj7vjp1PWv2UceYOMNpJe4wzQ==", "dev": true, "dependencies": { "ajv": "^6.12.6", diff --git a/package.json b/package.json index db412cb0dc2..22b8ccfedc1 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "generateNonCodeFiles": "npm run generateNonCodeFiles -w packages/ --if-present" }, "devDependencies": { - "@aws-toolkits/telemetry": "^1.0.247", + "@aws-toolkits/telemetry": "^1.0.250", "@playwright/browser-chromium": "^1.43.1", "@types/vscode": "^1.68.0", "@types/vscode-webview": "^1.57.1", diff --git a/packages/core/src/codewhisperer/commands/startTransformByQ.ts b/packages/core/src/codewhisperer/commands/startTransformByQ.ts index 8e38d90bb71..91a16691d5f 100644 --- a/packages/core/src/codewhisperer/commands/startTransformByQ.ts +++ b/packages/core/src/codewhisperer/commands/startTransformByQ.ts @@ -123,7 +123,7 @@ async function validateJavaHome(): Promise { // TODO: remove deprecated metric once BI started using new metrics telemetry.codeTransform_isDoubleClickedToTriggerInvalidProject.emit({ codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(), - codeTransformPreValidationError: 'ProjectJDKDiffersFromMavenJDK', + codeTransformPreValidationError: 'ProjectJDKDiffersFromBuildSystemJDK', result: MetadataResult.Fail, reason: `${transformByQState.getSourceJDKVersion()} (project) - ${javaVersionUsedByMaven} (maven)`, }) diff --git a/packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts b/packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts index 63df659d3a1..d6640822518 100644 --- a/packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts +++ b/packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts @@ -118,20 +118,10 @@ export async function uploadArtifactToS3( Math.round(uploadFileByteSize / 1000) ) - const apiStartTime = globals.clock.Date.now() const response = await request.fetch('PUT', resp.uploadUrl, { body: buffer, headers: getHeadersObj(sha256, resp.kmsKeyArn), }).response - // TODO: remove deprecated metric once BI started using new metrics - telemetry.codeTransform_logApiLatency.emit({ - codeTransformApiNames: 'UploadZip', - codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(), - codeTransformUploadId: resp.uploadId, - codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime), - codeTransformTotalByteSize: uploadFileByteSize, - result: MetadataResult.Pass, - }) getLogger().info(`CodeTransformation: Status from S3 Upload = ${response.status}`) } catch (e: any) { let errorMessage = `The upload failed due to: ${(e as Error).message}. For more information, see the [Amazon Q documentation](${CodeWhispererConstants.codeTransformTroubleshootUploadError})` @@ -149,21 +139,11 @@ export async function uploadArtifactToS3( export async function resumeTransformationJob(jobId: string, userActionStatus: TransformationUserActionStatus) { try { - const apiStartTime = globals.clock.Date.now() const response = await codeWhisperer.codeWhispererClient.codeModernizerResumeTransformation({ transformationJobId: jobId, userActionStatus, // can be "COMPLETED" or "REJECTED" }) if (response) { - // TODO: remove deprecated metric once BI started using new metrics - telemetry.codeTransform_logApiLatency.emit({ - codeTransformApiNames: 'ResumeTransformation', - codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(), - codeTransformJobId: jobId, - codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime), - codeTransformRequestId: response.$response.requestId, - result: MetadataResult.Pass, - }) // always store request ID, but it will only show up in a notification if an error occurs return response.transformationStatus } @@ -180,20 +160,10 @@ export async function stopJob(jobId: string) { } try { - const apiStartTime = globals.clock.Date.now() const response = await codeWhisperer.codeWhispererClient.codeModernizerStopCodeTransformation({ transformationJobId: jobId, }) if (response !== undefined) { - // TODO: remove deprecated metric once BI started using new metrics - telemetry.codeTransform_logApiLatency.emit({ - codeTransformApiNames: 'StopTransformation', - codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(), - codeTransformJobId: jobId, - codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime), - codeTransformRequestId: response.$response.requestId, - result: MetadataResult.Pass, - }) // always store request ID, but it will only show up in a notification if an error occurs if (response.$response.requestId) { transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`) @@ -213,7 +183,6 @@ export async function uploadPayload(payloadFileName: string, uploadContext?: Upl throwIfCancelled() let response = undefined try { - const apiStartTime = globals.clock.Date.now() response = await codeWhisperer.codeWhispererClient.createUploadUrl({ contentChecksum: sha256, contentChecksumType: CodeWhispererConstants.contentChecksumType, @@ -223,15 +192,6 @@ export async function uploadPayload(payloadFileName: string, uploadContext?: Upl if (response.$response.requestId) { transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`) } - // TODO: remove deprecated metric once BI started using new metrics - telemetry.codeTransform_logApiLatency.emit({ - codeTransformApiNames: 'CreateUploadUrl', - codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(), - codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime), - codeTransformUploadId: response.uploadId, - codeTransformRequestId: response.$response.requestId, - result: MetadataResult.Pass, - }) } catch (e: any) { const errorMessage = `The upload failed due to: ${(e as Error).message}` getLogger().error(`CodeTransformation: CreateUploadUrl error: = ${e}`) @@ -446,7 +406,6 @@ export async function startJob(uploadId: string) { const sourceLanguageVersion = `JAVA_${transformByQState.getSourceJDKVersion()}` const targetLanguageVersion = `JAVA_${transformByQState.getTargetJDKVersion()}` try { - const apiStartTime = globals.clock.Date.now() const response = await codeWhisperer.codeWhispererClient.codeModernizerStartCodeTransformation({ workspaceState: { uploadId: uploadId, @@ -461,15 +420,6 @@ export async function startJob(uploadId: string) { if (response.$response.requestId) { transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`) } - // TODO: remove deprecated metric once BI started using new metrics - telemetry.codeTransform_logApiLatency.emit({ - codeTransformApiNames: 'StartTransformation', - codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(), - codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime), - codeTransformJobId: response.transformationJobId, - codeTransformRequestId: response.$response.requestId, - result: MetadataResult.Pass, - }) return response.transformationJobId } catch (e: any) { const errorMessage = `Starting the job failed due to: ${(e as Error).message}` @@ -586,19 +536,9 @@ export async function getTransformationPlan(jobId: string) { response = await codeWhisperer.codeWhispererClient.codeModernizerGetCodeTransformationPlan({ transformationJobId: jobId, }) - const apiStartTime = globals.clock.Date.now() if (response.$response.requestId) { transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`) } - // TODO: remove deprecated metric once BI started using new metrics - telemetry.codeTransform_logApiLatency.emit({ - codeTransformApiNames: 'GetTransformationPlan', - codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(), - codeTransformJobId: jobId, - codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime), - codeTransformRequestId: response.$response.requestId, - result: MetadataResult.Pass, - }) const stepZeroProgressUpdates = response.transformationPlan.transformationSteps[0].progressUpdates @@ -657,22 +597,12 @@ export async function getTransformationSteps(jobId: string, handleThrottleFlag: if (handleThrottleFlag) { await sleep(2000) } - const apiStartTime = globals.clock.Date.now() const response = await codeWhisperer.codeWhispererClient.codeModernizerGetCodeTransformationPlan({ transformationJobId: jobId, }) if (response.$response.requestId) { transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`) } - // TODO: remove deprecated metric once BI started using new metrics - telemetry.codeTransform_logApiLatency.emit({ - codeTransformApiNames: 'GetTransformationPlan', - codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(), - codeTransformJobId: jobId, - codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime), - codeTransformRequestId: response.$response.requestId, - result: MetadataResult.Pass, - }) return response.transformationPlan.transformationSteps.slice(1) // skip step 0 (contains supplemental info) } catch (e: any) { const errorMessage = (e as Error).message @@ -687,19 +617,9 @@ export async function pollTransformationJob(jobId: string, validStates: string[] while (true) { throwIfCancelled() try { - const apiStartTime = globals.clock.Date.now() const response = await codeWhisperer.codeWhispererClient.codeModernizerGetCodeTransformation({ transformationJobId: jobId, }) - // TODO: remove deprecated metric once BI started using new metrics - telemetry.codeTransform_logApiLatency.emit({ - codeTransformApiNames: 'GetTransformation', - codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(), - codeTransformJobId: jobId, - codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime), - codeTransformRequestId: response.$response.requestId, - result: MetadataResult.Pass, - }) status = response.transformationJob.status! if (CodeWhispererConstants.validStatesForBuildSucceeded.includes(status)) { jobPlanProgress['buildCode'] = StepProgress.Succeeded diff --git a/packages/core/src/codewhisperer/service/transformByQ/transformProjectValidationHandler.ts b/packages/core/src/codewhisperer/service/transformByQ/transformProjectValidationHandler.ts index 7675ff62a74..5e932a84828 100644 --- a/packages/core/src/codewhisperer/service/transformByQ/transformProjectValidationHandler.ts +++ b/packages/core/src/codewhisperer/service/transformByQ/transformProjectValidationHandler.ts @@ -170,7 +170,7 @@ export async function validateOpenProjects( // TODO: remove deprecated metric once BI started using new metrics telemetry.codeTransform_isDoubleClickedToTriggerInvalidProject.emit({ codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(), - codeTransformPreValidationError: 'NonMavenProject', + codeTransformPreValidationError: 'UnsupportedBuildSystem', result: MetadataResult.Fail, reason: 'NoPomFileFound', }) diff --git a/packages/core/src/shared/utilities/download.ts b/packages/core/src/shared/utilities/download.ts index ce719da4bf1..8c9f5479ac0 100644 --- a/packages/core/src/shared/utilities/download.ts +++ b/packages/core/src/shared/utilities/download.ts @@ -6,12 +6,7 @@ import path from 'path' import { CodeWhispererStreaming, ExportResultArchiveCommandInput } from '@amzn/codewhisperer-streaming' import { ToolkitError } from '../errors' -import { CodeTransformTelemetryState } from '../../amazonqGumby/telemetry/codeTransformTelemetryState' -import { transformByQState } from '../../codewhisperer/models/model' -import { calculateTotalLatency } from '../../amazonqGumby/telemetry/codeTransformTelemetry' -import { telemetry } from '../telemetry/telemetry' import fs from '../fs/fs' -import globals from '../../shared/extensionGlobals' /** * This class represents the structure of the archive returned by the ExportResultArchive endpoint @@ -27,8 +22,6 @@ export async function downloadExportResultArchive( exportResultArchiveArgs: ExportResultArchiveCommandInput, toPath: string ) { - const apiStartTime = globals.clock.Date.now() - let totalDownloadBytes = 0 const result = await cwStreamingClient.exportResultArchive(exportResultArchiveArgs) const buffer = [] @@ -42,18 +35,9 @@ export async function downloadExportResultArchive( const chunkData = chunk.binaryPayloadEvent if (chunkData.bytes) { buffer.push(chunkData.bytes) - totalDownloadBytes += chunkData.bytes?.length } } } await fs.writeFile(toPath, Buffer.concat(buffer)) - telemetry.codeTransform_logApiLatency.emit({ - codeTransformApiNames: 'ExportResultArchive', - codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(), - codeTransformJobId: transformByQState.getJobId(), - codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime), - codeTransformTotalByteSize: totalDownloadBytes, - codeTransformRequestId: result.$metadata.requestId, - }) }