Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/tool-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---

Expand Down
8 changes: 7 additions & 1 deletion src/tools/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -144,6 +149,7 @@ export const analyzeInsight = defineTool({

const insightOutput = getInsightOutput(
lastRecording,
request.params.insightSetId,
request.params.insightName as InsightName,
);
if ('error' in insightOutput) {
Expand Down
22 changes: 6 additions & 16 deletions src/trace-processing/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export type InsightOutput = {output: string} | {error: string};

export function getInsightOutput(
result: TraceResult,
insightSetId: string,
insightName: InsightName,
): InsightOutput {
if (!result.insights) {
Expand All @@ -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.`,
Expand Down
3 changes: 3 additions & 0 deletions tests/tools/performance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ describe('performance', () => {
await analyzeInsight.handler(
{
params: {
insightSetId: '8463DF94CD61B265B664E7F768183DE3',
insightName: 'LCPBreakdown',
},
},
Expand All @@ -178,6 +179,7 @@ describe('performance', () => {
await analyzeInsight.handler(
{
params: {
insightSetId: '8463DF94CD61B265B664E7F768183DE3',
insightName: 'MadeUpInsightName',
},
},
Expand All @@ -197,6 +199,7 @@ describe('performance', () => {
await analyzeInsight.handler(
{
params: {
insightSetId: '8463DF94CD61B265B664E7F768183DE3',
insightName: 'LCPBreakdown',
},
},
Expand Down