Skip to content

feat(web-sdk): support custom web vitals target labels - #2361

Open
adityareddy-dev wants to merge 3 commits into
grafana:mainfrom
adityareddy-dev:feat/web-vitals-generate-target
Open

adityareddy-dev wants to merge 3 commits into
grafana:mainfrom
adityareddy-dev:feat/web-vitals-generate-target

Conversation

@adityareddy-dev

@adityareddy-dev adityareddy-dev commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Why

Web vitals targets are CSS selectors, and generated class names make them change between builds.

What

Added webVitalsInstrumentation.generateTarget, passed to web-vitals for LCP, INP and CLS. Returning undefined keeps the default selector. FCP and TTFB don't change.

Links

Fixes #2357

Checklist

  • Tests added
  • Changelog updated
  • Documentation updated

Copilot AI lite review requested due to automatic review settings November 3, 2026 15:48
@adityareddy-dev
adityareddy-dev requested a review from a team as a code owner November 3, 2026 15:48

Copilot AI left a comment

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.

🟢 Approval recommended

No active review issues are reported, and the change includes tests covering callback forwarding and preservation of existing behavior.

No open issues 🎉

What changed in this PR

Adds support for custom web-vitals target labels, allowing applications to replace unstable CSS selectors with meaningful labels for LCP, INP, and CLS attribution.

Changes:

  • Adds the optional webVitalsInstrumentation.generateTarget configuration callback.
  • Forwards the callback to onCLS, onINP, and onLCP, while preserving existing FCP and TTFB behavior.
  • Adds forwarding tests, README documentation, and a changelog entry.
File Description
packages/​web-sdk/​src/​instrumentations/​webVitals/​webVitalsWithAttribution.ts Forwards the callback to the relevant web-vitals attribution functions.
packages/​web-sdk/​src/​instrumentations/​webVitals/​webVitalsWithAttribution.test.ts Verifies callback forwarding and unchanged FCP/TTFB behavior.
packages/​web-sdk/​README.md Documents configuration and usage of custom target labels.
packages/​core/​src/​config/​types.ts Defines the public generateTarget configuration option.
CHANGELOG.md Records the new web-vitals target-label feature.

Review effort: Lite

@adityareddy-dev
adityareddy-dev requested a review from a team as a code owner November 4, 2026 15:26
@adityareddy-dev
adityareddy-dev requested review from Blinkuu and a lite review from Copilot November 4, 2026 15:26

Copilot AI left a comment

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.

🟢 Approval recommended

The reviewed implementation, forwarding tests, documentation, and changelog consistently cover the new callback while preserving existing FCP/TTFB behavior.

No open issues 🎉

Review effort: Lite

Comment thread packages/web-sdk/README.md Outdated
url: 'https://agent.myapp/collect',
app: { name: 'frontend' },
webVitalsInstrumentation: {
generateTarget: (element) =>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

with data-testid="", this example returns an empty string. web-vitals keeps it as the target, then Faro omits it from context instead of using the CSS selector. could the example normalize a blank test id to undefined?

Posted by Pi (gpt-6-luna) on Elliot's behalf.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, a blank data-testid returns undefined in the example, and a blank label from the callback does too.

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Signed commits report

All 3 commits between main and feat/web-vitals-generate-target have verified signatures. ✅

@adityareddy-dev
adityareddy-dev force-pushed the feat/web-vitals-generate-target branch from 8433438 to 7afed3f Compare November 16, 2026 10:18
web-vitals keeps an empty generateTarget result, and Faro then drops it, so the CSS selector is never used. A blank label is now passed on as undefined.
@adityareddy-dev
adityareddy-dev force-pushed the feat/web-vitals-generate-target branch from 5cfceee to 9a6a029 Compare November 20, 2026 09:15

This branch has not been deployed

No deployments
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.

Web Vitals: forward web-vitals' generateTarget option

3 participants