diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b62ee23f411..b063d950fbe 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -25,7 +25,7 @@ mockitoKotlin = "5.4.0" mockk = "1.13.10" nimbus-jose-jwt = "9.40" node-gradle = "7.0.2" -telemetryGenerator = "1.0.259" +telemetryGenerator = "1.0.262" testLogger = "4.0.0" testRetry = "1.5.10" # test-only; platform provides slf4j transitively at runtime diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/controller/chat/telemetry/TelemetryHelper.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/controller/chat/telemetry/TelemetryHelper.kt index c49592bc9e1..3c9676a4407 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/controller/chat/telemetry/TelemetryHelper.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/controller/chat/telemetry/TelemetryHelper.kt @@ -102,18 +102,18 @@ class TelemetryHelper(private val context: AmazonQAppInitContext, private val se cwsprChatUserIntent = data.userIntent?.let { getTelemetryUserIntent(it) }, cwsprChatHasCodeSnippet = data.activeFileContext.focusAreaContext?.codeSelection?.isNotEmpty() ?: false, cwsprChatProgrammingLanguage = data.activeFileContext.fileContext?.fileLanguage, - cwsprChatActiveEditorTotalCharacters = data.activeFileContext.focusAreaContext?.codeSelection?.length, - cwsprChatActiveEditorImportCount = data.activeFileContext.focusAreaContext?.codeNames?.fullyQualifiedNames?.used?.size, - cwsprChatResponseCodeSnippetCount = numberOfCodeBlocks, - cwsprChatResponseCode = statusCode, - cwsprChatSourceLinkCount = response.relatedSuggestions?.size, + cwsprChatActiveEditorTotalCharacters = data.activeFileContext.focusAreaContext?.codeSelection?.length?.toLong(), + cwsprChatActiveEditorImportCount = data.activeFileContext.focusAreaContext?.codeNames?.fullyQualifiedNames?.used?.size?.toLong(), + cwsprChatResponseCodeSnippetCount = numberOfCodeBlocks.toLong(), + cwsprChatResponseCode = statusCode.toLong(), + cwsprChatSourceLinkCount = response.relatedSuggestions?.size?.toLong(), cwsprChatReferencesCount = 0, // TODO - cwsprChatFollowUpCount = response.followUps?.size, - cwsprChatTimeToFirstChunk = getResponseStreamTimeToFirstChunk(response.tabId).toInt(), + cwsprChatFollowUpCount = response.followUps?.size?.toLong(), + cwsprChatTimeToFirstChunk = getResponseStreamTimeToFirstChunk(response.tabId).toLong(), cwsprChatTimeBetweenChunks = "[${getResponseStreamTimeBetweenChunks(response.tabId).joinToString(",")}]", - cwsprChatFullResponseLatency = responseStreamTotalTime[response.tabId] ?: 0, - cwsprChatRequestLength = data.message.length, - cwsprChatResponseLength = responseLength, + cwsprChatFullResponseLatency = responseStreamTotalTime[response.tabId]?.toLong() ?: 0, + cwsprChatRequestLength = data.message.length.toLong(), + cwsprChatResponseLength = responseLength.toLong(), cwsprChatConversationType = CwsprChatConversationType.Chat, credentialStartUrl = getStartUrl(context.project), codewhispererCustomizationArn = data.customization?.arn, @@ -152,10 +152,10 @@ class TelemetryHelper(private val context: AmazonQAppInitContext, private val se cwsprChatUserIntent = data.userIntent?.let { getTelemetryUserIntent(it) }, cwsprChatHasCodeSnippet = data.activeFileContext.focusAreaContext?.codeSelection?.isNotEmpty() ?: false, cwsprChatProgrammingLanguage = data.activeFileContext.fileContext?.fileLanguage, - cwsprChatActiveEditorTotalCharacters = data.activeFileContext.focusAreaContext?.codeSelection?.length, - cwsprChatActiveEditorImportCount = data.activeFileContext.focusAreaContext?.codeNames?.fullyQualifiedNames?.used?.size, - cwsprChatResponseCode = responseCode, - cwsprChatRequestLength = data.message.length, + cwsprChatActiveEditorTotalCharacters = data.activeFileContext.focusAreaContext?.codeSelection?.length?.toLong(), + cwsprChatActiveEditorImportCount = data.activeFileContext.focusAreaContext?.codeNames?.fullyQualifiedNames?.used?.size?.toLong(), + cwsprChatResponseCode = responseCode.toLong(), + cwsprChatRequestLength = data.message.length.toLong(), cwsprChatConversationType = CwsprChatConversationType.Chat, credentialStartUrl = getStartUrl(context.project) ) @@ -211,12 +211,12 @@ class TelemetryHelper(private val context: AmazonQAppInitContext, private val se cwsprChatConversationId = getConversationId(message.tabId).orEmpty(), cwsprChatMessageId = message.messageId, cwsprChatInteractionType = CwsprChatInteractionType.CopySnippet, - cwsprChatAcceptedCharactersLength = message.code.length, + cwsprChatAcceptedCharactersLength = message.code.length.toLong(), cwsprChatInteractionTarget = message.insertionTargetType, cwsprChatHasReference = null, credentialStartUrl = getStartUrl(context.project), - cwsprChatCodeBlockIndex = message.codeBlockIndex, - cwsprChatTotalCodeBlocks = message.totalCodeBlocks, + cwsprChatCodeBlockIndex = message.codeBlockIndex?.toLong(), + cwsprChatTotalCodeBlocks = message.totalCodeBlocks?.toLong(), cwsprChatHasProjectContext = getMessageHasProjectContext(message.messageId) ) ChatInteractWithMessageEvent.builder().apply { @@ -234,13 +234,13 @@ class TelemetryHelper(private val context: AmazonQAppInitContext, private val se cwsprChatConversationId = getConversationId(message.tabId).orEmpty(), cwsprChatMessageId = message.messageId, cwsprChatInteractionType = CwsprChatInteractionType.InsertAtCursor, - cwsprChatAcceptedCharactersLength = message.code.length, - cwsprChatAcceptedNumberOfLines = message.code.lines().size, + cwsprChatAcceptedCharactersLength = message.code.length.toLong(), + cwsprChatAcceptedNumberOfLines = message.code.lines().size.toLong(), cwsprChatInteractionTarget = message.insertionTargetType, cwsprChatHasReference = null, credentialStartUrl = getStartUrl(context.project), - cwsprChatCodeBlockIndex = message.codeBlockIndex, - cwsprChatTotalCodeBlocks = message.totalCodeBlocks, + cwsprChatCodeBlockIndex = message.codeBlockIndex?.toLong(), + cwsprChatTotalCodeBlocks = message.totalCodeBlocks?.toLong(), cwsprChatHasProjectContext = getMessageHasProjectContext(message.messageId) ) ChatInteractWithMessageEvent.builder().apply { @@ -422,11 +422,11 @@ class TelemetryHelper(private val context: AmazonQAppInitContext, private val se AmazonqTelemetry.indexWorkspace( project = null, duration = duration, - amazonqIndexFileCount = fileCount, - amazonqIndexFileSizeInMB = fileSize, + amazonqIndexFileCount = fileCount.toLong(), + amazonqIndexFileSizeInMB = fileSize.toLong(), success = isSuccess, - amazonqIndexMemoryUsageInMB = memoryUsage, - amazonqIndexCpuUsagePercentage = cpuUsage, + amazonqIndexMemoryUsageInMB = memoryUsage?.toLong(), + amazonqIndexCpuUsagePercentage = cpuUsage?.toLong(), credentialStartUrl = startUrl ) } diff --git a/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformTelemetryManager.kt b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformTelemetryManager.kt index 757c68da0c8..ec958cd2806 100644 --- a/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformTelemetryManager.kt +++ b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformTelemetryManager.kt @@ -89,9 +89,9 @@ class CodeTransformTelemetryManager(private val project: Project) { fun uploadProject(payloadSize: Int, startTime: Instant, dependenciesCopied: Boolean = false, telemetryErrorMessage: String? = null) { CodetransformTelemetry.uploadProject( - codeTransformRunTimeLatency = calculateTotalLatency(startTime, Instant.now()), + codeTransformRunTimeLatency = calculateTotalLatency(startTime, Instant.now()).toLong(), codeTransformSessionId = sessionId, - codeTransformTotalByteSize = payloadSize, + codeTransformTotalByteSize = payloadSize.toLong(), codeTransformDependenciesCopied = dependenciesCopied, result = if (telemetryErrorMessage.isNullOrEmpty()) Result.Succeeded else Result.Failed, reason = telemetryErrorMessage, @@ -101,7 +101,7 @@ class CodeTransformTelemetryManager(private val project: Project) { fun jobStart(transformStartTime: Instant, jobId: JobId?, telemetryErrorMessage: String? = null) = CodetransformTelemetry.jobStart( codeTransformSessionId = sessionId, codeTransformJobId = jobId?.id.orEmpty(), - codeTransformRunTimeLatency = calculateTotalLatency(transformStartTime, Instant.now()), // subtract current time by project start time + codeTransformRunTimeLatency = calculateTotalLatency(transformStartTime, Instant.now()).toLong(), // subtract current time by project start time result = if (telemetryErrorMessage.isNullOrEmpty()) Result.Succeeded else Result.Failed, reason = telemetryErrorMessage, ) @@ -117,9 +117,9 @@ class CodeTransformTelemetryManager(private val project: Project) { codeTransformArtifactType = artifactType, codeTransformJobId = jobId.id, codeTransformRuntimeError = telemetryErrorMessage, - codeTransformRunTimeLatency = calculateTotalLatency(downloadStartTime, Instant.now()), + codeTransformRunTimeLatency = calculateTotalLatency(downloadStartTime, Instant.now()).toLong(), codeTransformSessionId = sessionId, - codeTransformTotalByteSize = totalDownloadBytes, + codeTransformTotalByteSize = totalDownloadBytes.toLong(), result = if (telemetryErrorMessage.isNullOrEmpty()) Result.Succeeded else Result.Failed, reason = telemetryErrorMessage, ) @@ -175,7 +175,7 @@ class CodeTransformTelemetryManager(private val project: Project) { codeTransformRunTimeLatency = calculateTotalLatency( CodeTransformTelemetryState.instance.getStartTime(), Instant.now() - ), + ).toLong(), codeTransformLocalJavaVersion = getJavaVersionFromProjectSetting(project), ) diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/credentials/CodeWhispererClientAdaptor.kt b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/credentials/CodeWhispererClientAdaptor.kt index e2508153b21..e8694ca0dbc 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/credentials/CodeWhispererClientAdaptor.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/credentials/CodeWhispererClientAdaptor.kt @@ -104,9 +104,9 @@ interface CodeWhispererClientAdaptor : Disposable { fun sendCodePercentageTelemetry( language: CodeWhispererProgrammingLanguage, customizationArn: String?, - acceptedTokenCount: Int, - totalTokenCount: Int, - unmodifiedAcceptedTokenCount: Int? + acceptedTokenCount: Long, + totalTokenCount: Long, + unmodifiedAcceptedTokenCount: Long? ): SendTelemetryEventResponse fun sendUserModificationTelemetry( @@ -337,18 +337,18 @@ open class CodeWhispererClientAdaptorImpl(override val project: Project) : CodeW override fun sendCodePercentageTelemetry( language: CodeWhispererProgrammingLanguage, customizationArn: String?, - acceptedTokenCount: Int, - totalTokenCount: Int, - unmodifiedAcceptedTokenCount: Int? + acceptedTokenCount: Long, + totalTokenCount: Long, + unmodifiedAcceptedTokenCount: Long? ): SendTelemetryEventResponse = bearerClient().sendTelemetryEvent { requestBuilder -> requestBuilder.telemetryEvent { telemetryEventBuilder -> telemetryEventBuilder.codeCoverageEvent { it.programmingLanguage { languageBuilder -> languageBuilder.languageName(language.toCodeWhispererRuntimeLanguage().languageId) } it.customizationArn(customizationArn) - it.acceptedCharacterCount(acceptedTokenCount) - it.totalCharacterCount(totalTokenCount) + it.acceptedCharacterCount(acceptedTokenCount.toInt()) + it.totalCharacterCount(totalTokenCount.toInt()) it.timestamp(Instant.now()) - it.unmodifiedAcceptedCharacterCount(unmodifiedAcceptedTokenCount) + it.unmodifiedAcceptedCharacterCount(unmodifiedAcceptedTokenCount?.toInt()) } } requestBuilder.optOutPreference(getTelemetryOptOutPreference()) diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererCodeCoverageTracker.kt b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererCodeCoverageTracker.kt index dc4a42fede9..c8c07026422 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererCodeCoverageTracker.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererCodeCoverageTracker.kt @@ -38,7 +38,7 @@ import java.time.Duration import java.time.Instant import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicInteger -import kotlin.math.roundToInt +import kotlin.math.roundToLong // TODO: reset code coverage calculator on logging out connection? abstract class CodeWhispererCodeCoverageTracker( @@ -49,15 +49,15 @@ abstract class CodeWhispererCodeCoverageTracker( private val fileToTokens: MutableMap, private val myServiceInvocationCount: AtomicInteger ) : Disposable { - val percentage: Int? - get() = if (totalTokensSize != 0) calculatePercentage(acceptedTokensSize, totalTokensSize) else null - val acceptedTokensSize: Int + val percentage: Long? + get() = if (totalTokensSize != 0L) calculatePercentage(acceptedTokensSize, totalTokensSize) else null + val acceptedTokensSize: Long get() = fileToTokens.map { it.value.acceptedTokens.get() }.fold(0) { acc, next -> acc + next } - val totalTokensSize: Int + val totalTokensSize: Long get() = fileToTokens.map { it.value.totalTokens.get() }.fold(0) { acc, next -> @@ -203,7 +203,7 @@ abstract class CodeWhispererCodeCoverageTracker( if (myServiceInvocationCount.get() <= 0) return // accepted char count without considering modification - var rawAcceptedCharacterCount = 0 + var rawAcceptedCharacterCount = 0L rangeMarkers.forEach { rangeMarker -> if (!rangeMarker.isValid) return@forEach // if users add more code upon the recommendation generated from CodeWhisperer, we consider those added part as userToken but not CwsprTokens @@ -253,7 +253,7 @@ abstract class CodeWhispererCodeCoverageTracker( codewhispererLanguage = language.toTelemetryType(), codewhispererPercentage = percentage, codewhispererTotalTokens = totalTokensSize, - successCount = myServiceInvocationCount.get(), + successCount = myServiceInvocationCount.get().toLong(), codewhispererCustomizationArn = customizationArn, codewhispererUserGroup = CodeWhispererUserGroupSettings.getInstance().getUserGroup().name, credentialStartUrl = getCodeWhispererStartUrl(project) @@ -284,7 +284,7 @@ abstract class CodeWhispererCodeCoverageTracker( private val LOG = getLogger() private val instances: MutableMap = mutableMapOf() - fun calculatePercentage(acceptedTokens: Int, totalTokens: Int): Int = ((acceptedTokens.toDouble() * 100) / totalTokens).roundToInt() + fun calculatePercentage(acceptedTokens: Long, totalTokens: Long): Long = ((acceptedTokens.toDouble() * 100) / totalTokens).roundToLong() fun getInstance(project: Project, language: CodeWhispererProgrammingLanguage): CodeWhispererCodeCoverageTracker = when (val instance = instances[language]) { null -> { diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererTelemetryService.kt b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererTelemetryService.kt index 29c0902052a..faf375c0f3a 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererTelemetryService.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererTelemetryService.kt @@ -122,11 +122,11 @@ class CodeWhispererTelemetryService { project = requestContext.project, codewhispererAutomatedTriggerType = automatedTriggerType.telemetryType, codewhispererCompletionType = CodewhispererCompletionType.Line, - codewhispererCursorOffset = offset, + codewhispererCursorOffset = offset.toLong(), codewhispererGettingStartedTask = getGettingStartedTaskType(requestContext.editor), codewhispererLanguage = codewhispererLanguage, - codewhispererLastSuggestionIndex = lastRecommendationIndex, - codewhispererLineNumber = line, + codewhispererLastSuggestionIndex = lastRecommendationIndex.toLong(), + codewhispererLineNumber = line.toLong(), codewhispererRequestId = requestId, codewhispererSessionId = responseContext.sessionId, codewhispererTriggerType = triggerType, @@ -138,7 +138,7 @@ class CodeWhispererTelemetryService { codewhispererSupplementalContextTimeout = supContext?.isProcessTimeout, codewhispererSupplementalContextIsUtg = supContext?.isUtg, codewhispererSupplementalContextLatency = supContext?.latency?.toDouble(), - codewhispererSupplementalContextLength = supContext?.contentLength, + codewhispererSupplementalContextLength = supContext?.contentLength?.toLong(), codewhispererCustomizationArn = requestContext.customizationArn, codewhispererUserGroup = CodeWhispererUserGroupSettings.getInstance().getUserGroup().name ) @@ -172,18 +172,18 @@ class CodeWhispererTelemetryService { codewhispererCompletionType = detailContext.completionType, codewhispererGettingStartedTask = getGettingStartedTaskType(requestContext.editor), codewhispererLanguage = codewhispererLanguage, - codewhispererPaginationProgress = numOfRecommendations, + codewhispererPaginationProgress = numOfRecommendations.toLong(), codewhispererRequestId = requestId, codewhispererSessionId = responseContext.sessionId, - codewhispererSuggestionIndex = index, - codewhispererSuggestionReferenceCount = recommendation.references().size, + codewhispererSuggestionIndex = index.toLong(), + codewhispererSuggestionReferenceCount = recommendation.references().size.toLong(), codewhispererSuggestionReferences = jacksonObjectMapper().writeValueAsString(recommendation.references().map { it.licenseName() }.toSet().toList()), - codewhispererSuggestionImportCount = if (importEnabled) recommendation.mostRelevantMissingImports().size else null, + codewhispererSuggestionImportCount = if (importEnabled) recommendation.mostRelevantMissingImports().size.toLong() else null, codewhispererSuggestionState = suggestionState, codewhispererTriggerType = triggerTypeInfo.triggerType, credentialStartUrl = startUrl, codewhispererSupplementalContextIsUtg = supplementalContext?.isUtg, - codewhispererSupplementalContextLength = supplementalContext?.contentLength, + codewhispererSupplementalContextLength = supplementalContext?.contentLength?.toLong(), codewhispererSupplementalContextTimeout = supplementalContext?.isProcessTimeout, codewhispererUserGroup = CodeWhispererUserGroupSettings.getInstance().getUserGroup().name ) @@ -253,19 +253,19 @@ class CodeWhispererTelemetryService { credentialStartUrl = getConnectionStartUrl(requestContext.connection), codewhispererIsPartialAcceptance = null, codewhispererPartialAcceptanceCount = null, - codewhispererCharactersAccepted = acceptedCharCount, + codewhispererCharactersAccepted = acceptedCharCount.toLong(), codewhispererCharactersRecommended = null, codewhispererCompletionType = completionType, codewhispererLanguage = language.toTelemetryType(), codewhispererTriggerType = requestContext.triggerTypeInfo.triggerType, codewhispererAutomatedTriggerType = automatedTriggerType.telemetryType, - codewhispererLineNumber = requestContext.caretPosition.line, - codewhispererCursorOffset = requestContext.caretPosition.offset, - codewhispererSuggestionCount = recommendationContext.details.size, - codewhispererSuggestionImportCount = totalImportCount, + codewhispererLineNumber = requestContext.caretPosition.line.toLong(), + codewhispererCursorOffset = requestContext.caretPosition.offset.toLong(), + codewhispererSuggestionCount = recommendationContext.details.size.toLong(), + codewhispererSuggestionImportCount = totalImportCount.toLong(), codewhispererTotalShownTime = popupShownTime?.toMillis()?.toDouble(), codewhispererTriggerCharacter = triggerChar, - codewhispererTypeaheadLength = recommendationContext.userInputSinceInvocation.length, + codewhispererTypeaheadLength = recommendationContext.userInputSinceInvocation.length.toLong(), codewhispererTimeSinceLastDocumentChange = CodeWhispererInvocationStatus.getInstance().getTimeSinceDocumentChanged(), codewhispererTimeSinceLastUserDecision = codewhispererTimeSinceLastUserDecision, codewhispererTimeToFirstRecommendation = requestContext.latencyContext.paginationFirstCompletionTime, @@ -275,7 +275,7 @@ class CodeWhispererTelemetryService { codewhispererClassifierThreshold = classifierThreshold, codewhispererCustomizationArn = requestContext.customizationArn, codewhispererSupplementalContextIsUtg = supplementalContext?.isUtg, - codewhispererSupplementalContextLength = supplementalContext?.contentLength, + codewhispererSupplementalContextLength = supplementalContext?.contentLength?.toLong(), codewhispererSupplementalContextTimeout = supplementalContext?.isProcessTimeout, codewhispererSupplementalContextStrategyId = supplementalContext?.strategy.toString(), codewhispererUserGroup = CodeWhispererUserGroupSettings.getInstance().getUserGroup().name, @@ -315,19 +315,19 @@ class CodeWhispererTelemetryService { } CodewhispererTelemetry.securityScan( project = project, - codewhispererCodeScanLines = payloadContext.totalLines.toInt(), + codewhispererCodeScanLines = payloadContext.totalLines, codewhispererCodeScanJobId = codeScanJobId, codewhispererCodeScanProjectBytes = codeScanEvent.totalProjectSizeInBytes, - codewhispererCodeScanSrcPayloadBytes = payloadContext.srcPayloadSize.toInt(), - codewhispererCodeScanBuildPayloadBytes = payloadContext.buildPayloadSize?.toInt(), - codewhispererCodeScanSrcZipFileBytes = payloadContext.srcZipFileSize.toInt(), - codewhispererCodeScanTotalIssues = totalIssues, - codewhispererCodeScanIssuesWithFixes = issuesWithFixes, + codewhispererCodeScanSrcPayloadBytes = payloadContext.srcPayloadSize, + codewhispererCodeScanBuildPayloadBytes = payloadContext.buildPayloadSize, + codewhispererCodeScanSrcZipFileBytes = payloadContext.srcZipFileSize, + codewhispererCodeScanTotalIssues = totalIssues.toLong(), + codewhispererCodeScanIssuesWithFixes = issuesWithFixes.toLong(), codewhispererLanguage = payloadContext.language, duration = codeScanEvent.duration, - contextTruncationDuration = payloadContext.totalTimeInMilliseconds.toInt(), - artifactsUploadDuration = serviceInvocationContext.artifactsUploadDuration.toInt(), - codeScanServiceInvocationsDuration = serviceInvocationContext.serviceInvocationDuration.toInt(), + contextTruncationDuration = payloadContext.totalTimeInMilliseconds, + artifactsUploadDuration = serviceInvocationContext.artifactsUploadDuration, + codeScanServiceInvocationsDuration = serviceInvocationContext.serviceInvocationDuration, reason = reason, result = codeScanEvent.result, credentialStartUrl = startUrl, diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererUserModificationTracker.kt b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererUserModificationTracker.kt index 1c0174ec9a1..9320d76b0ce 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererUserModificationTracker.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererUserModificationTracker.kt @@ -207,12 +207,12 @@ class CodeWhispererUserModificationTracker(private val project: Project) : Dispo codewhispererRuntime = suggestion.codewhispererRuntime, codewhispererRuntimeSource = suggestion.codewhispererRuntimeSource, codewhispererSessionId = suggestion.sessionId, - codewhispererSuggestionIndex = suggestion.index, + codewhispererSuggestionIndex = suggestion.index.toLong(), codewhispererTriggerType = suggestion.triggerType, credentialStartUrl = startUrl, codewhispererUserGroup = CodeWhispererUserGroupSettings.getInstance().getUserGroup().name, - codewhispererCharactersModified = diff?.modified?.length ?: 0, - codewhispererCharactersAccepted = diff?.original?.length ?: 0 + codewhispererCharactersModified = diff?.modified?.length?.toLong() ?: 0, + codewhispererCharactersAccepted = diff?.original?.length?.toLong() ?: 0 ) } diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererCodeCoverageTrackerTest.kt b/plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererCodeCoverageTrackerTest.kt index be94fa83287..caebfb202d1 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererCodeCoverageTrackerTest.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererCodeCoverageTrackerTest.kt @@ -253,7 +253,7 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov val captor = argumentCaptor() verify(sut, Times(1)).documentChanged(captor.capture()) assertThat(captor.firstValue.newFragment.toString()).isEqualTo(keystrokeInput) - assertThat(sut.totalTokensSize).isEqualTo(keystrokeInput.length) + assertThat(sut.totalTokensSize).isEqualTo(keystrokeInput.length.toLong()) } @Test @@ -271,7 +271,7 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov val captor = argumentCaptor() verify(sut, Times(1)).documentChanged(captor.capture()) assertThat(captor.firstValue.newFragment.toString()).isEqualTo(pythonTestLeftContext) - assertThat(sut.totalTokensSize).isEqualTo(pythonTestLeftContext.length) + assertThat(sut.totalTokensSize).isEqualTo(pythonTestLeftContext.length.toLong()) val anotherCode = "(x, y):".repeat(8) runInEdtAndWait { @@ -279,7 +279,7 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov fixture.editor.appendString(anotherCode) } } - assertThat(sut.totalTokensSize).isEqualTo(pythonTestLeftContext.length) + assertThat(sut.totalTokensSize).isEqualTo(pythonTestLeftContext.length.toLong()) } @Test @@ -293,7 +293,7 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov CodeWhispererCodeCoverageTracker.getInstancesMap()[CodeWhispererPython.INSTANCE] = sut sut.activateTrackerIfNotActive() - assertThat(sut.totalTokensSize).isEqualTo(pythonTestLeftContext.length) + assertThat(sut.totalTokensSize).isEqualTo(pythonTestLeftContext.length.toLong()) runInEdtAndWait { fixture.editor.caretModel.primaryCaret.moveToOffset(fixture.editor.document.textLength) @@ -302,7 +302,7 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov } } - assertThat(sut.totalTokensSize).isEqualTo(pythonTestLeftContext.length) + assertThat(sut.totalTokensSize).isEqualTo(pythonTestLeftContext.length.toLong()) } @Test @@ -315,7 +315,7 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov ) CodeWhispererCodeCoverageTracker.getInstancesMap()[CodeWhispererPython.INSTANCE] = sut sut.activateTrackerIfNotActive() - assertThat(sut.totalTokensSize).isEqualTo(pythonTestLeftContext.length) + assertThat(sut.totalTokensSize).isEqualTo(pythonTestLeftContext.length.toLong()) runInEdtAndWait { WriteCommandAction.runWriteCommandAction(project) { @@ -323,7 +323,7 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov } } - assertThat(sut.totalTokensSize).isEqualTo(pythonTestLeftContext.length + 1) + assertThat(sut.totalTokensSize).isEqualTo(pythonTestLeftContext.length + 1L) } @Test @@ -366,8 +366,8 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov sut.activateTrackerIfNotActive() assertThat(sut.activeRequestCount()).isEqualTo(1) - assertThat(sut.acceptedTokensSize).isEqualTo("bar".length) - assertThat(sut.totalTokensSize).isEqualTo("foobar".length) + assertThat(sut.acceptedTokensSize).isEqualTo("bar".length.toLong()) + assertThat(sut.totalTokensSize).isEqualTo("foobar".length.toLong()) sut.forceTrackerFlush() @@ -569,7 +569,7 @@ internal class CodeWhispererCodeCoverageTrackerTestJava : CodeWhispererCodeCover } // reformat should fire documentChanged events, but tracker should not update token from these events verify(sut, atLeastOnce()).documentChanged(any()) - assertThat(sut.totalTokensSize).isEqualTo(codeNeedToBeReformatted.length) + assertThat(sut.totalTokensSize).isEqualTo(codeNeedToBeReformatted.length.toLong()) val formatted = """ class Answer { diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererTelemetryTest.kt b/plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererTelemetryTest.kt index 3a575bdb748..6fdf79471c9 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererTelemetryTest.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererTelemetryTest.kt @@ -531,7 +531,7 @@ class CodeWhispererTelemetryTest : CodeWhispererTestBase() { CodeWhispererCodeCoverageTracker.getInstance(project, CodeWhispererPython.INSTANCE).dispose() - val rawAcceptedTokenSize = pythonResponse.completions().first().content().length + val rawAcceptedTokenSize = pythonResponse.completions().first().content().length.toLong() val acceptedTokensSize = rawAcceptedTokenSize - deletedTokenByUser val totalTokensSize = keystrokeInput.length + rawAcceptedTokenSize @@ -580,7 +580,7 @@ class CodeWhispererTelemetryTest : CodeWhispererTestBase() { CodeWhispererCodeCoverageTracker.getInstance(project, CodeWhispererPython.INSTANCE).dispose() } - val rawAcceptedTokenSize = pythonResponse.completions().first().content().length + val rawAcceptedTokenSize = pythonResponse.completions().first().content().length.toLong() val totalTokensSize = keystrokeInput.length + rawAcceptedTokenSize + 1 val metricCaptor = argumentCaptor() @@ -682,7 +682,7 @@ class CodeWhispererTelemetryTest : CodeWhispererTestBase() { CodeWhispererCodeCoverageTracker.getInstance(project, CodeWhispererPython.INSTANCE).dispose() val rawAcceptedTokenSize = "x, y):\n return x + y".length - val acceptedTokensSize = rawAcceptedTokenSize + val acceptedTokensSize = rawAcceptedTokenSize.toLong() val totalTokensSize = "()".length + acceptedTokensSize val metricCaptor = argumentCaptor() verify(batcher, atLeastOnce()).enqueue(metricCaptor.capture()) diff --git a/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/credentials/sso/SsoAccessTokenProvider.kt b/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/credentials/sso/SsoAccessTokenProvider.kt index 131a017b297..882cbce553e 100644 --- a/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/credentials/sso/SsoAccessTokenProvider.kt +++ b/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/credentials/sso/SsoAccessTokenProvider.kt @@ -345,14 +345,14 @@ class SsoAccessTokenProvider( result: Result ) { val tokenCreationTime = currentToken.createdAt - val sessionDuration = Duration.between(Instant.now(clock), tokenCreationTime) + val sessionDuration = Duration.between(tokenCreationTime, Instant.now(clock)) val credentialSourceId = if (currentToken.ssoUrl == SONO_URL) CredentialSourceId.AwsId else CredentialSourceId.IamIdentityCenter if (tokenCreationTime != Instant.EPOCH) { AwsTelemetry.refreshCredentials( project = null, result = result, - sessionDuration = sessionDuration.toHours().toInt(), + sessionDuration = sessionDuration.toMillis(), credentialSourceId = credentialSourceId, reason = reason, reasonDesc = reasonDesc, @@ -419,10 +419,11 @@ class SsoAccessTokenProvider( is AwsServiceException -> e.requestId() else -> null } - val message = when (e) { - is AwsServiceException -> e.awsErrorDetails()?.errorMessage() - else -> e.message - } ?: "$stageName: Unknown error" + + // AwsServiceException#message will automatically pull in AwsServiceException#awsErrorDetails + // we expect messages for SsoOidcException to be populated in e.message using execution executor added in + // https://github.com/aws/aws-toolkit-jetbrains/commit/cc9ed87fa9391dd39ac05cbf99b4437112fa3d10 + val message = e.message ?: "$stageName: ${e::class.java.name}" sendRefreshCredentialsMetric( currentToken, @@ -435,7 +436,7 @@ class SsoAccessTokenProvider( } } - enum class RefreshCredentialStage { + private enum class RefreshCredentialStage { CREATE_TOKEN, GET_TOKEN_DETAILS, SAVE_TOKEN diff --git a/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/GettingStartedAuthUtils.kt b/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/GettingStartedAuthUtils.kt index e71729efe2c..b35d8ff5661 100644 --- a/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/GettingStartedAuthUtils.kt +++ b/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/GettingStartedAuthUtils.kt @@ -30,7 +30,7 @@ import software.aws.toolkits.telemetry.Result fun requestCredentialsForCodeWhisperer( project: Project, popupBuilderIdTab: Boolean = true, - initialConnectionCount: Int = getConnectionCount(), + initialConnectionCount: Long = getConnectionCount(), initialAuthConnections: String = getEnabledConnections( project ), @@ -116,7 +116,7 @@ fun requestCredentialsForCodeWhisperer( @Deprecated("pending moving to Q package") fun requestCredentialsForQ( project: Project, - initialConnectionCount: Int = getConnectionCount(), + initialConnectionCount: Long = getConnectionCount(), initialAuthConnections: String = getEnabledConnections( project ), diff --git a/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/SetupAuthenticationDialog.kt b/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/SetupAuthenticationDialog.kt index 85877f31683..a5679e810dc 100644 --- a/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/SetupAuthenticationDialog.kt +++ b/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/SetupAuthenticationDialog.kt @@ -112,7 +112,7 @@ data class SetupAuthenticationNotice( } interface AuthenticationDialog { - val attempts: Int + val attempts: Long val authType: CredentialSourceId } @@ -138,7 +138,7 @@ class SetupAuthenticationDialog( private val builderIdTab = BuilderIdTabPanelBuilder().build() private val iamTab = iamTab() private val wrappers = SetupAuthenticationTabs.values().associateWith { BorderLayoutPanel() } - override var attempts = 0 + override var attempts = 0L private set override var authType = CredentialSourceId.IamIdentityCenter private set diff --git a/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt b/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt index 66f8ecfda6b..3dbbf7380b7 100644 --- a/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt +++ b/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/gettingstarted/editor/GettingStartedTelemetryUtils.kt @@ -14,10 +14,10 @@ import software.aws.toolkits.jetbrains.settings.AwsSettings import software.aws.toolkits.telemetry.AuthStatus import software.aws.toolkits.telemetry.StartUpState -fun getConnectionCount(): Int { +fun getConnectionCount(): Long { val bearerTokenCount = ToolkitAuthManager.getInstance().listConnections().size val iamCredentialCount = CredentialManager.getInstance().getCredentialIdentifiers().count { it !is ProfileCredentialsIdentifierSso } - return bearerTokenCount + iamCredentialCount + return (bearerTokenCount + iamCredentialCount).toLong() } fun getEnabledConnectionsForTelemetry(project: Project?): Set { diff --git a/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/FeatureDevSessionContext.kt b/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/FeatureDevSessionContext.kt index b5f4e84532d..4527e819f5d 100644 --- a/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/FeatureDevSessionContext.kt +++ b/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/FeatureDevSessionContext.kt @@ -119,7 +119,7 @@ class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Lo suspend fun zipFiles(projectRoot: VirtualFile): File = withContext(getCoroutineBgContext()) { val files = mutableListOf() - val ignoredExtensionMap = mutableMapOf().withDefault { 0 } + val ignoredExtensionMap = mutableMapOf().withDefault { 0L } var totalSize: Long = 0 VfsUtil.visitChildrenRecursively( diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/core/gettingstarted/GatewaySetupAuthenticationDialog.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/core/gettingstarted/GatewaySetupAuthenticationDialog.kt index 1e51bfd3daa..010899bab27 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/core/gettingstarted/GatewaySetupAuthenticationDialog.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/core/gettingstarted/GatewaySetupAuthenticationDialog.kt @@ -62,7 +62,7 @@ class GatewaySetupAuthenticationDialog( private val idcTab = IdcTabPanelBuilder(state.idcTabState::startUrl, state.idcTabState::region).build() private val builderIdTab = BuilderIdTabPanelBuilder().build() private val wrappers = GatewaySetupAuthenticationTabs.values().associateWith { BorderLayoutPanel() } - override var attempts = 0 + override var attempts = 0L private set override var authType = CredentialSourceId.IamIdentityCenter private set diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/core/gettingstarted/ToolkitGettingStartedAuthUtils.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/core/gettingstarted/ToolkitGettingStartedAuthUtils.kt index 2a4176fe980..d84a424c578 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/core/gettingstarted/ToolkitGettingStartedAuthUtils.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/core/gettingstarted/ToolkitGettingStartedAuthUtils.kt @@ -23,7 +23,7 @@ import software.aws.toolkits.telemetry.Result fun requestCredentialsForCodeCatalyst( project: Project?, popupBuilderIdTab: Boolean = true, - initialConnectionCount: Int = getConnectionCount(), + initialConnectionCount: Long = getConnectionCount(), initialAuthConnections: String = getEnabledConnections( project ), @@ -117,7 +117,7 @@ fun requestCredentialsForCodeCatalyst( fun requestCredentialsForExplorer( project: Project, - initialConnectionCount: Int = getConnectionCount(), + initialConnectionCount: Long = getConnectionCount(), initialAuthConnections: String = getEnabledConnections( project ),