Skip to content

Commit 401692e

Browse files
chargomeclaude
andcommitted
test(browser): Register the LCP handlers in the bundle of the SDK
The handlers lived in the subject bundle, which got its own copy of the instrumentation and so an LCP observer of its own. On Linux CI that copy sometimes only ever saw the body candidate while the SDK's copy saw the image, so the handler assertions failed on every run of some trees and timed out in others. In the bundle of the SDK the handlers share its observer and see exactly what the span reports. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 37f012b commit 401692e

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)