-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
telemetry(amazonq): Measure e2e latency for amazon q requests
Problem: - We can't measure e2e how long a chat request takes Solution: - Plumb the trace id through to the webview -> vscode -> webview. This allows us to know exactly what is happening to a message and how long everything took to get there - chat e2e latency can be linked with the other telemetry events via the traceId
- Loading branch information
1 parent
3b44bcb
commit e7bd8a0
Showing
14 changed files
with
251 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { globals } from '../../shared' | ||
import { telemetry } from '../../shared/telemetry' | ||
import { Event, uiEventRecorder } from '../util/eventRecorder' | ||
|
||
export class AmazonQChatMessageDuration { | ||
/** | ||
* Record the initial requests in the chat message flow | ||
*/ | ||
static startListening(msg: { traceId: string; startTime: number; trigger?: string }) { | ||
const { traceId, startTime, trigger } = msg | ||
|
||
uiEventRecorder.set(traceId, { | ||
events: { | ||
chatMessageSent: startTime, | ||
}, | ||
}) | ||
uiEventRecorder.set(traceId, { | ||
events: { | ||
editorReceivedMessage: globals.clock.Date.now(), | ||
}, | ||
}) | ||
if (trigger) { | ||
uiEventRecorder.set(traceId, { | ||
trigger, | ||
}) | ||
} | ||
} | ||
|
||
/** | ||
* Stop listening to all incoming events and emit what we've found | ||
*/ | ||
static stopListening(msg: { traceId: string }) { | ||
const { traceId } = msg | ||
|
||
// We can't figure out what trace this event was associated with | ||
if (!traceId) { | ||
return | ||
} | ||
|
||
uiEventRecorder.set(traceId, { | ||
events: { | ||
messageDisplayed: globals.clock.Date.now(), | ||
}, | ||
}) | ||
|
||
const metrics = uiEventRecorder.get(traceId) | ||
|
||
// get events sorted by the time they were created | ||
const events = Object.entries(metrics.events) | ||
.map((x) => ({ | ||
event: x[0], | ||
duration: x[1], | ||
})) | ||
.sort((a, b) => { | ||
return a.duration - b.duration | ||
}) | ||
|
||
const chatMessageSentTime = events[events.length - 1].duration | ||
// Get the total duration by subtracting when the message was displayed and when the chat message was first sent | ||
const totalDuration = events[events.length - 1].duration - events[0].duration | ||
|
||
/** | ||
* Find the time it took to get between two metric events | ||
*/ | ||
const timings = new Map<Event, number>() | ||
for (let i = 1; i < events.length; i++) { | ||
const currentEvent = events[i] | ||
const previousEvent = events[i - 1] | ||
|
||
const timeDifference = currentEvent.duration - previousEvent.duration | ||
|
||
timings.set(currentEvent.event as Event, timeDifference) | ||
} | ||
|
||
telemetry.amazonq_chatRoundTrip.emit({ | ||
amazonqChatMessageSentTime: chatMessageSentTime, | ||
amazonqEditorReceivedMessageMs: timings.get('editorReceivedMessage') ?? -1, | ||
amazonqFeatureReceivedMessageMs: timings.get('featureReceivedMessage') ?? -1, | ||
amazonqMessageDisplayedMs: timings.get('messageDisplayed') ?? -1, | ||
source: metrics.trigger, | ||
duration: totalDuration, | ||
result: 'Succeeded', | ||
traceId, | ||
}) | ||
|
||
uiEventRecorder.delete(traceId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { RecordMap } from '../../shared/utilities/map' | ||
|
||
export type Event = | ||
| 'chatMessageSent' // initial on chat prompt event in the ui | ||
| 'editorReceivedMessage' // message gets from the chat prompt to VSCode | ||
| 'featureReceivedMessage' // message gets redirected from VSCode -> Partner team features implementation | ||
| 'messageDisplayed' // message gets received in the UI | ||
|
||
/** | ||
* For a given traceID, map an event to a time | ||
*/ | ||
export const uiEventRecorder = new RecordMap<{ | ||
trigger: string | ||
events: Partial<Record<Event, number>> | ||
}>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.