Skip to content

Commit 950a52b

Browse files
authored
codewhisperer: add accepted char count in telemetry (#3917)
1 parent 007e6c1 commit 950a52b

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/telemetry/CodeWhispererTelemetryService.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ class CodeWhispererTelemetryService {
185185
suggestionState: CodewhispererSuggestionState,
186186
popupShownTime: Duration?,
187187
suggestionReferenceCount: Int,
188-
generatedLineCount: Int
188+
generatedLineCount: Int,
189+
acceptedCharCount: Int
189190
) {
190191
val project = requestContext.project
191192
val totalImportCount = recommendationContext.details.fold(0) { grandTotal, detail ->
@@ -245,7 +246,7 @@ class CodeWhispererTelemetryService {
245246
credentialStartUrl = getConnectionStartUrl(requestContext.connection),
246247
codewhispererIsPartialAcceptance = null,
247248
codewhispererPartialAcceptanceCount = null,
248-
codewhispererCharactersAccepted = null,
249+
codewhispererCharactersAccepted = acceptedCharCount,
249250
codewhispererCharactersRecommended = null,
250251
codewhispererCompletionType = completionType,
251252
codewhispererLanguage = language.toTelemetryType(),
@@ -373,14 +374,16 @@ class CodeWhispererTelemetryService {
373374
""
374375
}
375376
val generatedLineCount = if (acceptedContent.isEmpty()) 0 else acceptedContent.split("\n").size
377+
val acceptedCharCount = acceptedContent.length
376378
sendUserTriggerDecisionEvent(
377379
requestContext,
378380
responseContext,
379381
recommendationContext,
380382
CodewhispererSuggestionState.from(this.toString()),
381383
popupShownTime,
382384
referenceCount,
383-
generatedLineCount
385+
generatedLineCount,
386+
acceptedCharCount
384387
)
385388

386389
// step 2, put current decision into queue for later reference

jetbrains-core/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererTelemetryServiceTest.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ class CodeWhispererTelemetryServiceTest {
240240
val suggestionState = CodewhispererSuggestionState.Reject
241241
val suggestionReferenceCount = Random.nextInt(2)
242242
val lineCount = Random.nextInt(0, 100)
243+
val charCount = Random.nextInt(0, 100)
243244

244245
val expectedTotalImportCount = recommendationContext.details.fold(0) { grandTotal, detail ->
245246
grandTotal + detail.recommendation.mostRelevantMissingImports().size
@@ -252,7 +253,8 @@ class CodeWhispererTelemetryServiceTest {
252253
suggestionState,
253254
popupShownDuration,
254255
suggestionReferenceCount,
255-
lineCount
256+
lineCount,
257+
charCount
256258
)
257259

258260
argumentCaptor<MetricEvent>().apply {
@@ -284,14 +286,15 @@ class CodeWhispererTelemetryServiceTest {
284286
"codewhispererUserGroup" to "Control",
285287
"codewhispererSupplementalContextTimeout" to supplementalContextInfo.isProcessTimeout,
286288
"codewhispererSupplementalContextIsUtg" to supplementalContextInfo.isUtg,
287-
"codewhispererSupplementalContextLength" to supplementalContextInfo.contentLength
289+
"codewhispererSupplementalContextLength" to supplementalContextInfo.contentLength,
290+
"codewhispererCharactersAccepted" to charCount
288291
)
289292
}
290293
}
291294

292295
@Test
293296
fun `sendUserDecisionEventForAll will send userDecision event for all suggestions`() {
294-
doNothing().whenever(sut).sendUserTriggerDecisionEvent(any(), any(), any(), any(), any(), any(), any())
297+
doNothing().whenever(sut).sendUserTriggerDecisionEvent(any(), any(), any(), any(), any(), any(), any(), any())
295298
val eventCount = mutableMapOf<CodewhispererSuggestionState, Int>()
296299
var totalEventCount = 0
297300
val requestContext = aRequestContext(projectRule.project)
@@ -463,6 +466,7 @@ class CodeWhispererTelemetryServiceTest {
463466
val expectedDuration = Duration.ofSeconds(1)
464467
val expectedSuggestionReferenceCount = 1
465468
val expectedGeneratedLineCount = 50
469+
val expectedCharCount = 100
466470
val expectedCompletionType = if (expectedRecommendationContext.details.any {
467471
it.completionType == CodewhispererCompletionType.Block
468472
}
@@ -476,7 +480,8 @@ class CodeWhispererTelemetryServiceTest {
476480
expectedSuggestionState,
477481
expectedDuration,
478482
expectedSuggestionReferenceCount,
479-
expectedGeneratedLineCount
483+
expectedGeneratedLineCount,
484+
expectedCharCount
480485
)
481486

482487
if (isProTier || isTelemetryEnabled) {

0 commit comments

Comments
 (0)