Skip to content

Commit 8917978

Browse files
author
David Hasani
committed
add try-catch
1 parent 3fb1c2f commit 8917978

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/ArtifactHandler.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,14 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
203203
if (output.artifact is CodeModernizerArtifact && output.artifact.metrics != null) {
204204
output.artifact.metrics.linesOfCodeSubmitted = CodeModernizerSessionState.getInstance(project).getLinesOfCodeSubmitted()
205205
output.artifact.metrics.programmingLanguage = CodeModernizerSessionState.getInstance(project).getTransformationLanguage()
206-
clientAdaptor.sendTransformTelemetryEvent(job, output.artifact.metrics)
206+
notifyStickyInfo("metrics.json", output.artifact.metrics.toString())
207+
try {
208+
clientAdaptor.sendTransformTelemetryEvent(job, output.artifact.metrics)
209+
} catch (e: Exception) {
210+
// log error, but can still show diff.patch and summary.md
211+
LOG.error { e.message.toString() }
212+
telemetryErrorMessage = "Unexpected error when sending telemetry with metrics ${e.localizedMessage}"
213+
}
207214
}
208215
}
209216
output

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/client/GumbyClient.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeModerni
5252
import software.aws.toolkits.jetbrains.services.codemodernizer.model.JobId
5353
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.calculateTotalLatency
5454
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererUtil.getTelemetryOptOutPreference
55+
import software.aws.toolkits.jetbrains.utils.notifyStickyInfo
5556
import java.io.File
5657
import java.net.HttpURLConnection
5758
import java.time.Instant
@@ -215,7 +216,8 @@ class GumbyClient(private val project: Project) {
215216
}
216217

217218
fun sendTransformTelemetryEvent(job: JobId, metrics: CodeModernizerMetrics) {
218-
bearerClient().sendTelemetryEvent { requestBuilder ->
219+
notifyStickyInfo("in sendTransformTelemetryEvent!")
220+
val resp = bearerClient().sendTelemetryEvent { requestBuilder ->
219221
requestBuilder.telemetryEvent { telemetryEventBuilder ->
220222
telemetryEventBuilder.transformEvent {
221223
it.jobId(job.id)
@@ -229,9 +231,13 @@ class GumbyClient(private val project: Project) {
229231
it.linesOfCodeSubmitted(metrics.linesOfCodeSubmitted) // currently unavailable for SQL conversions
230232
}
231233
}
234+
notifyStickyInfo("sendTelemetryEvent requestBuilder", requestBuilder.toString())
232235
requestBuilder.optOutPreference(getTelemetryOptOutPreference())
236+
notifyStickyInfo("sendTelemetryEvent optOutPreference", getTelemetryOptOutPreference().toString())
233237
requestBuilder.userContext(codeWhispererUserContext())
238+
notifyStickyInfo("sendTelemetryEvent userContext", codeWhispererUserContext().toString())
234239
}
240+
notifyStickyInfo("sendTelemetryEvent resp", resp.toString())
235241
}
236242

237243
companion object {

0 commit comments

Comments
 (0)