@@ -6,7 +6,7 @@ import { browserPerformanceTimeOrigin, getGlobalObject, htmlTreeAsString, isNode
6
6
import { Span } from '../span' ;
7
7
import { Transaction } from '../transaction' ;
8
8
import { msToSec } from '../utils' ;
9
- import { getCLS } from './web-vitals/getCLS' ;
9
+ import { getCLS , LayoutShift } from './web-vitals/getCLS' ;
10
10
import { getFID } from './web-vitals/getFID' ;
11
11
import { getLCP , LargestContentfulPaint } from './web-vitals/getLCP' ;
12
12
import { getFirstHidden } from './web-vitals/lib/getFirstHidden' ;
@@ -20,6 +20,7 @@ export class MetricsInstrumentation {
20
20
21
21
private _performanceCursor : number = 0 ;
22
22
private _lcpEntry : LargestContentfulPaint | undefined ;
23
+ private _clsEntry : LayoutShift | undefined ;
23
24
24
25
public constructor ( ) {
25
26
if ( ! isNodeEnv ( ) && global ?. performance ) {
@@ -207,6 +208,13 @@ export class MetricsInstrumentation {
207
208
208
209
transaction . setTag ( 'lcp.size' , this . _lcpEntry . size ) ;
209
210
}
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
+ }
210
218
}
211
219
}
212
220
@@ -221,6 +229,7 @@ export class MetricsInstrumentation {
221
229
222
230
logger . log ( '[Measurements] Adding CLS' ) ;
223
231
this . _measurements [ 'cls' ] = { value : metric . value } ;
232
+ this . _clsEntry = entry as LayoutShift ;
224
233
} ) ;
225
234
}
226
235
0 commit comments