Skip to content

Commit dc4887c

Browse files
authored
telemetry(amazonq): Create server request metrics that include conversation id creation (#5839)
## Problem - The full server response metrics don't include the ~2 seconds to create the conversation id, it just handles everything between after the conversation id was created ## Solution - Create new metrics that include the conversation id creation data
1 parent 4d7431f commit dc4887c

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ export class ChatController {
660660
session.createNewTokenSource()
661661
try {
662662
this.messenger.sendInitalStream(tabID, triggerID)
663+
this.telemetryHelper.setConversationStreamStartTime(tabID)
663664
response = await session.chat(request)
664665
this.telemetryHelper.recordEnterFocusConversation(triggerEvent.tabID)
665666
this.telemetryHelper.recordStartConversation(triggerEvent, triggerPayload)

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export class CWCTelemetryHelper {
6565
private triggerEventsStorage: TriggerEventsStorage
6666
private responseStreamStartTime: Map<string, number> = new Map()
6767
private responseStreamTotalTime: Map<string, number> = new Map()
68+
private conversationStreamStartTime: Map<string, number> = new Map()
69+
private conversationStreamTotalTime: Map<string, number> = new Map()
6870
private responseStreamTimeForChunks: Map<string, number[]> = new Map()
6971
private responseWithProjectContext: Map<string, boolean> = new Map()
7072

@@ -447,7 +449,9 @@ export class CWCTelemetryHelper {
447449
this.getTimeBetweenChunks(message.tabID, this.responseStreamTimeForChunks)
448450
),
449451
cwsprChatFullResponseLatency: this.responseStreamTotalTime.get(message.tabID) ?? 0,
450-
cwsprTimeToFirstDisplay: this.getFirstDisplayTime(tabID, startTime),
452+
cwsprChatTimeToFirstDisplay: this.getFirstDisplayTime(tabID, startTime),
453+
cwsprChatTimeFirstUsableChunk: this.getFirstUsableChunkTime(message.tabID) ?? 0,
454+
cwsprChatFullServerResponseLatency: this.conversationStreamTotalTime.get(message.tabID) ?? 0,
451455
cwsprChatTimeBetweenDisplays: JSON.stringify(this.getTimeBetweenChunks(tabID, this.displayTimeForChunks)),
452456
cwsprChatFullDisplayLatency: fullDisplayLatency,
453457
cwsprChatRequestLength: triggerPayload.message?.length ?? 0,
@@ -549,6 +553,10 @@ export class CWCTelemetryHelper {
549553
this.responseWithProjectContext.set(messageId, true)
550554
}
551555

556+
public setConversationStreamStartTime(tabID: string) {
557+
this.conversationStreamStartTime.set(tabID, performance.now())
558+
}
559+
552560
private getResponseStreamTimeToFirstChunk(tabID: string): number {
553561
const chunkTimes = this.responseStreamTimeForChunks.get(tabID) ?? [0, 0]
554562
if (chunkTimes.length === 1) {
@@ -568,6 +576,13 @@ export class CWCTelemetryHelper {
568576
return Math.round(chunkTimes[0] - startTime)
569577
}
570578

579+
private getFirstUsableChunkTime(tabID: string) {
580+
const startTime = this.conversationStreamStartTime.get(tabID) ?? 0
581+
const chunkTimes = this.responseStreamTimeForChunks.get(tabID) ?? [0, 0]
582+
// first chunk is the start time, we use the second because thats the first actual usable chunk time
583+
return Math.round(chunkTimes[1] - startTime)
584+
}
585+
571586
private getTimeBetweenChunks(tabID: string, chunks: Map<string, number[]>): number[] {
572587
try {
573588
const chunkDeltaTimes: number[] = []
@@ -584,8 +599,13 @@ export class CWCTelemetryHelper {
584599
}
585600

586601
public setResponseStreamTotalTime(tabID: string) {
587-
const totalTime = performance.now() - (this.responseStreamStartTime.get(tabID) ?? 0)
588-
this.responseStreamTotalTime.set(tabID, Math.round(totalTime))
602+
// time from when the requests started streaming until the end of the stream
603+
const totalStreamingTime = performance.now() - (this.responseStreamStartTime.get(tabID) ?? 0)
604+
this.responseStreamTotalTime.set(tabID, Math.round(totalStreamingTime))
605+
606+
// time from the initial server request, including creating the conversation id, until the end of the stream
607+
const totalConversationTime = performance.now() - (this.conversationStreamStartTime.get(tabID) ?? 0)
608+
this.conversationStreamTotalTime.set(tabID, Math.round(totalConversationTime))
589609
}
590610

591611
public getConversationId(tabID: string): string | undefined {

packages/core/src/shared/telemetry/vscodeTelemetry.json

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
{
158158
"name": "cwsprChatTimeToFirstChunk",
159159
"type": "int",
160-
"description": "The time between the initial server request and when we got back the first usable result"
160+
"description": "The time between when the conversation id was created and when we got back the first usable result"
161161
},
162162
{
163163
"name": "cwsprChatTimeBetweenChunks",
@@ -167,10 +167,20 @@
167167
{
168168
"name": "cwsprChatFullResponseLatency",
169169
"type": "int",
170-
"description": "The time between the initial server request and the final response from the server"
170+
"description": "The time between when the conversation id was created and the final response from the server was received"
171171
},
172172
{
173-
"name": "cwsprTimeToFirstDisplay",
173+
"name": "cwsprChatTimeFirstUsableChunk",
174+
"type": "int",
175+
"description": "The time between the initial server request, including creating the conversation id, and the first usable result"
176+
},
177+
{
178+
"name": "cwsprChatFullServerResponseLatency",
179+
"type": "int",
180+
"description": "The time between the initial server request, including creating the conversation id, and the final response from the server"
181+
},
182+
{
183+
"name": "cwsprChatTimeToFirstDisplay",
174184
"type": "int",
175185
"description": "The time between the user pressing enter and when the first chunk of data is displayed to the user"
176186
},
@@ -753,7 +763,13 @@
753763
"type": "cwsprChatFullResponseLatency"
754764
},
755765
{
756-
"type": "cwsprTimeToFirstDisplay"
766+
"type": "cwsprChatTimeFirstUsableChunk"
767+
},
768+
{
769+
"type": "cwsprChatFullServerResponseLatency"
770+
},
771+
{
772+
"type": "cwsprChatTimeToFirstDisplay"
757773
},
758774
{
759775
"type": "cwsprChatFullDisplayLatency"

0 commit comments

Comments
 (0)