Repository navigation
feat(web-sdk): support custom web vitals target labels - #2361
adityareddy-dev wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
🟢 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.generateTargetconfiguration callback. - Forwards the callback to
onCLS,onINP, andonLCP, 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
| url: 'https://agent.myapp/collect', | ||
| app: { name: 'frontend' }, | ||
| webVitalsInstrumentation: { | ||
| generateTarget: (element) => |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yes, a blank data-testid returns undefined in the example, and a blank label from the callback does too.
Signed commits reportAll 3 commits between |
8433438 to
7afed3f
Compare
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.
5cfceee to
9a6a029
Compare
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. Returningundefinedkeeps the default selector. FCP and TTFB don't change.Links
Fixes #2357
Checklist