Skip to content

Commit 280a49e

Browse files
authored
fix(browser/v7): Continuously record CLS (#11935)
1 parent a09daa4 commit 280a49e

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

packages/opentelemetry-node/test/spanprocessor.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ describe('SentrySpanProcessor', () => {
629629

630630
expect(description).toBe('GET /my/route/{id}');
631631
expect(data).toEqual({
632-
'http.method': 'GET',
632+
'http.request.method': 'GET',
633633
'http.route': '/my/route/{id}',
634634
'http.target': '/my/route/123',
635635
'http.url': 'http://example.com/my/route/123',
@@ -661,7 +661,7 @@ describe('SentrySpanProcessor', () => {
661661

662662
expect(description).toBe('GET http://example.com/my/route/123');
663663
expect(data).toEqual({
664-
'http.method': 'GET',
664+
'http.request.method': 'GET',
665665
'http.target': '/my/route/123',
666666
'http.url': 'http://example.com/my/route/123',
667667
'otel.kind': 'INTERNAL',
@@ -693,7 +693,7 @@ describe('SentrySpanProcessor', () => {
693693

694694
expect(description).toBe('GET http://example.com/my/route/123');
695695
expect(data).toEqual({
696-
'http.method': 'GET',
696+
'http.request.method': 'GET',
697697
'http.target': '/my/route/123',
698698
'http.url': 'http://example.com/my/route/123?what=123#myHash',
699699
'otel.kind': 'INTERNAL',

packages/tracing-internal/src/browser/instrument.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,15 @@ function triggerHandlers(type: InstrumentHandlerType, data: unknown): void {
208208
}
209209

210210
function instrumentCls(): StopListening {
211-
return onCLS(metric => {
212-
triggerHandlers('cls', {
213-
metric,
214-
});
215-
_previousCls = metric;
216-
});
211+
return onCLS(
212+
metric => {
213+
triggerHandlers('cls', {
214+
metric,
215+
});
216+
_previousCls = metric;
217+
},
218+
{ reportAllChanges: true },
219+
);
217220
}
218221

219222
function instrumentFid(): void {

packages/tracing-internal/src/browser/web-vitals/getCLS.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ import type { CLSMetric, ReportCallback, StopListening } from './types';
4141
* hidden. As a result, the `callback` function might be called multiple times
4242
* during the same page load._
4343
*/
44-
export const onCLS = (onReport: ReportCallback): StopListening | undefined => {
44+
export const onCLS = (
45+
onReport: ReportCallback,
46+
options: { reportAllChanges?: boolean } = {},
47+
): StopListening | undefined => {
4548
const metric = initMetric('CLS', 0);
4649
let report: ReturnType<typeof bindReporter>;
4750

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

8891
const po = observe('layout-shift', handleEntries);
8992
if (po) {
90-
report = bindReporter(onReport, metric);
93+
report = bindReporter(onReport, metric, options.reportAllChanges);
9194

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

0 commit comments

Comments
 (0)