Commit d8288b1
feat: emit element-selector attribution on web-vitals metrics (#515)
## Summary
Switches the SDK's web-vitals listener from the plain `web-vitals` build
to `web-vitals/attribution` so we can attribute each LCP / CLS / INP /
FID to a specific DOM element. The selector and a couple of high-signal
context fields are emitted as OTel attributes on the gauge metric,
closing a feature parity gap with Datadog RUM's `_target_selector`.
Attribute keys (kept tight to limit cardinality):
- LCP: `web_vital.element`, `web_vital.attribution.url` (sanitized)
- CLS: `web_vital.element` (largest-shift target),
`web_vital.load_state`
- INP: `web_vital.element` (event target), `web_vital.event_type`,
`web_vital.load_state`
- FID: `web_vital.element`, `web_vital.event_type`
- FCP: `web_vital.load_state`
- TTFB: no element-level attribute (timing breakdown is already in the
value)
Both consumers (`sdk/observe.ts` and `client/index.tsx`) get the new
attributes; their existing differing shapes (semconv keys vs. plain
group/category) are preserved.
Bundle-size delta (brotli, the enforced metric): **166.07 kB → 166.99 kB
(+0.92 kB)**, well under the 256 kB cap. Gzipped `index.umd.js` grows by
~1.4 kB.
## Test plan
- [x] `yarn turbo run build --filter highlight.run`
- [x] `yarn turbo run test --filter highlight.run` (406/406 pass)
- [x] `yarn enforce-size` (166.99 kB / 256 kB)
- [x] `yarn format-check`
- [ ] Verify in a real page that gauge metrics now carry
`web_vital.element` / `web_vital.event_type` etc.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes how web-vitals metrics are sourced and adds new per-metric
attribution fields, which can affect telemetry shape/cardinality and
downstream dashboards. Low security risk but does emit additional
(sanitized) URL and DOM-selector data.
>
> **Overview**
> Web-vitals collection now uses `web-vitals/attribution` and exposes a
typed `WebVitalMetric` union so consumers can safely access per-metric
attribution fields.
>
> Both metric emitters (`client/index.tsx` and `sdk/observe.ts`) now
attach **additional web-vitals attributes** (e.g. `web_vital.element`,
`web_vital.event_type`, `web_vital.load_state`, and a sanitized
`web_vital.attribution.url`) when recording gauges, while keeping each
emitter’s existing metric attribute/tag shape intact.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
54e116b. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent edefe2c commit d8288b1
3 files changed
Lines changed: 128 additions & 9 deletions
File tree
- sdk/highlight-run/src
- client
- listeners/web-vitals-listener
- sdk
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| |||
1122 | 1123 | | |
1123 | 1124 | | |
1124 | 1125 | | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
1125 | 1167 | | |
1126 | 1168 | | |
1127 | 1169 | | |
1128 | 1170 | | |
1129 | 1171 | | |
| 1172 | + | |
1130 | 1173 | | |
1131 | 1174 | | |
1132 | 1175 | | |
| |||
Lines changed: 30 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
2 | 15 | | |
3 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
4 | 32 | | |
5 | 33 | | |
6 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
653 | 653 | | |
654 | 654 | | |
655 | 655 | | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
656 | 710 | | |
657 | 711 | | |
658 | 712 | | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | | - | |
| 713 | + | |
666 | 714 | | |
667 | 715 | | |
668 | 716 | | |
| |||
0 commit comments