Skip to content

Commit c3f0218

Browse files
committed
record invocation only when API was called
1 parent cbb8916 commit c3f0218

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/codewhisperer/service/recommendationHandler.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export class RecommendationHandler {
121121
let nextToken = ''
122122
let errorCode = ''
123123
let req: codewhispererClient.ListRecommendationsRequest | codewhispererClient.GenerateRecommendationsRequest
124+
let shouldRecordServiceInvocation = false
124125

125126
if (pagination) {
126127
req = EditorContext.buildListRecommendationRequest(editor as vscode.TextEditor, this.nextToken)
@@ -141,6 +142,7 @@ export class RecommendationHandler {
141142
const codewhispererPromise = pagination
142143
? client.listRecommendations(req)
143144
: client.generateRecommendations(req)
145+
shouldRecordServiceInvocation = true
144146
const resp = await this.getServerResponse(
145147
triggerType,
146148
config.isManualTriggerEnabled,
@@ -217,24 +219,25 @@ export class RecommendationHandler {
217219
recommendation.forEach((item, index) => {
218220
getLogger().verbose(`[${index}]\n${item.content.trimRight()}`)
219221
})
220-
221-
telemetry.recordCodewhispererServiceInvocation({
222-
codewhispererRequestId: requestId ? requestId : undefined,
223-
codewhispererSessionId: sessionId ? sessionId : undefined,
224-
codewhispererLastSuggestionIndex: this.recommendations.length - 1,
225-
codewhispererTriggerType: triggerType,
226-
codewhispererAutomatedTriggerType: autoTriggerType,
227-
codewhispererCompletionType:
228-
invocationResult == 'Succeeded' ? TelemetryHelper.instance.completionType : undefined,
229-
result: invocationResult,
230-
duration: latency ? latency : 0,
231-
codewhispererLineNumber: this.startPos.line ? this.startPos.line : 0,
232-
codewhispererCursorOffset: TelemetryHelper.instance.cursorOffset
233-
? TelemetryHelper.instance.cursorOffset
234-
: 0,
235-
codewhispererLanguage: languageContext.language,
236-
reason: reason ? reason.substring(0, 200) : undefined,
237-
})
222+
if (shouldRecordServiceInvocation) {
223+
telemetry.recordCodewhispererServiceInvocation({
224+
codewhispererRequestId: requestId ? requestId : undefined,
225+
codewhispererSessionId: sessionId ? sessionId : undefined,
226+
codewhispererLastSuggestionIndex: this.recommendations.length - 1,
227+
codewhispererTriggerType: triggerType,
228+
codewhispererAutomatedTriggerType: autoTriggerType,
229+
codewhispererCompletionType:
230+
invocationResult == 'Succeeded' ? TelemetryHelper.instance.completionType : undefined,
231+
result: invocationResult,
232+
duration: latency ? latency : 0,
233+
codewhispererLineNumber: this.startPos.line ? this.startPos.line : 0,
234+
codewhispererCursorOffset: TelemetryHelper.instance.cursorOffset
235+
? TelemetryHelper.instance.cursorOffset
236+
: 0,
237+
codewhispererLanguage: languageContext.language,
238+
reason: reason ? reason.substring(0, 200) : undefined,
239+
})
240+
}
238241
recommendation = recommendation.filter(r => r.content.length > 0)
239242

240243
if (config.isIncludeSuggestionsWithCodeReferencesEnabled === false) {

0 commit comments

Comments
 (0)