Skip to content

Commit fdfc07c

Browse files
authored
telemetry(amazonq): map to the correct scope (#5210)
1 parent e2bac9b commit fdfc07c

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererCodeScanManager.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ class CodeWhispererCodeScanManager(val project: Project) {
475475
codeScanStatus,
476476
codeScanResponseContext.payloadContext.srcPayloadSize.toDouble() ?: 0.0,
477477
connection,
478-
scope
478+
scope,
479+
initiatedByChat
479480
)
480481
)
481482
sendCodeScanTelemetryToServiceAPI(project, language, codeScanResponseContext, scope)

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/model/CodeWhispererModel.kt

+1
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ data class CodeScanTelemetryEvent(
254254
val totalProjectSizeInBytes: Double?,
255255
val connection: ToolkitConnection?,
256256
val codeAnalysisScope: CodeWhispererConstants.CodeAnalysisScope,
257+
val initiatedByChat: Boolean = false,
257258
)
258259

259260
data class CreateUploadUrlServiceInvocationContext(

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererTelemetryService.kt

+21-6
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,18 @@ class CodeWhispererTelemetryService {
283283
)
284284
}
285285

286+
private fun mapToTelemetryScope(codeAnalysisScope: CodeWhispererConstants.CodeAnalysisScope, initiatedByChat: Boolean): CodewhispererCodeScanScope =
287+
when (codeAnalysisScope) {
288+
CodeWhispererConstants.CodeAnalysisScope.FILE -> {
289+
if (initiatedByChat) {
290+
CodewhispererCodeScanScope.FILEONDEMAND
291+
} else {
292+
CodewhispererCodeScanScope.FILEAUTO
293+
}
294+
}
295+
CodeWhispererConstants.CodeAnalysisScope.PROJECT -> CodewhispererCodeScanScope.PROJECT
296+
}
297+
286298
fun sendSecurityScanEvent(codeScanEvent: CodeScanTelemetryEvent, project: Project? = null) {
287299
val payloadContext = codeScanEvent.codeScanResponseContext.payloadContext
288300
val serviceInvocationContext = codeScanEvent.codeScanResponseContext.serviceInvocationContext
@@ -291,8 +303,9 @@ class CodeWhispererTelemetryService {
291303
val issuesWithFixes = codeScanEvent.codeScanResponseContext.codeScanIssuesWithFixes
292304
val reason = codeScanEvent.codeScanResponseContext.reason
293305
val startUrl = getConnectionStartUrl(codeScanEvent.connection)
294-
val codeAnalysisScope = codeScanEvent.codeAnalysisScope
295-
val passive = codeAnalysisScope == CodeWhispererConstants.CodeAnalysisScope.FILE
306+
val codeAnalysisScope = mapToTelemetryScope(codeScanEvent.codeAnalysisScope, codeScanEvent.initiatedByChat)
307+
val passive = codeAnalysisScope == CodewhispererCodeScanScope.FILEAUTO
308+
val source = if (codeScanEvent.initiatedByChat) "chat" else "menu"
296309

297310
LOG.debug {
298311
"Recording code security scan event. \n" +
@@ -309,8 +322,9 @@ class CodeWhispererTelemetryService {
309322
"Service invocation duration in milliseconds: ${serviceInvocationContext.serviceInvocationDuration}, \n" +
310323
"Total number of lines scanned: ${payloadContext.totalLines}, \n" +
311324
"Reason: $reason \n" +
312-
"Scope: ${codeAnalysisScope.value} \n" +
313-
"Passive: $passive \n"
325+
"Scope: $codeAnalysisScope \n" +
326+
"Passive: $passive \n" +
327+
"Source: $source \n"
314328
}
315329
CodewhispererTelemetry.securityScan(
316330
project = project,
@@ -330,8 +344,9 @@ class CodeWhispererTelemetryService {
330344
reason = reason,
331345
result = codeScanEvent.result,
332346
credentialStartUrl = startUrl,
333-
codewhispererCodeScanScope = CodewhispererCodeScanScope.from(codeAnalysisScope.value),
334-
passive = passive
347+
codewhispererCodeScanScope = codeAnalysisScope,
348+
passive = passive,
349+
source = source
335350
)
336351
}
337352

0 commit comments

Comments
 (0)