Skip to content

Commit d637201

Browse files
chungjacRandall-Jiang
authored andcommitted
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 5f64d90 commit d637201

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
@@ -1662,7 +1662,26 @@ export class ChatController {
16621662

16631663
await this.messenger.sendAIResponse(response, session, tabID, triggerID, triggerPayload)
16641664
} catch (e: any) {
1665-
this.telemetryHelper.recordMessageResponseError(triggerPayload, tabID, getHttpStatusCode(e) ?? 0)
1665+
let errorMessage: string
1666+
let requestID: string | undefined
1667+
1668+
if (e instanceof CodeWhispererStreamingServiceException) {
1669+
errorMessage = e.message
1670+
requestID = e.$metadata.requestId
1671+
} else {
1672+
errorMessage = 'Error is not CodeWhispererStreamingServiceException. '
1673+
if (e instanceof Error || e?.message) {
1674+
errorMessage += `Error message is: ${e.message}`
1675+
}
1676+
}
1677+
1678+
this.telemetryHelper.recordMessageResponseError(
1679+
triggerPayload,
1680+
tabID,
1681+
getHttpStatusCode(e) ?? 0,
1682+
requestID,
1683+
errorMessage
1684+
)
16661685
// clears session, record telemetry before this call
16671686
this.processException(e, tabID)
16681687
}

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)