Skip to content

fix(browser/v7): Continuously record CLS #11935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/opentelemetry-node/test/spanprocessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ describe('SentrySpanProcessor', () => {

expect(description).toBe('GET /my/route/{id}');
expect(data).toEqual({
'http.method': 'GET',
'http.request.method': 'GET',
'http.route': '/my/route/{id}',
'http.target': '/my/route/123',
'http.url': 'http://example.com/my/route/123',
Expand Down Expand Up @@ -661,7 +661,7 @@ describe('SentrySpanProcessor', () => {

expect(description).toBe('GET http://example.com/my/route/123');
expect(data).toEqual({
'http.method': 'GET',
'http.request.method': 'GET',
'http.target': '/my/route/123',
'http.url': 'http://example.com/my/route/123',
'otel.kind': 'INTERNAL',
Expand Down Expand Up @@ -693,7 +693,7 @@ describe('SentrySpanProcessor', () => {

expect(description).toBe('GET http://example.com/my/route/123');
expect(data).toEqual({
'http.method': 'GET',
'http.request.method': 'GET',
'http.target': '/my/route/123',
'http.url': 'http://example.com/my/route/123?what=123#myHash',
'otel.kind': 'INTERNAL',
Expand Down
15 changes: 9 additions & 6 deletions packages/tracing-internal/src/browser/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,15 @@ function triggerHandlers(type: InstrumentHandlerType, data: unknown): void {
}

function instrumentCls(): StopListening {
return onCLS(metric => {
triggerHandlers('cls', {
metric,
});
_previousCls = metric;
});
return onCLS(
metric => {
triggerHandlers('cls', {
metric,
});
_previousCls = metric;
},
{ reportAllChanges: true },
);
}

function instrumentFid(): void {
Expand Down
7 changes: 5 additions & 2 deletions packages/tracing-internal/src/browser/web-vitals/getCLS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ import type { CLSMetric, ReportCallback, StopListening } from './types';
* hidden. As a result, the `callback` function might be called multiple times
* during the same page load._
*/
export const onCLS = (onReport: ReportCallback): StopListening | undefined => {
export const onCLS = (
onReport: ReportCallback,
options: { reportAllChanges?: boolean } = {},
): StopListening | undefined => {
const metric = initMetric('CLS', 0);
let report: ReturnType<typeof bindReporter>;

Expand Down Expand Up @@ -87,7 +90,7 @@ export const onCLS = (onReport: ReportCallback): StopListening | undefined => {

const po = observe('layout-shift', handleEntries);
if (po) {
report = bindReporter(onReport, metric);
report = bindReporter(onReport, metric, options.reportAllChanges);

const stopListening = (): void => {
handleEntries(po.takeRecords() as CLSMetric['entries']);
Expand Down
Loading