Skip to content

Commit dc531cd

Browse files
authored
telemetry(amazonq chat): numberOfCodeBlocks aws#4755
Problem The Q chat telemetry event recordAddMessage is missing the required parameter cwsprChatResponseCodeSnippetCount for AB testing. Solution Count the three back ticks(```) to find out total number of code blocks in the generated message response.
1 parent 92d513b commit dc531cd

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "Amazon Q Chat: Added metric parameters to recordAddMessage telemetry event."
4+
}

packages/core/src/codewhisperer/client/user-service-2.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@
344344
"timeBetweenChunks": { "shape": "TimeBetweenChunks" },
345345
"fullResponselatency": { "shape": "Double" },
346346
"requestLength": { "shape": "Integer" },
347-
"responseLength": { "shape": "Integer" }
347+
"responseLength": { "shape": "Integer" },
348+
"numberOfCodeBlocks": { "shape": "Integer" }
348349
}
349350
},
350351
"ChatHistory": {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ export class Messenger {
8989
)
9090
)
9191
}
92+
93+
public countTotalNumberOfCodeBlocks(message: string): number {
94+
if (message === undefined) {
95+
return 0
96+
}
97+
const countOfCodeBlocks = message.match(/^```/gm)
98+
const numberOfTripleBackTicksInMarkdown = countOfCodeBlocks ? countOfCodeBlocks.length : 0
99+
return Math.floor(numberOfTripleBackTicksInMarkdown / 2)
100+
}
101+
92102
public async sendAIResponse(
93103
response: GenerateAssistantResponseCommandOutput,
94104
session: ChatSession,
@@ -265,6 +275,7 @@ export class Messenger {
265275
messageID,
266276
responseCode,
267277
codeReferenceCount: codeReference.length,
278+
totalNumberOfCodeBlocksInResponse: this.countTotalNumberOfCodeBlocks(message),
268279
})
269280
})
270281
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export interface PromptAnswer {
7676
messageID: string
7777
responseCode: number
7878
codeReferenceCount: number
79+
totalNumberOfCodeBlocksInResponse: number
7980
}
8081

8182
export interface StopResponseMessage {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export class CWCTelemetryHelper {
321321
cwsprChatProgrammingLanguage: triggerPayload.fileLanguage,
322322
cwsprChatActiveEditorTotalCharacters: triggerPayload.fileText?.length,
323323
cwsprChatActiveEditorImportCount: triggerPayload.codeQuery?.fullyQualifiedNames?.used?.length,
324-
cwsprChatResponseCodeSnippetCount: 0, // TODO
324+
cwsprChatResponseCodeSnippetCount: message.totalNumberOfCodeBlocksInResponse,
325325
cwsprChatResponseCode: message.responseCode,
326326
cwsprChatSourceLinkCount: message.suggestionCount,
327327
cwsprChatReferencesCount: message.codeReferenceCount,
@@ -353,6 +353,7 @@ export class CWCTelemetryHelper {
353353
fullResponselatency: event.cwsprChatFullResponseLatency,
354354
requestLength: event.cwsprChatRequestLength,
355355
responseLength: event.cwsprChatResponseLength,
356+
numberOfCodeBlocks: event.cwsprChatResponseCodeSnippetCount,
356357
},
357358
},
358359
})

0 commit comments

Comments
 (0)