@@ -6,7 +6,7 @@ import { browserPerformanceTimeOrigin, getGlobalObject, htmlTreeAsString, isNode
66import { Span } from '../span' ;
77import { Transaction } from '../transaction' ;
88import { msToSec } from '../utils' ;
9- import { getCLS } from './web-vitals/getCLS' ;
9+ import { getCLS , LayoutShift } from './web-vitals/getCLS' ;
1010import { getFID } from './web-vitals/getFID' ;
1111import { getLCP , LargestContentfulPaint } from './web-vitals/getLCP' ;
1212import { getFirstHidden } from './web-vitals/lib/getFirstHidden' ;
@@ -20,6 +20,7 @@ export class MetricsInstrumentation {
2020
2121 private _performanceCursor : number = 0 ;
2222 private _lcpEntry : LargestContentfulPaint | undefined ;
23+ private _clsEntry : LayoutShift | undefined ;
2324
2425 public constructor ( ) {
2526 if ( ! isNodeEnv ( ) && global ?. performance ) {
@@ -207,6 +208,13 @@ export class MetricsInstrumentation {
207208
208209 transaction . setTag ( 'lcp.size' , this . _lcpEntry . size ) ;
209210 }
211+
212+ if ( this . _clsEntry ) {
213+ logger . log ( '[Measurements] Adding CLS Data' ) ;
214+ transaction . setData ( 'measurements.cls' , {
215+ sources : this . _clsEntry . sources . map ( source => htmlTreeAsString ( source . node ) ) ,
216+ } ) ;
217+ }
210218 }
211219 }
212220
@@ -221,6 +229,7 @@ export class MetricsInstrumentation {
221229
222230 logger . log ( '[Measurements] Adding CLS' ) ;
223231 this . _measurements [ 'cls' ] = { value : metric . value } ;
232+ this . _clsEntry = entry as LayoutShift ;
224233 } ) ;
225234 }
226235
0 commit comments