Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "Amazon Q Chat: Added metric parameters to recordAddMessage telemetry event."
}
3 changes: 2 additions & 1 deletion packages/core/src/codewhisperer/client/user-service-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@
"timeBetweenChunks": { "shape": "TimeBetweenChunks" },
"fullResponselatency": { "shape": "Double" },
"requestLength": { "shape": "Integer" },
"responseLength": { "shape": "Integer" }
"responseLength": { "shape": "Integer" },
"numberOfCodeBlocks": { "shape": "Integer" }
}
},
"ChatHistory": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { OnboardingPageInteraction } from '../../../../amazonq/onboardingPage/mo
import { FeatureAuthState } from '../../../../codewhisperer/util/authUtil'
import { AuthFollowUpType, expiredText, enableQText, reauthenticateText } from '../../../../amazonq/auth/model'
import { userGuideURL } from '../../../../amazonq/webview/ui/texts/constants'
import { marked } from 'marked'

export type StaticTextResponseType = 'quick-action-help' | 'onboarding-help' | 'transform' | 'help'

Expand Down Expand Up @@ -88,6 +89,21 @@ export class Messenger {
)
)
}

public async countTotalNumberOfCodeBlocks(message: string): Promise<number> {
if (message === undefined) {
return 0
}

// To Convert Markdown text to HTML using marked library
const html = await marked(message)

// Count the number of <pre> tags in the HTML to find the total number of code blocks
const totalNumberOfCodeBlocks = (html.match(/<pre>/g) || []).length

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not specific enough - it could match unrelated <pre> tags.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion would be jsdom and the method querySelectorAll with a query of pre > code to find all code blocks


return totalNumberOfCodeBlocks
}

public async sendAIResponse(
response: GenerateAssistantResponseCommandOutput,
session: ChatSession,
Expand Down Expand Up @@ -214,7 +230,7 @@ export class Messenger {
relatedSuggestions = []
this.telemetryHelper.recordMessageResponseError(triggerPayload, tabID, statusCode ?? 0)
})
.finally(() => {
.finally(async () => {
if (relatedSuggestions.length !== 0) {
this.dispatcher.sendChatMessage(
new ChatMessage(
Expand Down Expand Up @@ -264,6 +280,7 @@ export class Messenger {
messageID,
responseCode,
codeReferenceCount: codeReference.length,
totalNumberOfCodeBlocksInResponse: await this.countTotalNumberOfCodeBlocks(message),
})
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export interface PromptAnswer {
messageID: string
responseCode: number
codeReferenceCount: number
totalNumberOfCodeBlocksInResponse: number
}

export interface StopResponseMessage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export class CWCTelemetryHelper {
cwsprChatProgrammingLanguage: triggerPayload.fileLanguage,
cwsprChatActiveEditorTotalCharacters: triggerPayload.fileText?.length,
cwsprChatActiveEditorImportCount: triggerPayload.codeQuery?.fullyQualifiedNames?.used?.length,
cwsprChatResponseCodeSnippetCount: 0, // TODO
cwsprChatResponseCodeSnippetCount: message.totalNumberOfCodeBlocksInResponse,
cwsprChatResponseCode: message.responseCode,
cwsprChatSourceLinkCount: message.suggestionCount,
cwsprChatReferencesCount: message.codeReferenceCount,
Expand Down Expand Up @@ -353,6 +353,7 @@ export class CWCTelemetryHelper {
fullResponselatency: event.cwsprChatFullResponseLatency,
requestLength: event.cwsprChatRequestLength,
responseLength: event.cwsprChatResponseLength,
numberOfCodeBlocks: event.cwsprChatResponseCodeSnippetCount,
},
},
})
Expand Down