Skip to content

Commit 90fafb3

Browse files
committed
telemetry(amazonq): Add id2 and additional logging for createUpload metrics
1 parent 42c1a99 commit 90fafb3

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanException.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ open class CodeWhispererCodeFixException(override val message: String?) : Runtim
1212
open class CodeWhispererCodeScanServerException(
1313
override val message: String?,
1414
val requestId: String?,
15+
val id2: String?,
1516
val requestServiceType: String?,
1617
val httpStatusCode: String?,
1718
) : RuntimeException()
@@ -37,9 +38,10 @@ internal fun fileTooLarge(): Nothing =
3738
internal fun codeScanServerException(
3839
errorMessage: String,
3940
requestId: String? = null,
41+
id2: String? = null,
4042
requestServiceType: String? = null,
4143
httpStatusCode: String? = null,
42-
): Nothing = throw CodeWhispererCodeScanServerException(errorMessage, requestId, requestServiceType, httpStatusCode)
44+
): Nothing = throw CodeWhispererCodeScanServerException(errorMessage, requestId, id2, requestServiceType, httpStatusCode)
4345

4446
internal fun invalidSourceZipError(): Nothing =
4547
throw CodeWhispererCodeScanException(message("codewhisperer.codescan.invalid_source_zip_telemetry"))

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererZipUploadManager.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class CodeWhispererZipUploadManager(private val project: Project) {
6363
var requestId: String? = null
6464
var requestServiceType: String? = null
6565
var httpStatusCode: String? = null
66+
var id2: String? = null
6667
try {
6768
// Throw error if zipFile is invalid.
6869
if (!zipFile.exists()) {
@@ -77,7 +78,7 @@ class CodeWhispererZipUploadManager(private val project: Project) {
7778
val url = createUploadUrlResponse.uploadUrl()
7879
LOG.debug { "$featureUseCase: Uploading $artifactType using the presigned URL." }
7980

80-
uploadArtifactToS3(
81+
val connection = uploadArtifactToS3(
8182
url,
8283
createUploadUrlResponse.uploadId(),
8384
zipFile,
@@ -86,6 +87,8 @@ class CodeWhispererZipUploadManager(private val project: Project) {
8687
createUploadUrlResponse.requestHeaders(),
8788
featureUseCase
8889
)
90+
requestId = connection?.getHeaderField("x-amz-request-id")
91+
id2 = connection?.getHeaderField("x-amz-id-2")
8992
return createUploadUrlResponse
9093
} catch (e: Exception) {
9194
result = MetricResult.Failed
@@ -95,10 +98,12 @@ class CodeWhispererZipUploadManager(private val project: Project) {
9598
requestId = e.requestId
9699
requestServiceType = e.requestServiceType
97100
httpStatusCode = e.httpStatusCode
101+
id2 = e.id2
98102
}
99103
throw e
100104
} finally {
101105
if (featureUseCase == CodeWhispererConstants.FeatureName.CODE_REVIEW) {
106+
LOG.info("Upload to S3 details: x-amz-request-id: $requestId and x-amz-id-2: $id2")
102107
AmazonqTelemetry.createUpload(
103108
amazonqConversationId = "",
104109
amazonqUploadIntent = if (taskType == CodeWhispererConstants.UploadTaskType.SCAN_PROJECT) {
@@ -112,6 +117,7 @@ class CodeWhispererZipUploadManager(private val project: Project) {
112117
duration = (System.currentTimeMillis() - startTime).toDouble(),
113118
credentialStartUrl = getStartUrl(project),
114119
requestId = requestId,
120+
id2 = id2,
115121
requestServiceType = requestServiceType,
116122
httpStatusCode = httpStatusCode
117123
)
@@ -128,7 +134,7 @@ class CodeWhispererZipUploadManager(private val project: Project) {
128134
kmsArn: String?,
129135
requestHeaders: Map<String, String>?,
130136
featureUseCase: CodeWhispererConstants.FeatureName,
131-
) {
137+
) : HttpURLConnection? {
132138
var connection: HttpURLConnection? = null
133139
RetryableOperation<Unit>().execute(
134140
operation = {
@@ -166,6 +172,7 @@ class CodeWhispererZipUploadManager(private val project: Project) {
166172
codeScanServerException(
167173
"CreateUploadUrlException: $errorMessage",
168174
connection?.getHeaderField("x-amz-request-id"),
175+
connection?.getHeaderField("x-amz-id-2"),
169176
"s3",
170177
(e as? HttpRequests.HttpStatusException)?.statusCode.toString()
171178
)
@@ -179,6 +186,7 @@ class CodeWhispererZipUploadManager(private val project: Project) {
179186
}
180187
}
181188
)
189+
return connection
182190
}
183191

184192
fun createUploadUrl(

0 commit comments

Comments
 (0)