Skip to content

feat: emit element-selector attribution on web-vitals metrics#515

Merged
Vadman97 merged 3 commits intomainfrom
vkorolik/web-vitals-attribution
May 1, 2026
Merged

feat: emit element-selector attribution on web-vitals metrics#515
Vadman97 merged 3 commits intomainfrom
vkorolik/web-vitals-attribution

Conversation

@Vadman97
Copy link
Copy Markdown
Contributor

@Vadman97 Vadman97 commented Apr 30, 2026

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

  • yarn turbo run build --filter highlight.run
  • yarn turbo run test --filter highlight.run (406/406 pass)
  • yarn enforce-size (166.99 kB / 256 kB)
  • 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


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.

Reviewed by Cursor Bugbot for commit 54e116b. Bugbot is set up for automated code reviews on this repo. Configure here.

Switches the web-vitals listener to the `web-vitals/attribution` build
and emits per-vital attribution attributes (LCP element, CLS largest-
shift target, INP/FID interaction target, etc.) on the gauge metrics so
slow vitals can be attributed to a specific DOM element on the page.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Vadman97 Vadman97 requested a review from a team as a code owner April 30, 2026 19:37
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 64a49d8. Configure here.

Comment thread sdk/highlight-run/src/client/index.tsx Outdated
Comment thread sdk/highlight-run/src/client/index.tsx Outdated
- Wrap LCP `web_vital.attribution.url` with sanitizeUrl() to match
  observe.ts and avoid leaking signed-URL credentials/tokens in
  metric tag values.
- Tighten addTag guard from `v !== undefined` to truthiness so empty
  strings (commonly returned by web-vitals when the attributed DOM
  element has been removed) don't pollute metrics with empty
  `web_vital.element` tags.

Addresses Cursor bugbot comments on PR #515.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Vadman97 Vadman97 merged commit d8288b1 into main May 1, 2026
22 checks passed
@Vadman97 Vadman97 deleted the vkorolik/web-vitals-attribution branch May 1, 2026 15:35
Vadman97 pushed a commit that referenced this pull request May 1, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>observability: 1.1.7</summary>

##
[1.1.7](observability-1.1.6...observability-1.1.7)
(2026-05-01)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * highlight.run bumped to 10.2.0
</details>

<details><summary>session-replay: 1.1.7</summary>

##
[1.1.7](session-replay-1.1.6...session-replay-1.1.7)
(2026-05-01)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * highlight.run bumped to 10.2.0
</details>

<details><summary>highlight.run: 10.2.0</summary>

##
[10.2.0](highlight.run-10.1.2...highlight.run-10.2.0)
(2026-05-01)


### Features

* emit element-selector attribution on web-vitals metrics
([#515](#515))
([d8288b1](d8288b1))
* include LD context keys in metric event attributes
([#514](#514))
([edefe2c](edefe2c))


### Bug Fixes

* emit url.query_params as nested otel attributes
([#517](#517))
([69629e1](69629e1))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Low risk release-only changes: version bumps and changelog updates
with no code logic modifications in this PR. Runtime behavior changes
come only from the upgraded `highlight.run` dependency.
> 
> **Overview**
> Bumps released package versions for `@launchdarkly/observability` and
`@launchdarkly/session-replay` to `1.1.7`, and updates the workspace
`highlight.run` package to `10.2.0` (with corresponding changelog
entries).
> 
> Updates `.release-please-manifest.json` to reflect the new versions
and documents `highlight.run` 10.2.0 feature/bugfix notes (web-vitals
element selector attribution, additional LD context keys on metric
attributes, and nested `url.query_params` OTEL attributes).
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
cdd7820. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants