Repository navigation
feat(trace-view): Read web vitals from trace metrics - #133025
edwardgou-sentry wants to merge 4 commits into
Conversation
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.
c0c8cc4 to
e894889
Compare
| queryParams, | ||
| traceSlug, | ||
| }); | ||
| const tree = useTraceTree({trace, replay: null, webVitalMetrics}); |
There was a problem hiding this comment.
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
FromTraceexpands bounds for span-derived indicators, then assigns the resulting space totree.rootandtraceNodebefore collecting web-vital metrics.collectWebVitalMetricscomputes 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.indicatorsafter the bounds pass;Traceusesroot.spacefor its timeline, andbuild()does not recalculate that space.
Also found at 3 additional locations
static/app/views/performance/traceDetails/traceModels/traceTree.tsx:51-52static/app/views/performance/traceDetails/traceModels/traceTree.tsx:401-404static/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.
| const webVitalMetrics = useTraceWebVitalMetrics({ | ||
| enabled: organization.features.includes('dashboards-web-vitals-trace-metrics'), | ||
| queryParams, | ||
| traceSlug, | ||
| }); | ||
| const tree = useTraceTree({trace, replay: null, webVitalMetrics}); |
There was a problem hiding this comment.
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
useTraceWebVitalMetricsreturnsdata: result.data?.data ?? NO_ROWSwheneverenabledis true, so empty success and error both become[](useTraceWebVitalMetrics.tsx).useTraceTreepasses that array intoTraceTree.FromTraceaswebVitalMetrics.FromTracerunswithoutWebVitals(c.measurements)wheneveroptions.webVitalMetricsis truthy, and[]is truthy (traceTree.tsx).collectWebVitalMetricsonly runs whenoptions.webVitalMetrics?.lengthis 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}); |
There was a problem hiding this comment.
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.tsxpasses the fetched metric rows touseTraceTree, which builds the tree withcollectWebVitalMetrics. useTraceWebVitalMetricsrequests bothsentry.span_idandspan_id; the collector uses??, which does not fall back for an empty string.- The collector then skips the row because
spanIdis empty. The metrics sample link usesoldSpanId || spanIdfor 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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| 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 | ||
| ) | ||
| ); | ||
| } |
There was a problem hiding this comment.
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
collectTraceMeasurementsskips a non-standalone indicator only whentree.indicatorsalready has thattype(existingIndicatorIndex !== -1).collectWebVitalMetricsconcatenates each call's return value into a localindicatorsarray and never writes those markers ontotree.indicatorsbetween iterations.FromTraceonly doestree.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.indicatorsafter every node; the existing test expects a single LCP indicator when multiple spans carry LCP.
Identified by Warden · code-review · 8L7-H4R
Behind
dashboards-web-vitals-trace-metrics, the trace view queries the trace'sbrowser.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 bysentry.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