@@ -69,62 +69,73 @@ export class MetricsInstrumentation {
69
69
global . performance
70
70
. getEntries ( )
71
71
. slice ( this . _performanceCursor )
72
- . forEach ( ( entry : Record < string , any > ) => {
73
- const startTime = msToSec ( entry . startTime as number ) ;
74
- const duration = msToSec ( entry . duration as number ) ;
75
-
76
- if ( transaction . op === 'navigation' && timeOrigin + startTime < transaction . startTimestamp ) {
77
- return ;
78
- }
79
-
80
- switch ( entry . entryType ) {
81
- case 'navigation' : {
82
- addNavigationSpans ( transaction , entry , timeOrigin ) ;
83
- responseStartTimestamp = timeOrigin + msToSec ( entry . responseStart as number ) ;
84
- requestStartTimestamp = timeOrigin + msToSec ( entry . requestStart as number ) ;
85
- break ;
72
+ . forEach (
73
+ // eslint-disable-next-line complexity
74
+ ( entry : Record < string , any > ) => {
75
+ const startTime = msToSec ( entry . startTime as number ) ;
76
+ const duration = msToSec ( entry . duration as number ) ;
77
+
78
+ if ( transaction . op === 'navigation' && timeOrigin + startTime < transaction . startTimestamp ) {
79
+ return ;
86
80
}
87
- case 'mark' :
88
- case 'paint' :
89
- case 'measure' : {
90
- const startTimestamp = addMeasureSpans ( transaction , entry , startTime , duration , timeOrigin ) ;
91
- if ( tracingInitMarkStartTime === undefined && entry . name === 'sentry-tracing-init' ) {
92
- tracingInitMarkStartTime = startTimestamp ;
93
- }
94
-
95
- // capture web vitals
96
-
97
- const firstHidden = getVisibilityWatcher ( ) ;
98
- // Only report if the page wasn't hidden prior to the web vital.
99
- const shouldRecord = entry . startTime < firstHidden . firstHiddenTime ;
100
81
101
- if ( entry . name === 'first-paint' && shouldRecord ) {
102
- logger . log ( '[Measurements] Adding FP' ) ;
103
- this . _measurements [ 'fp' ] = { value : entry . startTime } ;
104
- this . _measurements [ 'mark.fp' ] = { value : startTimestamp } ;
82
+ switch ( entry . entryType ) {
83
+ case 'navigation' : {
84
+ addNavigationSpans ( transaction , entry , timeOrigin ) ;
85
+ responseStartTimestamp = timeOrigin + msToSec ( entry . responseStart as number ) ;
86
+ requestStartTimestamp = timeOrigin + msToSec ( entry . requestStart as number ) ;
87
+ break ;
105
88
}
106
-
107
- if ( entry . name === 'first-contentful-paint' && shouldRecord ) {
108
- logger . log ( '[Measurements] Adding FCP' ) ;
109
- this . _measurements [ 'fcp' ] = { value : entry . startTime } ;
110
- this . _measurements [ 'mark.fcp' ] = { value : startTimestamp } ;
89
+ case 'mark' :
90
+ case 'paint' :
91
+ case 'measure' : {
92
+ const startTimestamp = addMeasureSpans ( transaction , entry , startTime , duration , timeOrigin ) ;
93
+ if ( tracingInitMarkStartTime === undefined && entry . name === 'sentry-tracing-init' ) {
94
+ tracingInitMarkStartTime = startTimestamp ;
95
+ }
96
+
97
+ // capture web vitals
98
+
99
+ const firstHidden = getVisibilityWatcher ( ) ;
100
+ // Only report if the page wasn't hidden prior to the web vital.
101
+ const shouldRecord = entry . startTime < firstHidden . firstHiddenTime ;
102
+
103
+ if ( entry . name === 'first-paint' && shouldRecord ) {
104
+ logger . log ( '[Measurements] Adding FP' ) ;
105
+ this . _measurements [ 'fp' ] = { value : entry . startTime } ;
106
+ this . _measurements [ 'mark.fp' ] = { value : startTimestamp } ;
107
+ }
108
+
109
+ if ( entry . name === 'first-contentful-paint' && shouldRecord ) {
110
+ logger . log ( '[Measurements] Adding FCP' ) ;
111
+ this . _measurements [ 'fcp' ] = { value : entry . startTime } ;
112
+ this . _measurements [ 'mark.fcp' ] = { value : startTimestamp } ;
113
+ }
114
+
115
+ if ( this . _measurements [ 'fcp' ] ?. value && entry . startTime > this . _measurements [ 'fcp' ] . value ) {
116
+ logger . log ( '[Measurements] Adding TBT' ) ;
117
+ const entryBlockingTime = entry . duration - 50 ;
118
+ if ( entryBlockingTime > 0 ) {
119
+ this . _measurements [ 'tbt' ] = { value : ( this . _measurements [ 'tbt' ] ?. value || 0 ) + entryBlockingTime } ;
120
+ }
121
+ }
122
+
123
+ break ;
111
124
}
112
-
113
- break ;
114
- }
115
- case 'resource' : {
116
- const resourceName = ( entry . name as string ) . replace ( window . location . origin , '' ) ;
117
- const endTimestamp = addResourceSpans ( transaction , entry , resourceName , startTime , duration , timeOrigin ) ;
118
- // We remember the entry script end time to calculate the difference to the first init mark
119
- if ( entryScriptStartTimestamp === undefined && ( entryScriptSrc || '' ) . indexOf ( resourceName ) > - 1 ) {
120
- entryScriptStartTimestamp = endTimestamp ;
125
+ case 'resource' : {
126
+ const resourceName = ( entry . name as string ) . replace ( window . location . origin , '' ) ;
127
+ const endTimestamp = addResourceSpans ( transaction , entry , resourceName , startTime , duration , timeOrigin ) ;
128
+ // We remember the entry script end time to calculate the difference to the first init mark
129
+ if ( entryScriptStartTimestamp === undefined && ( entryScriptSrc || '' ) . indexOf ( resourceName ) > - 1 ) {
130
+ entryScriptStartTimestamp = endTimestamp ;
131
+ }
132
+ break ;
121
133
}
122
- break ;
134
+ default :
135
+ // Ignore other entry types.
123
136
}
124
- default :
125
- // Ignore other entry types.
126
- }
127
- } ) ;
137
+ } ,
138
+ ) ;
10000
128
139
129
140
if ( entryScriptStartTimestamp !== undefined && tracingInitMarkStartTime !== undefined ) {
130
141
_startChild ( transaction , {
0 commit comments