Skip to content

Commit 28168cb

Browse files
authored
telemetry(chat): request id and error message in error metric (aws#7045)
## Problem - do not have `requestID` and `errorMessage` in amazonq_messageResponseError ## Solution - emit amazonq_messageResponseError event with `requestID` and `errorMessage` --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent d636449 commit 28168cb

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

packages/core/src/codewhispererChat/controllers/chat/controller.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,26 @@ export class ChatController {
16511651

16521652
await this.messenger.sendAIResponse(response, session, tabID, triggerID, triggerPayload)
16531653
} catch (e: any) {
1654-
this.telemetryHelper.recordMessageResponseError(triggerPayload, tabID, getHttpStatusCode(e) ?? 0)
1654+
let errorMessage: string
1655+
let requestID: string | undefined
1656+
1657+
if (e instanceof CodeWhispererStreamingServiceException) {
1658+
errorMessage = e.message
1659+
requestID = e.$metadata.requestId
1660+
} else {
1661+
errorMessage = 'Error is not CodeWhispererStreamingServiceException. '
1662+
if (e instanceof Error || e?.message) {
1663+
errorMessage += `Error message is: ${e.message}`
1664+
}
1665+
}
1666+
1667+
this.telemetryHelper.recordMessageResponseError(
1668+
triggerPayload,
1669+
tabID,
1670+
getHttpStatusCode(e) ?? 0,
1671+
requestID,
1672+
errorMessage
1673+
)
16551674
// clears session, record telemetry before this call
16561675
this.processException(e, tabID)
16571676
}

packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,13 @@ export class Messenger {
540540

541541
followUps = []
542542
relatedSuggestions = []
543-
this.telemetryHelper.recordMessageResponseError(triggerPayload, tabID, errorInfo.statusCode ?? 0)
543+
this.telemetryHelper.recordMessageResponseError(
544+
triggerPayload,
545+
tabID,
546+
errorInfo.statusCode ?? 0,
547+
errorInfo.requestId,
548+
errorInfo.errorMessage
549+
)
544550
})
545551
.finally(async () => {
546552
if (session.sessionIdentifier && !this.isTriggerCancelled(triggerID)) {

packages/core/src/codewhispererChat/controllers/chat/telemetryHelper.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { TriggerEvent, TriggerEventsStorage } from '../../storages/triggerEvents
3838
import globals from '../../../shared/extensionGlobals'
3939
import { getLogger } from '../../../shared/logger/logger'
4040
import { codeWhispererClient } from '../../../codewhisperer/client/codewhisperer'
41-
import { isAwsError } from '../../../shared/errors'
41+
import { getTelemetryReasonDesc, isAwsError } from '../../../shared/errors'
4242
import { ChatMessageInteractionType } from '../../../codewhisperer/client/codewhispereruserclient'
4343
import { supportedLanguagesList } from '../chat/chatRequest/converter'
4444
import { AuthUtil } from '../../../codewhisperer/util/authUtil'
@@ -603,7 +603,13 @@ export class CWCTelemetryHelper {
603603
this.messageStorage.delete(tabID)
604604
}
605605

606-
public recordMessageResponseError(triggerPayload: TriggerPayload, tabID: string, responseCode: number) {
606+
public recordMessageResponseError(
607+
triggerPayload: TriggerPayload,
608+
tabID: string,
609+
responseCode: number,
610+
requestID?: string,
611+
errorReason?: string
612+
) {
607613
const triggerEvent = this.triggerEventsStorage.getLastTriggerEventByTabID(tabID)
608614

609615
telemetry.amazonq_messageResponseError.emit({
@@ -617,8 +623,10 @@ export class CWCTelemetryHelper {
617623
cwsprChatActiveEditorImportCount: triggerPayload.codeQuery?.fullyQualifiedNames?.used?.length,
618624
cwsprChatResponseCode: responseCode,
619625
cwsprChatRequestLength: triggerPayload.message?.length ?? 0,
620-
cwsprChatConversationType: 'Chat',
626+
cwsprChatConversationType: triggerPayload.origin ? 'AgenticChat' : 'Chat',
621627
credentialStartUrl: AuthUtil.instance.startUrl,
628+
requestId: requestID,
629+
reasonDesc: getTelemetryReasonDesc(errorReason),
622630
})
623631
}
624632

0 commit comments

Comments
 (0)