Skip to content

fix(browser): filter implausible LCP values - #20338

Merged
logaretm merged 3 commits into
developfrom
feat/lcp-plausibility-filter
Apr 16, 2026
Merged

fix(browser): filter implausible LCP values#20338
logaretm merged 3 commits into
developfrom
feat/lcp-plausibility-filter

Conversation

@logaretm

@logaretmlogaretm commented Apr 15, 2026

Copy link
Copy Markdown
Member

Summary

  • add an LCP plausibility guard to drop implausible browser-reported values above 60 seconds
  • apply the guard to both pageload LCP measurements and standalone LCP spans
  • add focused unit tests for valid and invalid LCP values

@github-actions

github-actionsBot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser25.78 kB--
@sentry/browser - with treeshaking flags24.27 kB--
@sentry/browser (incl. Tracing)43.65 kB+0.09%+38 B 🔺
@sentry/browser (incl. Tracing + Span Streaming)45.36 kB+0.09%+37 B 🔺
@sentry/browser (incl. Tracing, Profiling)48.58 kB+0.16%+75 B 🔺
@sentry/browser (incl. Tracing, Replay)82.79 kB+0.07%+56 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags72.29 kB+0.07%+46 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas)87.49 kB+0.08%+63 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback)99.74 kB+0.07%+64 B 🔺
@sentry/browser (incl. Feedback)42.59 kB--
@sentry/browser (incl. sendFeedback)30.45 kB--
@sentry/browser (incl. FeedbackAsync)35.45 kB--
@sentry/browser (incl. Metrics)27.07 kB--
@sentry/browser (incl. Logs)27.2 kB+0.01%+1 B 🔺
@sentry/browser (incl. Metrics & Logs)27.89 kB--
@sentry/react27.53 kB--
@sentry/react (incl. Tracing)45.92 kB+0.09%+39 B 🔺
@sentry/vue30.61 kB--
@sentry/vue (incl. Tracing)45.49 kB+0.1%+41 B 🔺
@sentry/svelte25.8 kB--
CDN Bundle28.46 kB-0.01%-1 B 🔽
CDN Bundle (incl. Tracing)44.73 kB+0.09%+36 B 🔺
CDN Bundle (incl. Logs, Metrics)29.83 kB--
CDN Bundle (incl. Tracing, Logs, Metrics)45.81 kB+0.09%+39 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics)68.73 kB--
CDN Bundle (incl. Tracing, Replay)81.68 kB+0.05%+33 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)82.77 kB+0.05%+37 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback)87.2 kB+0.04%+30 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)88.27 kB+0.05%+36 B 🔺
CDN Bundle - uncompressed83.12 kB--
CDN Bundle (incl. Tracing) - uncompressed133.75 kB+0.09%+116 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed87.27 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed137.17 kB+0.09%+116 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed210.63 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed250.99 kB+0.05%+116 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed254.38 kB+0.05%+116 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed263.9 kB+0.05%+116 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed267.29 kB+0.05%+116 B 🔺
@sentry/nextjs (client)48.44 kB+0.06%+25 B 🔺
@sentry/sveltekit (client)44.09 kB+0.09%+39 B 🔺
@sentry/node-core57.94 kB+0.02%+7 B 🔺
@sentry/node174.78 kB+0.01%+6 B 🔺
@sentry/node - without tracing97.89 kB+0.03%+21 B 🔺
@sentry/aws-serverless115.12 kB+0.01%+8 B 🔺

View base workflow run

@Lms24Lms24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Gonna approve, I think this is a good short-term fix/improvement

Co-Authored-By: GPT-5 <noreply@anthropic.com>
@logaretm
logaretmforce-pushed the feat/lcp-plausibility-filter branch from 8aa994f to 1063983CompareApril 16, 2026 16:04
@logaretm
logaretm marked this pull request as ready for review April 16, 2026 16:04
CopilotAI review requested due to automatic review settings April 16, 2026 16:04

CopilotAI 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.

Pull request overview

Adds an LCP plausibility guard in browser-utils to prevent reporting obviously incorrect Largest Contentful Paint values (e.g. > 60s), aiming to improve the quality of browser LCP metrics/spans.

Changes:

  • Introduce MAX_PLAUSIBLE_LCP_DURATION and isValidLcpMetric(...) for LCP plausibility filtering.
  • Apply the plausibility check to pageload LCP measurements and standalone LCP spans.
  • Add unit tests covering valid/invalid LCP values and standalone LCP span emission.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

FileDescription
packages/browser-utils/test/metrics/lcp.test.tsAdds unit tests for the new LCP validation helper and standalone LCP span guard behavior.
packages/browser-utils/src/metrics/lcp.tsDefines plausibility threshold + validation helper; uses it when collecting/sending standalone LCP spans.
packages/browser-utils/src/metrics/browserMetrics.tsUses the new validation helper to filter implausible LCP values when recording pageload measurements.
Comments suppressed due to low confidence (1)

packages/browser-utils/src/metrics/browserMetrics.ts:292

  • The new LCP plausibility filter in _trackLCP changes pageload measurement behavior but isn't covered by unit tests. Since there are existing tests for metrics/browserMetrics (e.g. packages/browser-utils/test/browser/browserMetrics.test.ts), consider adding a focused test which verifies that values > MAX_PLAUSIBLE_LCP_DURATION do not set the lcp measurement / entry, while plausible values still do.
function _trackLCP(): () => void {
return addLcpInstrumentationHandler(({ metric }) => {
const entry = metric.entries[metric.entries.length - 1];
if (!entry || !isValidLcpMetric(metric.value)) {
return;
}
_measurements['lcp'] = { value: metric.value, unit: 'millisecond' };
_lcpEntry = entry as LargestContentfulPaint;
}, true);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadpackages/browser-utils/src/metrics/lcp.ts
Comment threadpackages/browser-utils/src/metrics/lcp.ts
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@cursorcursorBot left a comment

Copy link
Copy Markdown

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 1 potential issue.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit 128ab47. Configure here.

Comment threadpackages/browser-utils/src/metrics/lcp.ts
LCP is a paint time — 0ms is physically impossible. Accepting it let the
uninitialized default (0) leak through as a spurious span when the only
observed LCP value was filtered out as implausibly high.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@logaretm
logaretm merged commit 104b64e into developApr 16, 2026
476 of 477 checks passed
@logaretm
logaretm deleted the feat/lcp-plausibility-filter branch April 16, 2026 18:44
andreiborza pushed a commit that referenced this pull request Apr 20, 2026
## Summary
- add an LCP plausibility guard to drop implausible browser-reported
values above 60 seconds
- apply the guard to both pageload LCP measurements and standalone LCP
spans
- add focused unit tests for valid and invalid LCP values
---------
Co-authored-by: GPT-5 <noreply@anthropic.com>
Sign up for freeto 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.

3 participants

@logaretm@Lms24