Skip to content

Commit 36504d2

Browse files
authored
feat: add insightSetId to performance_analyze_insight (#518)
This should land with / after #508
1 parent 6af9133 commit 36504d2

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

docs/tool-reference.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,12 @@
215215

216216
### `performance_analyze_insight`
217217

218-
**Description:** Provides more detailed information on a specific Performance Insight that was highlighted in the results of a trace recording.
218+
**Description:** Provides more detailed information on a specific Performance Insight of an insight set that was highlighted in the results of a trace recording.
219219

220220
**Parameters:**
221221

222222
- **insightName** (string) **(required)**: The name of the Insight you want more information on. For example: "DocumentLatency" or "LCPBreakdown"
223+
- **insightSetId** (string) **(required)**: The id for the specific insight set. Only use the ids given in the "Available insight sets" list.
223224

224225
---
225226

src/tools/performance.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,17 @@ export const stopTrace = defineTool({
121121
export const analyzeInsight = defineTool({
122122
name: 'performance_analyze_insight',
123123
description:
124-
'Provides more detailed information on a specific Performance Insight that was highlighted in the results of a trace recording.',
124+
'Provides more detailed information on a specific Performance Insight of an insight set that was highlighted in the results of a trace recording.',
125125
annotations: {
126126
category: ToolCategory.PERFORMANCE,
127127
readOnlyHint: true,
128128
},
129129
schema: {
130+
insightSetId: zod
131+
.string()
132+
.describe(
133+
'The id for the specific insight set. Only use the ids given in the "Available insight sets" list.',
134+
),
130135
insightName: zod
131136
.string()
132137
.describe(
@@ -144,6 +149,7 @@ export const analyzeInsight = defineTool({
144149

145150
const insightOutput = getInsightOutput(
146151
lastRecording,
152+
request.params.insightSetId,
147153
request.params.insightName as InsightName,
148154
);
149155
if ('error' in insightOutput) {

src/trace-processing/parse.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export type InsightOutput = {output: string} | {error: string};
9797

9898
export function getInsightOutput(
9999
result: TraceResult,
100+
insightSetId: string,
100101
insightName: InsightName,
101102
): InsightOutput {
102103
if (!result.insights) {
@@ -105,27 +106,16 @@ export function getInsightOutput(
105106
};
106107
}
107108

108-
// Currently, we do not support inspecting traces with multiple navigations. We either:
109-
// 1. Find Insights from the first navigation (common case: user records a trace with a page reload to test load performance)
110-
// 2. Fall back to finding Insights not associated with a navigation (common case: user tests an interaction without a page load).
111-
const mainNavigationId =
112-
result.parsedTrace.data.Meta.mainFrameNavigations.at(0)?.args.data
113-
?.navigationId;
114-
115-
const insightsForNav = result.insights.get(
116-
mainNavigationId ?? TraceEngine.Types.Events.NO_NAVIGATION,
117-
);
118-
119-
if (!insightsForNav) {
109+
const insightSet = result.insights.get(insightSetId);
110+
if (!insightSet) {
120111
return {
121-
error: 'No Performance Insights for this trace.',
112+
error:
113+
'No Performance Insights for the given insight set id. Only use ids given in the "Available insight sets" list.',
122114
};
123115
}
124116

125117
const matchingInsight =
126-
insightName in insightsForNav.model
127-
? insightsForNav.model[insightName]
128-
: null;
118+
insightName in insightSet.model ? insightSet.model[insightName] : null;
129119
if (!matchingInsight) {
130120
return {
131121
error: `No Insight with the name ${insightName} found. Double check the name you provided is accurate and try again.`,

tests/tools/performance.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ describe('performance', () => {
158158
await analyzeInsight.handler(
159159
{
160160
params: {
161+
insightSetId: '8463DF94CD61B265B664E7F768183DE3',
161162
insightName: 'LCPBreakdown',
162163
},
163164
},
@@ -178,6 +179,7 @@ describe('performance', () => {
178179
await analyzeInsight.handler(
179180
{
180181
params: {
182+
insightSetId: '8463DF94CD61B265B664E7F768183DE3',
181183
insightName: 'MadeUpInsightName',
182184
},
183185
},
@@ -197,6 +199,7 @@ describe('performance', () => {
197199
await analyzeInsight.handler(
198200
{
199201
params: {
202+
insightSetId: '8463DF94CD61B265B664E7F768183DE3',
200203
insightName: 'LCPBreakdown',
201204
},
202205
},

0 commit comments

Comments
 (0)