Skip to content

fix(browser): filter implausible LCP values#20338

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

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

Conversation

@logaretm
Copy link
Copy Markdown
Member

@logaretm logaretm commented Apr 15, 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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 15, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.78 kB - -
@sentry/browser - with treeshaking flags 24.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 flags 72.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/react 27.53 kB - -
@sentry/react (incl. Tracing) 45.92 kB +0.09% +39 B 🔺
@sentry/vue 30.61 kB - -
@sentry/vue (incl. Tracing) 45.49 kB +0.1% +41 B 🔺
@sentry/svelte 25.8 kB - -
CDN Bundle 28.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 - uncompressed 83.12 kB - -
CDN Bundle (incl. Tracing) - uncompressed 133.75 kB +0.09% +116 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 87.27 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 137.17 kB +0.09% +116 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 210.63 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 250.99 kB +0.05% +116 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 254.38 kB +0.05% +116 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 263.9 kB +0.05% +116 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 267.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-core 57.94 kB +0.02% +7 B 🔺
@sentry/node 174.78 kB +0.01% +6 B 🔺
@sentry/node - without tracing 97.89 kB +0.03% +21 B 🔺
@sentry/aws-serverless 115.12 kB +0.01% +8 B 🔺

View base workflow run

Copy link
Copy Markdown
Member

@Lms24 Lms24 left a comment

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 logaretm force-pushed the feat/lcp-plausibility-filter branch from 8aa994f to 1063983 Compare April 16, 2026 16:04
@logaretm logaretm marked this pull request as ready for review April 16, 2026 16:04
Copilot AI review requested due to automatic review settings April 16, 2026 16:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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.

File Description
packages/browser-utils/test/metrics/lcp.test.ts Adds unit tests for the new LCP validation helper and standalone LCP span guard behavior.
packages/browser-utils/src/metrics/lcp.ts Defines plausibility threshold + validation helper; uses it when collecting/sending standalone LCP spans.
packages/browser-utils/src/metrics/browserMetrics.ts Uses 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 thread packages/browser-utils/src/metrics/lcp.ts
Comment thread packages/browser-utils/src/metrics/lcp.ts
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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 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 thread packages/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 develop Apr 16, 2026
476 of 477 checks passed
@logaretm logaretm deleted the feat/lcp-plausibility-filter branch April 16, 2026 18:44
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.

3 participants