Skip to content

telemetry(amazonq): Add id2 and logging for createUpload metrics #5512

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,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()) {
Expand All @@ -78,7 +79,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,
Expand All @@ -87,6 +88,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
Expand All @@ -96,10 +99,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) {
Expand All @@ -113,6 +118,7 @@ class CodeWhispererZipUploadManager(private val project: Project) {
duration = (System.currentTimeMillis() - startTime).toDouble(),
credentialStartUrl = getStartUrl(project),
requestId = requestId,
requestId2 = id2,
requestServiceType = requestServiceType,
httpStatusCode = httpStatusCode
)
Expand All @@ -129,7 +135,7 @@ class CodeWhispererZipUploadManager(private val project: Project) {
kmsArn: String?,
requestHeaders: Map<String, String>?,
featureUseCase: CodeWhispererConstants.FeatureName,
) {
) : HttpURLConnection? {
var connection: HttpURLConnection? = null
RetryableOperation<Unit>().execute(
operation = {
Expand Down Expand Up @@ -167,6 +173,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()
)
Expand All @@ -180,6 +187,7 @@ class CodeWhispererZipUploadManager(private val project: Project) {
}
}
)
return connection
}

fun createUploadUrl(
Expand Down
Loading