diff --git a/docs/tool-reference.md b/docs/tool-reference.md index 72a41da7c..0e126b8c3 100644 --- a/docs/tool-reference.md +++ b/docs/tool-reference.md @@ -215,11 +215,12 @@ ### `performance_analyze_insight` -**Description:** Provides more detailed information on a specific Performance Insight that was highlighted in the results of a trace recording. +**Description:** Provides more detailed information on a specific Performance Insight of an insight set that was highlighted in the results of a trace recording. **Parameters:** - **insightName** (string) **(required)**: The name of the Insight you want more information on. For example: "DocumentLatency" or "LCPBreakdown" +- **insightSetId** (string) **(required)**: The id for the specific insight set. Only use the ids given in the "Available insight sets" list. --- diff --git a/src/tools/performance.ts b/src/tools/performance.ts index 420a62132..a8b24903c 100644 --- a/src/tools/performance.ts +++ b/src/tools/performance.ts @@ -121,12 +121,17 @@ export const stopTrace = defineTool({ export const analyzeInsight = defineTool({ name: 'performance_analyze_insight', description: - 'Provides more detailed information on a specific Performance Insight that was highlighted in the results of a trace recording.', + 'Provides more detailed information on a specific Performance Insight of an insight set that was highlighted in the results of a trace recording.', annotations: { category: ToolCategory.PERFORMANCE, readOnlyHint: true, }, schema: { + insightSetId: zod + .string() + .describe( + 'The id for the specific insight set. Only use the ids given in the "Available insight sets" list.', + ), insightName: zod .string() .describe( @@ -144,6 +149,7 @@ export const analyzeInsight = defineTool({ const insightOutput = getInsightOutput( lastRecording, + request.params.insightSetId, request.params.insightName as InsightName, ); if ('error' in insightOutput) { diff --git a/src/trace-processing/parse.ts b/src/trace-processing/parse.ts index 23e195764..cbd79462e 100644 --- a/src/trace-processing/parse.ts +++ b/src/trace-processing/parse.ts @@ -97,6 +97,7 @@ export type InsightOutput = {output: string} | {error: string}; export function getInsightOutput( result: TraceResult, + insightSetId: string, insightName: InsightName, ): InsightOutput { if (!result.insights) { @@ -105,27 +106,16 @@ export function getInsightOutput( }; } - // Currently, we do not support inspecting traces with multiple navigations. We either: - // 1. Find Insights from the first navigation (common case: user records a trace with a page reload to test load performance) - // 2. Fall back to finding Insights not associated with a navigation (common case: user tests an interaction without a page load). - const mainNavigationId = - result.parsedTrace.data.Meta.mainFrameNavigations.at(0)?.args.data - ?.navigationId; - - const insightsForNav = result.insights.get( - mainNavigationId ?? TraceEngine.Types.Events.NO_NAVIGATION, - ); - - if (!insightsForNav) { + const insightSet = result.insights.get(insightSetId); + if (!insightSet) { return { - error: 'No Performance Insights for this trace.', + error: + 'No Performance Insights for the given insight set id. Only use ids given in the "Available insight sets" list.', }; } const matchingInsight = - insightName in insightsForNav.model - ? insightsForNav.model[insightName] - : null; + insightName in insightSet.model ? insightSet.model[insightName] : null; if (!matchingInsight) { return { error: `No Insight with the name ${insightName} found. Double check the name you provided is accurate and try again.`, diff --git a/tests/tools/performance.test.ts b/tests/tools/performance.test.ts index b8ac55338..0c3cb6584 100644 --- a/tests/tools/performance.test.ts +++ b/tests/tools/performance.test.ts @@ -158,6 +158,7 @@ describe('performance', () => { await analyzeInsight.handler( { params: { + insightSetId: '8463DF94CD61B265B664E7F768183DE3', insightName: 'LCPBreakdown', }, }, @@ -178,6 +179,7 @@ describe('performance', () => { await analyzeInsight.handler( { params: { + insightSetId: '8463DF94CD61B265B664E7F768183DE3', insightName: 'MadeUpInsightName', }, }, @@ -197,6 +199,7 @@ describe('performance', () => { await analyzeInsight.handler( { params: { + insightSetId: '8463DF94CD61B265B664E7F768183DE3', insightName: 'LCPBreakdown', }, },