Skip to content

Commit

Permalink
fix(amazonq): add field for builderId vs IdC (aws#4249)
Browse files Browse the repository at this point in the history
* fix(amazonq): improve telemetry

* remove unused import

* address comments

* fix detekt issue

---------

Co-authored-by: David Hasani <[email protected]>
  • Loading branch information
2 people authored and kumsmrit committed Apr 16, 2024
1 parent 0d4e131 commit 22f39d5
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 179 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mockito = "5.10.0"
mockitoKotlin = "5.2.1"
mockk = "1.13.8"
node-gradle = "7.0.1"
telemetryGenerator = "1.0.197"
telemetryGenerator = "1.0.201"
testLogger = "4.0.0"
testRetry = "1.5.2"
# test-only; platform provides slf4j transitively at runtime. <233, 1.7.36; >=233, 2.0.9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
)
dialog.isModal = true

telemetry.vcsDiffViewerVisible(jobId)
telemetry.vcsDiffViewerVisible(jobId) // download succeeded
if (dialog.showAndGet()) {
telemetry.vcsViewerSubmitted(jobId)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,13 @@ class CodeModernizerSession(
LOG.warn { "Job was cancelled by user before start job was called" }
CodeModernizerStartJobResult.Cancelled
} else {
val errorMessage = "Failed to start job"
LOG.error(e) { errorMessage }
state.putJobHistory(sessionContext, TransformationStatus.FAILED)
state.currentJobStatus = TransformationStatus.FAILED
telemetry.error(errorMessage)
CodeModernizerStartJobResult.UnableToStartJob(e.message.toString())
}
} catch (e: Exception) {
val errorMessage = "Failed to start job"
LOG.error(e) { errorMessage }
state.putJobHistory(sessionContext, TransformationStatus.FAILED)
state.currentJobStatus = TransformationStatus.FAILED
telemetry.error(errorMessage)
CodeModernizerStartJobResult.UnableToStartJob(e.message.toString())
} finally {
deleteUploadArtifact(payload)
Expand Down Expand Up @@ -273,6 +267,8 @@ class CodeModernizerSession(
) { shouldStop.get() }
} catch (e: Exception) {
val errorMessage = "Unexpected error when uploading artifact to S3: ${e.localizedMessage}"
LOG.error { errorMessage }
// emit this metric here manually since we don't use callApi(), which emits its own metric
telemetry.apiError(errorMessage, CodeTransformApiNames.UploadZip, createUploadUrlResponse.uploadId())
throw e // pass along error to callee
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import org.apache.commons.codec.digest.DigestUtils
import software.amazon.awssdk.services.codewhispererruntime.model.TransformationStatus
import software.aws.toolkits.jetbrains.core.gettingstarted.editor.ActiveConnection
import software.aws.toolkits.jetbrains.core.gettingstarted.editor.ActiveConnectionType
import software.aws.toolkits.jetbrains.core.gettingstarted.editor.BearerTokenFeatureSet
import software.aws.toolkits.jetbrains.core.gettingstarted.editor.checkBearerConnectionValidity
import software.aws.toolkits.jetbrains.services.codemodernizer.model.CustomerSelection
import software.aws.toolkits.jetbrains.services.codemodernizer.model.JobId
import software.aws.toolkits.jetbrains.services.codemodernizer.model.ValidationResult
Expand All @@ -20,9 +24,9 @@ import software.aws.toolkits.telemetry.CodeTransformJavaTargetVersionsAllowed
import software.aws.toolkits.telemetry.CodeTransformMavenBuildCommand
import software.aws.toolkits.telemetry.CodeTransformPatchViewerCancelSrcComponents
import software.aws.toolkits.telemetry.CodeTransformPreValidationError
import software.aws.toolkits.telemetry.CodeTransformStartSrcComponents
import software.aws.toolkits.telemetry.CodeTransformVCSViewerSrcComponents
import software.aws.toolkits.telemetry.CodetransformTelemetry
import software.aws.toolkits.telemetry.CredentialSourceId
import software.aws.toolkits.telemetry.Result
import java.time.Instant
import java.util.Base64
Expand All @@ -34,14 +38,6 @@ import java.util.Base64
class CodeTransformTelemetryManager(private val project: Project) {
private val sessionId get() = CodeTransformTelemetryState.instance.getSessionId()
private val currentJobStatus get() = CodeModernizerSessionState.getInstance(project).currentJobStatus.toString()
fun sendUserClickedTelemetry(srcStartComponent: CodeTransformStartSrcComponents) {
CodeTransformTelemetryState.instance.setStartTime()
CodeTransformTelemetryState.instance.setSessionId()
CodetransformTelemetry.isDoubleClickedToTriggerUserModal(
codeTransformStartSrcComponents = srcStartComponent,
codeTransformSessionId = sessionId,
)
}

private fun getProjectHash(customerSelection: CustomerSelection) = Base64.getEncoder().encodeToString(
DigestUtils.sha256(customerSelection.configurationFile.toNioPath().toAbsolutePath().toString())
Expand Down Expand Up @@ -183,10 +179,16 @@ class CodeTransformTelemetryManager(private val project: Project) {
}

fun dependenciesCopied() = CodetransformTelemetry.dependenciesCopied(codeTransformSessionId = sessionId)
fun configurationFileSelectedChanged() = CodetransformTelemetry.configurationFileSelectedChanged(codeTransformSessionId = sessionId)
fun jobIsStartedFromUserPopupClick() = CodetransformTelemetry.jobIsStartedFromUserPopupClick(codeTransformSessionId = sessionId)
fun jobIsCanceledFromUserPopupClick() = CodetransformTelemetry.jobIsCanceledFromUserPopupClick(codeTransformSessionId = sessionId)
fun jobIsStartedFromChatPrompt() = CodetransformTelemetry.jobIsStartedFromChatPrompt(codeTransformSessionId = sessionId)
fun jobIsStartedFromChatPrompt() {
val connection = checkBearerConnectionValidity(project, BearerTokenFeatureSet.Q)
var authType: CredentialSourceId? = null
if (connection.connectionType == ActiveConnectionType.IAM_IDC && connection is ActiveConnection.ValidBearer) {
authType = CredentialSourceId.IamIdentityCenter
} else if (connection.connectionType == ActiveConnectionType.BUILDER_ID && connection is ActiveConnection.ValidBearer) {
authType = CredentialSourceId.AwsId
}
CodetransformTelemetry.jobIsStartedFromChatPrompt(codeTransformSessionId = sessionId, credentialSourceId = authType)
}

companion object {
fun getInstance(project: Project): CodeTransformTelemetryManager = project.service()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.toVirtualFile
import software.aws.toolkits.jetbrains.services.codemodernizer.tryGetJdk
import software.aws.toolkits.jetbrains.services.cwc.messages.ChatMessageType
import software.aws.toolkits.resources.message
import software.aws.toolkits.telemetry.CodeTransformStartSrcComponents

class CodeTransformChatController(
private val context: AmazonQAppInitContext,
private val chatSessionStorage: ChatSessionStorage
) : InboundAppMessagesHandler {
private val authController = AuthController()
private val messagePublisher = context.messagesFromAppToUi
private val telemetry = CodeTransformTelemetryManager.getInstance(context.project)
private val codeModernizerManager = CodeModernizerManager.getInstance(context.project)
private val codeTransformChatHelper = CodeTransformChatHelper(context.messagesFromAppToUi, chatSessionStorage)
private val artifactHandler = ArtifactHandler(context.project, GumbyClient.getInstance(context.project))
Expand All @@ -72,9 +70,6 @@ class CodeTransformChatController(
return
}

CodeTransformTelemetryManager.getInstance(context.project).jobIsStartedFromChatPrompt()

telemetry.sendUserClickedTelemetry(CodeTransformStartSrcComponents.ChatPrompt)
codeTransformChatHelper.setActiveCodeTransformTabId(message.tabId)

if (!message.startNewTransform) {
Expand Down Expand Up @@ -108,6 +103,8 @@ class CodeTransformChatController(

delay(500)

CodeTransformTelemetryManager.getInstance(context.project).jobIsStartedFromChatPrompt()

codeTransformChatHelper.addNewMessage(
buildUserInputChatContent(context.project, validationResult)
)
Expand Down

This file was deleted.

0 comments on commit 22f39d5

Please sign in to comment.