Skip to content

Commit 1947887

Browse files
authored
telemetry(amazonq): fix userTriggerDecision not being sent if service returns empty (#6053)
## Problem there are 2 scenarios where we consider "Empty" 1. empty list of suggestion : `[]` 2. non empty list of suggestion with empty content: `['', '']` Currently, only (2) will have plugins send out `userTriggerDecision` event whereas (1) doesn't. ## Solution --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent fb2b23e commit 1947887

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

packages/core/src/codewhisperer/service/recommendationHandler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ export class RecommendationHandler {
390390

391391
// send Empty userDecision event if user receives no recommendations in this session at all.
392392
if (invocationResult === 'Succeeded' && nextToken === '') {
393+
// case 1: empty list of suggestion []
393394
if (session.recommendations.length === 0) {
394395
session.requestIdList.push(requestId)
395396
// Received an empty list of recommendations
@@ -404,7 +405,8 @@ export class RecommendationHandler {
404405
session.requestContext.supplementalMetadata
405406
)
406407
}
407-
if (!this.hasAtLeastOneValidSuggestion(typedPrefix)) {
408+
// case 2: non empty list of suggestion but with (a) empty content or (b) non-matching typeahead
409+
else if (!this.hasAtLeastOneValidSuggestion(typedPrefix)) {
408410
this.reportUserDecisions(-1)
409411
}
410412
}

packages/core/src/codewhisperer/util/telemetryHelper.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ export class TelemetryHelper {
9999
language: CodewhispererLanguage,
100100
supplementalContextMetadata?: CodeWhispererSupplementalContext | undefined
101101
) {
102+
const selectedCustomization = getSelectedCustomization()
103+
102104
telemetry.codewhisperer_userDecision.emit({
103105
codewhispererCompletionType: 'Line',
104106
codewhispererGettingStartedTask: session.taskType,
@@ -117,6 +119,41 @@ export class TelemetryHelper {
117119
credentialStartUrl: AuthUtil.instance.startUrl,
118120
traceId: this.traceId,
119121
})
122+
123+
telemetry.codewhisperer_userTriggerDecision.emit({
124+
codewhispererAutomatedTriggerType: session.autoTriggerType,
125+
codewhispererClassifierResult: this.classifierResult,
126+
codewhispererClassifierThreshold: this.classifierThreshold,
127+
codewhispererCompletionType: 'Line',
128+
codewhispererCursorOffset: session.startCursorOffset,
129+
codewhispererCustomizationArn: selectedCustomization.arn === '' ? undefined : selectedCustomization.arn,
130+
codewhispererFeatureEvaluations: FeatureConfigProvider.instance.getFeatureConfigsTelemetry(),
131+
codewhispererFirstRequestId: requestIdList[0],
132+
codewhispererGettingStartedTask: session.taskType,
133+
codewhispererLanguage: language,
134+
codewhispererLineNumber: session.startPos.line,
135+
codewhispererPreviousSuggestionState: this.prevTriggerDecision,
136+
codewhispererSessionId: sessionId,
137+
codewhispererSuggestionCount: 0,
138+
codewhispererSuggestionImportCount: 0,
139+
codewhispererSuggestionState: 'Empty',
140+
codewhispererSupplementalContextIsUtg: supplementalContextMetadata?.isUtg,
141+
codewhispererSupplementalContextLength: supplementalContextMetadata?.contentsLength,
142+
// eslint-disable-next-line id-length
143+
codewhispererSupplementalContextStrategyId: supplementalContextMetadata?.strategy,
144+
codewhispererSupplementalContextTimeout: supplementalContextMetadata?.isProcessTimeout,
145+
codewhispererTimeSinceLastDocumentChange: this.timeSinceLastModification
146+
? this.timeSinceLastModification
147+
: undefined,
148+
codewhispererTimeSinceLastUserDecision: this.lastTriggerDecisionTime
149+
? performance.now() - this.lastTriggerDecisionTime
150+
: undefined,
151+
codewhispererTimeToFirstRecommendation: session.timeToFirstRecommendation,
152+
codewhispererTriggerType: session.triggerType,
153+
codewhispererTypeaheadLength: this.typeAheadLength,
154+
credentialStartUrl: AuthUtil.instance.startUrl,
155+
traceId: this.traceId,
156+
})
120157
}
121158

122159
/**

0 commit comments

Comments
 (0)