-
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: - Take an initial approach, see what works and what doesn't Original approach: - The original approach was to "listen" to all events coming out of telemetry. I think this is something we probably want to do eventually because it means we won't need to manually instrument flows ourselves but I think the integration needed to be more refined Current approach: - Plumb the trace id through to the webview -> vscode -> vscode. This allows us to know exactly what is happening to a message and how long everything took to get there
- Loading branch information
1 parent
5eea5f9
commit 22db33e
Showing
15 changed files
with
232 additions
and
13 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,88 @@ | ||
/*! | ||
* 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 { 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 | ||
}) | ||
|
||
// Get the total duration by subtracting the 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<string, 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, timeDifference) | ||
} | ||
|
||
telemetry.event_flow.emit({ | ||
name: metrics.trigger, | ||
duration: totalDuration, | ||
result: 'Succeeded', | ||
...Object.fromEntries(timings), | ||
} as any) | ||
|
||
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,22 @@ | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { MetricName } from '../../shared/telemetry/telemetry.gen' | ||
import { RecordMap } from '../../shared/utilities/map' | ||
|
||
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 | ||
| MetricName // any telemetry event emitted between when the partner teams code gets the original message to when its sent to the UI | ||
| '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
Oops, something went wrong.