From 90fafb3a25e79e23d5883b9a0172062558a32ac6 Mon Sep 17 00:00:00 2001 From: Yaofu Zuo Date: Wed, 26 Mar 2025 01:50:36 -0700 Subject: [PATCH 1/2] telemetry(amazonq): Add id2 and additional logging for createUpload metrics --- .../codescan/CodeWhispererCodeScanException.kt | 4 +++- .../util/CodeWhispererZipUploadManager.kt | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanException.kt b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanException.kt index a50aac1a773..2146ed80ff0 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanException.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanException.kt @@ -12,6 +12,7 @@ open class CodeWhispererCodeFixException(override val message: String?) : Runtim open class CodeWhispererCodeScanServerException( override val message: String?, val requestId: String?, + val id2: String?, val requestServiceType: String?, val httpStatusCode: String?, ) : RuntimeException() @@ -37,9 +38,10 @@ internal fun fileTooLarge(): Nothing = internal fun codeScanServerException( errorMessage: String, requestId: String? = null, + id2: String? = null, requestServiceType: String? = null, httpStatusCode: String? = null, -): Nothing = throw CodeWhispererCodeScanServerException(errorMessage, requestId, requestServiceType, httpStatusCode) +): Nothing = throw CodeWhispererCodeScanServerException(errorMessage, requestId, id2, requestServiceType, httpStatusCode) internal fun invalidSourceZipError(): Nothing = throw CodeWhispererCodeScanException(message("codewhisperer.codescan.invalid_source_zip_telemetry")) diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererZipUploadManager.kt b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererZipUploadManager.kt index 8d997645a14..d3aa2e2530a 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererZipUploadManager.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererZipUploadManager.kt @@ -63,6 +63,7 @@ class CodeWhispererZipUploadManager(private val project: Project) { var requestId: String? = null var requestServiceType: String? = null var httpStatusCode: String? = null + var id2: String? = null try { // Throw error if zipFile is invalid. if (!zipFile.exists()) { @@ -77,7 +78,7 @@ class CodeWhispererZipUploadManager(private val project: Project) { val url = createUploadUrlResponse.uploadUrl() LOG.debug { "$featureUseCase: Uploading $artifactType using the presigned URL." } - uploadArtifactToS3( + val connection = uploadArtifactToS3( url, createUploadUrlResponse.uploadId(), zipFile, @@ -86,6 +87,8 @@ class CodeWhispererZipUploadManager(private val project: Project) { createUploadUrlResponse.requestHeaders(), featureUseCase ) + requestId = connection?.getHeaderField("x-amz-request-id") + id2 = connection?.getHeaderField("x-amz-id-2") return createUploadUrlResponse } catch (e: Exception) { result = MetricResult.Failed @@ -95,10 +98,12 @@ class CodeWhispererZipUploadManager(private val project: Project) { requestId = e.requestId requestServiceType = e.requestServiceType httpStatusCode = e.httpStatusCode + id2 = e.id2 } throw e } finally { if (featureUseCase == CodeWhispererConstants.FeatureName.CODE_REVIEW) { + LOG.info("Upload to S3 details: x-amz-request-id: $requestId and x-amz-id-2: $id2") AmazonqTelemetry.createUpload( amazonqConversationId = "", amazonqUploadIntent = if (taskType == CodeWhispererConstants.UploadTaskType.SCAN_PROJECT) { @@ -112,6 +117,7 @@ class CodeWhispererZipUploadManager(private val project: Project) { duration = (System.currentTimeMillis() - startTime).toDouble(), credentialStartUrl = getStartUrl(project), requestId = requestId, + id2 = id2, requestServiceType = requestServiceType, httpStatusCode = httpStatusCode ) @@ -128,7 +134,7 @@ class CodeWhispererZipUploadManager(private val project: Project) { kmsArn: String?, requestHeaders: Map?, featureUseCase: CodeWhispererConstants.FeatureName, - ) { + ) : HttpURLConnection? { var connection: HttpURLConnection? = null RetryableOperation().execute( operation = { @@ -166,6 +172,7 @@ class CodeWhispererZipUploadManager(private val project: Project) { codeScanServerException( "CreateUploadUrlException: $errorMessage", connection?.getHeaderField("x-amz-request-id"), + connection?.getHeaderField("x-amz-id-2"), "s3", (e as? HttpRequests.HttpStatusException)?.statusCode.toString() ) @@ -179,6 +186,7 @@ class CodeWhispererZipUploadManager(private val project: Project) { } } ) + return connection } fun createUploadUrl( From 3b8fc307e23a71af7b41fd851ab7af7bef761e89 Mon Sep 17 00:00:00 2001 From: Yaofu Zuo Date: Wed, 26 Mar 2025 14:38:53 -0700 Subject: [PATCH 2/2] update packages and rename requestId2 --- gradle/libs.versions.toml | 2 +- .../codewhisperer/util/CodeWhispererZipUploadManager.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e017dce6fed..5497bc430c0 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -27,7 +27,7 @@ mockitoKotlin = "5.4.0" mockk = "1.13.17" nimbus-jose-jwt = "9.40" node-gradle = "7.0.2" -telemetryGenerator = "1.0.310" +telemetryGenerator = "1.0.312" testLogger = "4.0.0" testRetry = "1.5.10" # test-only; platform provides slf4j transitively at runtime diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererZipUploadManager.kt b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererZipUploadManager.kt index d3aa2e2530a..a2f8af25ca4 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererZipUploadManager.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererZipUploadManager.kt @@ -117,7 +117,7 @@ class CodeWhispererZipUploadManager(private val project: Project) { duration = (System.currentTimeMillis() - startTime).toDouble(), credentialStartUrl = getStartUrl(project), requestId = requestId, - id2 = id2, + requestId2 = id2, requestServiceType = requestServiceType, httpStatusCode = httpStatusCode )