in packages/core/src/codewhispererChat/controllers/chat/telemetryHelper.ts [486:587]
public emitAddMessage(tabID: string, fullDisplayLatency: number, traceId: string, startTime?: number) {
const payload = this.messageStorage.get(tabID)
if (!payload) {
return
}
const { triggerPayload, message } = payload
const triggerEvent = this.triggerEventsStorage.getLastTriggerEventByTabID(message.tabID)
const hasProjectLevelContext =
triggerPayload.relevantTextDocuments &&
triggerPayload.relevantTextDocuments.length > 0 &&
triggerPayload.useRelevantDocuments === true
const contextCounts = this.getAdditionalContextCounts(triggerPayload)
const event: AmazonqAddMessage = {
result: 'Succeeded',
cwsprChatConversationId: this.getConversationId(message.tabID) ?? '',
cwsprChatMessageId: message.messageID,
cwsprChatTriggerInteraction: this.getTriggerInteractionFromTriggerEvent(triggerEvent),
cwsprChatUserIntent: this.getUserIntentForTelemetry(triggerPayload.userIntent),
cwsprChatHasCodeSnippet: triggerPayload.codeSelection && !triggerPayload.codeSelection.isEmpty,
cwsprChatProgrammingLanguage: triggerPayload.fileLanguage,
cwsprChatActiveEditorTotalCharacters: triggerPayload.fileText.length,
cwsprChatActiveEditorImportCount: triggerPayload.codeQuery?.fullyQualifiedNames?.used?.length,
cwsprChatResponseCodeSnippetCount: message.totalNumberOfCodeBlocksInResponse,
cwsprChatResponseCode: message.responseCode,
cwsprChatSourceLinkCount: message.suggestionCount,
cwsprChatReferencesCount: message.codeReferenceCount,
cwsprChatFollowUpCount: message.followUpCount,
cwsprChatTimeToFirstChunk: this.getResponseStreamTimeToFirstChunk(message.tabID),
cwsprChatTimeBetweenChunks: JSON.stringify(
this.getTimeBetweenChunks(message.tabID, this.responseStreamTimeForChunks)
),
cwsprChatFullResponseLatency: this.responseStreamTotalTime.get(message.tabID) ?? 0,
cwsprChatTimeToFirstDisplay: this.getFirstDisplayTime(tabID, startTime),
cwsprChatTimeToFirstUsableChunk: this.getFirstUsableChunkTime(message.tabID) ?? 0,
cwsprChatFullServerResponseLatency: this.conversationStreamTotalTime.get(message.tabID) ?? 0,
cwsprChatTimeBetweenDisplays: JSON.stringify(this.getTimeBetweenChunks(tabID, this.displayTimeForChunks)),
cwsprChatFullDisplayLatency: fullDisplayLatency,
cwsprChatRequestLength: triggerPayload.message.length,
cwsprChatResponseLength: message.messageLength,
cwsprChatConversationType: 'Chat',
credentialStartUrl: AuthUtil.instance.startUrl,
codewhispererCustomizationArn: triggerPayload.customization.arn,
cwsprChatHasProjectContext: hasProjectLevelContext,
cwsprChatHasContextList: triggerPayload.documentReferences.length > 0,
cwsprChatFolderContextCount: contextCounts.folderContextCount,
cwsprChatFileContextCount: contextCounts.fileContextCount,
cwsprChatFileContextLength: triggerPayload.contextLengths.additionalContextLengths.fileContextLength,
cwsprChatFileContextTruncatedLength:
triggerPayload.contextLengths.truncatedAdditionalContextLengths.fileContextLength,
cwsprChatRuleContextCount: triggerPayload.workspaceRulesCount,
cwsprChatRuleContextLength: triggerPayload.contextLengths.additionalContextLengths.ruleContextLength,
cwsprChatRuleContextTruncatedLength:
triggerPayload.contextLengths.truncatedAdditionalContextLengths.ruleContextLength,
cwsprChatPromptContextCount: contextCounts.promptContextCount,
cwsprChatPromptContextLength: triggerPayload.contextLengths.additionalContextLengths.promptContextLength,
cwsprChatPromptContextTruncatedLength:
triggerPayload.contextLengths.truncatedAdditionalContextLengths.promptContextLength,
cwsprChatFocusFileContextLength: triggerPayload.contextLengths.focusFileContextLength,
cwsprChatFocusFileContextTruncatedLength: triggerPayload.contextLengths.truncatedFocusFileContextLength,
cwsprChatUserInputContextLength: triggerPayload.contextLengths.userInputContextLength,
cwsprChatUserInputContextTruncatedLength: triggerPayload.contextLengths.truncatedUserInputContextLength,
cwsprChatWorkspaceContextLength: triggerPayload.contextLengths.workspaceContextLength,
cwsprChatWorkspaceContextTruncatedLength: triggerPayload.contextLengths.truncatedWorkspaceContextLength,
traceId,
}
telemetry.amazonq_addMessage.emit(event)
const language = this.isProgrammingLanguageSupported(triggerPayload.fileLanguage)
? { languageName: triggerPayload.fileLanguage as string }
: undefined
codeWhispererClient
.sendTelemetryEvent({
telemetryEvent: {
chatAddMessageEvent: {
conversationId: event.cwsprChatConversationId,
messageId: event.cwsprChatMessageId,
userIntent: triggerPayload.userIntent,
hasCodeSnippet: event.cwsprChatHasCodeSnippet,
...(language !== undefined ? { programmingLanguage: language } : {}),
activeEditorTotalCharacters: event.cwsprChatActiveEditorTotalCharacters,
timeToFirstChunkMilliseconds: event.cwsprChatTimeToFirstChunk,
timeBetweenChunks: this.getTimeBetweenChunks(message.tabID, this.responseStreamTimeForChunks),
fullResponselatency: event.cwsprChatFullResponseLatency,
requestLength: event.cwsprChatRequestLength,
responseLength: event.cwsprChatResponseLength,
numberOfCodeBlocks: event.cwsprChatResponseCodeSnippetCount,
hasProjectLevelContext: hasProjectLevelContext,
customizationArn: undefinedIfEmpty(getSelectedCustomization().arn),
},
},
profileArn: AuthUtil.instance.regionProfileManager.activeRegionProfile?.arn,
})
.then()
.catch(logSendTelemetryEventFailure)
this.messageStorage.delete(tabID)
}