Skip to content

Commit

Permalink
fix(browser/v7): Continuously record CLS (#11935)
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst committed May 7, 2024
1 parent a09daa4 commit 280a49e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
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

0 comments on commit 280a49e

Please sign in to comment.