Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
)
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand Down Expand Up @@ -175,7 +175,7 @@ class CodeTransformTelemetryManager(private val project: Project) {
codeTransformRunTimeLatency = calculateTotalLatency(
CodeTransformTelemetryState.instance.getStartTime(),
Instant.now()
),
).toLong(),
codeTransformLocalJavaVersion = getJavaVersionFromProjectSetting(project),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -49,15 +49,15 @@ abstract class CodeWhispererCodeCoverageTracker(
private val fileToTokens: MutableMap<Document, CodeCoverageTokens>,
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 ->
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -284,7 +284,7 @@ abstract class CodeWhispererCodeCoverageTracker(
private val LOG = getLogger<CodeWhispererCodeCoverageTracker>()
private val instances: MutableMap<CodeWhispererProgrammingLanguage, CodeWhispererCodeCoverageTracker> = 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 -> {
Expand Down
Loading
Loading