1
1
/* eslint-disable max-lines */
2
2
/* eslint-disable @typescript-eslint/no-explicit-any */
3
3
import { Measurements , SpanContext } from '@sentry/types' ;
4
- import { browserPerformanceTimeOrigin , getGlobalObject , logger } from '@sentry/utils' ;
4
+ import { browserPerformanceTimeOrigin , getGlobalObject , htmlTreeAsString , logger } from '@sentry/utils' ;
5
5
6
6
import { Span } from '../span' ;
7
7
import { Transaction } from '../transaction' ;
8
8
import { msToSec } from '../utils' ;
9
9
import { getCLS } from './web-vitals/getCLS' ;
10
10
import { getFID } from './web-vitals/getFID' ;
11
- import { getLCP } from './web-vitals/getLCP' ;
11
+ import { getLCP , LargestContentfulPaint } from './web-vitals/getLCP' ;
12
12
import { getTTFB } from './web-vitals/getTTFB' ;
13
13
import { getFirstHidden } from './web-vitals/lib/getFirstHidden' ;
14
14
import { NavigatorDeviceMemory , NavigatorNetworkInformation } from './web-vitals/types' ;
@@ -20,6 +20,7 @@ export class MetricsInstrumentation {
20
20
private _measurements : Measurements = { } ;
21
21
22
22
private _performanceCursor : number = 0 ;
23
+ private _lcpEntry : LargestContentfulPaint | undefined ;
23
24
24
25
public constructor ( ) {
25
26
if ( global && global . performance ) {
@@ -170,6 +171,26 @@ export class MetricsInstrumentation {
170
171
}
171
172
172
173
transaction . setMeasurements ( this . _measurements ) ;
174
+
175
+ if ( this . _lcpEntry ) {
176
+ logger . log ( '[Measurements] Adding LCP Data' ) ;
177
+ // Capture Properties of the LCP element that contributes to the LCP.
178
+
179
+ if ( this . _lcpEntry . element ) {
180
+ transaction . setTag ( 'lcp.element' , htmlTreeAsString ( this . _lcpEntry . element ) ) ;
181
+ }
182
+
183
+ if ( this . _lcpEntry . id ) {
184
+ transaction . setTag ( 'lcp.id' , this . _lcpEntry . id ) ;
185
+ }
186
+
187
+ if ( this . _lcpEntry . url ) {
188
+ // Trim URL to the first 200 characters.
189
+ transaction . setTag ( 'lcp.url' , this . _lcpEntry . url . trim ( ) . slice ( 0 , 200 ) ) ;
190
+ }
191
+
192
+ transaction . setTag ( 'lcp.size' , this . _lcpEntry . size ) ;
193
+ }
173
194
}
174
195
}
175
196
@@ -241,6 +262,7 @@ export class MetricsInstrumentation {
241
262
logger . log ( '[Measurements] Adding LCP' ) ;
242
263
this . _measurements [ 'lcp' ] = { value : metric . value } ;
243
264
this . _measurements [ 'mark.lcp' ] = { value : timeOrigin + startTime } ;
265
+ this . _lcpEntry = entry as LargestContentfulPaint ;
244
266
} ) ;
245
267
}
246
268
0 commit comments