Skip to content

Commit 203765a

Browse files
chargomeclaude
andauthored
test(browser): Register the LCP handlers in the bundle of the SDK (#25263)
Fixes a flaky test. The `handlers-lcp` test registered its LCP handlers in a separate bundle, so they watched LCP through their own observer and sometimes saw a different element than the SDK did on Linux CI. Now the handlers are registered in the same bundle as the SDK, so they see exactly what the SDK sees. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 12a84a9 commit 203765a

2 files changed

Lines changed: 31 additions & 18 deletions

File tree

  • dev-packages/browser-integration-tests/suites/tracing/metrics/handlers-lcp
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { addLcpInstrumentationHandler } from '@sentry/browser-utils';
3+
4+
window.Sentry = Sentry;
5+
6+
Sentry.init({
7+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
8+
integrations: [Sentry.browserTracingIntegration()],
9+
tracesSampleRate: 1,
10+
});
11+
12+
// Registered in the bundle of the SDK, so the handlers share its LCP observer. A second bundle gets
13+
// a copy of the instrumentation with an observer of its own, whose view of the LCP candidates can
14+
// differ from the SDK's (e.g. a different first-hidden time), which made this test flaky.
15+
addLcpInstrumentationHandler(({ metric }) => {
16+
const entry = metric.entries[metric.entries.length - 1];
17+
window._LCP = entry.size;
18+
});
19+
20+
addLcpInstrumentationHandler(({ metric }) => {
21+
const entry = metric.entries[metric.entries.length - 1];
22+
window._LCP2 = entry.size;
23+
});
24+
25+
window.ADD_HANDLER = () => {
26+
addLcpInstrumentationHandler(({ metric }) => {
27+
const entry = metric.entries[metric.entries.length - 1];
28+
window._LCP3 = entry.size;
29+
});
30+
};
Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1 @@
1-
import { addLcpInstrumentationHandler } from '@sentry/browser-utils';
2-
3-
addLcpInstrumentationHandler(({ metric }) => {
4-
const entry = metric.entries[metric.entries.length - 1];
5-
window._LCP = entry.size;
6-
});
7-
8-
addLcpInstrumentationHandler(({ metric }) => {
9-
const entry = metric.entries[metric.entries.length - 1];
10-
window._LCP2 = entry.size;
11-
});
12-
13-
window.ADD_HANDLER = () => {
14-
addLcpInstrumentationHandler(({ metric }) => {
15-
const entry = metric.entries[metric.entries.length - 1];
16-
window._LCP3 = entry.size;
17-
});
18-
};
1+
// The handlers live in `init.js`, see there.

0 commit comments

Comments
 (0)