Skip to content

feat(trace-view): Read web vitals from trace metrics - #133025

Draft
edwardgou-sentry wants to merge 4 commits into
masterfrom
edwardgou-sentry/feat/trace-view-web-vital-metrics
Draft

edwardgou-sentry wants to merge 4 commits into
masterfrom
edwardgou-sentry/feat/trace-view-web-vital-metrics

Conversation

@edwardgou-sentry

@edwardgou-sentry edwardgou-sentry commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Behind dashboards-web-vitals-trace-metrics, the trace view queries the trace's browser.web_vital.* metrics and reads its web vitals from them instead of the spans: the waterfall markers and the vitals section come from the metric rows, matched to nodes by sentry.span_id. Span web vital measurements are ignored under the flag; mobile vitals still come from spans. The tree waits for the metrics before it builds.

The flag check is page-local for now. ENG-9200 replaces it with the shared dataset hook.

Refs ENG-9199

@linear-code

linear-code Bot commented Dec 1, 2026

Copy link
Copy Markdown

ENG-9199

@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Dec 1, 2026
Behind the dashboards-web-vitals-trace-metrics flag, the trace view queries the web vital metrics of the trace and adds them to the nodes they were measured on.
The span_id alias is empty on trace metrics; Relay writes sentry.span_id.
queryParams,
traceSlug,
});
const tree = useTraceTree({trace, replay: null, webVitalMetrics});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Web-vital metrics beyond the last span fall outside the trace timeline

When a metric’s computed timestamp is later than the last span, FromTrace adds its indicator after setting root.space and traceNode.space, without expanding those bounds. The marker is then positioned beyond the trace timeline instead of being included in its time range.

Evidence
  • FromTrace expands bounds for span-derived indicators, then assigns the resulting space to tree.root and traceNode before collecting web-vital metrics.
  • collectWebVitalMetrics computes metric timestamps from the trace origin plus the metric value in milliseconds, so a metric timestamp can exceed the span-derived end.
  • The metrics are added to tree.indicators after the bounds pass; Trace uses root.space for its timeline, and build() does not recalculate that space.
Also found at 3 additional locations
  • static/app/views/performance/traceDetails/traceModels/traceTree.tsx:51-52
  • static/app/views/performance/traceDetails/traceModels/traceTree.tsx:401-404
  • static/app/views/performance/traceDetails/traceModels/traceTree.tsx:556-560

Identified by Warden · code-review · H5K-TVU

Span web vital measurements are skipped under the flag; mobile vitals still come from spans.
Comment on lines +114 to +119
const webVitalMetrics = useTraceWebVitalMetrics({
enabled: organization.features.includes('dashboards-web-vitals-trace-metrics'),
queryParams,
traceSlug,
});
const tree = useTraceTree({trace, replay: null, webVitalMetrics});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty metrics result strips span web vitals

When the flag is on and the metrics query returns no rows or fails, webVitalMetrics is [], which is truthy for withoutWebVitals but falsy for collectWebVitalMetrics, so span web vitals are removed and nothing replaces them.

Evidence
  • useTraceWebVitalMetrics returns data: result.data?.data ?? NO_ROWS whenever enabled is true, so empty success and error both become [] (useTraceWebVitalMetrics.tsx).
  • useTraceTree passes that array into TraceTree.FromTrace as webVitalMetrics.
  • FromTrace runs withoutWebVitals(c.measurements) whenever options.webVitalMetrics is truthy, and [] is truthy (traceTree.tsx).
  • collectWebVitalMetrics only runs when options.webVitalMetrics?.length is non-zero, so an empty array never restores vitals.
  • The PR contract says traces that still carry web vital spans should keep those values.

Identified by Warden · code-review · 7D7-4FD

queryParams,
traceSlug,
});
const tree = useTraceTree({trace, replay: null, webVitalMetrics});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty legacy span IDs prevent fallback to span_id

When a metric row has an empty sentry.span_id and a populated span_id, the nullish fallback keeps the empty value, so the vital is not attached to any trace node.

Evidence
  • With the feature enabled, index.tsx passes the fetched metric rows to useTraceTree, which builds the tree with collectWebVitalMetrics.
  • useTraceWebVitalMetrics requests both sentry.span_id and span_id; the collector uses ??, which does not fall back for an empty string.
  • The collector then skips the row because spanId is empty. The metrics sample link uses oldSpanId || spanId for the same fields, confirming that an empty legacy ID needs the fallback.

Identified by Warden · code-review · N7M-C96

Metrics with no matching span were dropped. The first row per vital now wins.
@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
scraps Error Error Dec 3, 2026 4:18am UTC

Request Review

Comment on lines +235 to +247
let indicators: TraceTree.Indicator[] = [];
for (const [node, nodeMeasurements] of measurements) {
indicators = indicators.concat(
collectTraceMeasurements(
tree,
node,
traceNode.traceOrigin || node.space[0],
nodeMeasurements,
tree.vitals,
tree.vital_types
)
);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collectWebVitalMetrics emits duplicate waterfall markers for the same vital

When the same web vital exists on multiple nodes, each collectTraceMeasurements call only dedupes against tree.indicators, so later nodes still contribute markers to the local array and the waterfall shows duplicate LCP/FCP/TTFB indicators. Append each batch to tree.indicators inside the loop (matching FromTrace's span path) before continuing.

Evidence
  • collectTraceMeasurements skips a non-standalone indicator only when tree.indicators already has that type (existingIndicatorIndex !== -1).
  • collectWebVitalMetrics concatenates each call's return value into a local indicators array and never writes those markers onto tree.indicators between iterations.
  • FromTrace only does tree.indicators = tree.indicators.concat(collectWebVitalMetrics(...)) after the full return, so N nodes with LCP produce N LCP markers.
  • The span path avoids this by concatenating onto tree.indicators after every node; the existing test expects a single LCP indicator when multiple spans carry LCP.

Identified by Warden · code-review · 8L7-H4R

This branch was successfully deployed

2 active (1 outdated) deployments
Preview – sentry — d89e332c Deployed Dec 3, 2026 by vercel[bot]
Preview — 8b0f0747 Deployed Dec 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant