@@ -99,10 +99,10 @@ export function startTrackingWebVitals(): () => void {
99
99
*/
100
100
export function startTrackingLongTasks ( ) : void {
101
101
addPerformanceInstrumentationHandler ( 'longtask' , ( { entries } ) => {
102
+ if ( ! getActiveSpan ( ) ) {
103
+ return ;
104
+ }
102
105
for ( const entry of entries ) {
103
- if ( ! getActiveSpan ( ) ) {
104
- return ;
105
- }
106
106
const startTime = msToSec ( ( browserPerformanceTimeOrigin as number ) + entry . startTime ) ;
107
107
const duration = msToSec ( entry . duration ) ;
108
108
@@ -129,12 +129,12 @@ export function startTrackingLongAnimationFrames(): void {
129
129
// we directly observe `long-animation-frame` events instead of through the web-vitals
130
130
// `observe` helper function.
131
131
const observer = new PerformanceObserver ( list => {
132
+ if ( ! getActiveSpan ( ) ) {
133
+ return ;
134
+ }
132
135
for ( const entry of list . getEntries ( ) as PerformanceLongAnimationFrameTiming [ ] ) {
133
- if ( ! getActiveSpan ( ) ) {
134
- return ;
135
- }
136
136
if ( ! entry . scripts [ 0 ] ) {
137
- return ;
137
+ continue ;
138
138
}
139
139
140
140
const startTime = msToSec ( ( browserPerformanceTimeOrigin as number ) + entry . startTime ) ;
@@ -143,20 +143,19 @@ export function startTrackingLongAnimationFrames(): void {
143
143
const attributes : SpanAttributes = {
144
144
[ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.ui.browser.metrics' ,
145
145
} ;
146
+
146
147
const initialScript = entry . scripts [ 0 ] ;
147
- if ( initialScript ) {
148
- const { invoker, invokerType, sourceURL, sourceFunctionName, sourceCharPosition } = initialScript ;
149
- attributes [ 'browser.script.invoker' ] = invoker ;
150
- attributes [ 'browser.script.invoker_type' ] = invokerType ;
151
- if ( sourceURL ) {
152
- attributes [ 'code.filepath' ] = sourceURL ;
153
- }
154
- if ( sourceFunctionName ) {
155
- attributes [ 'code.function' ] = sourceFunctionName ;
156
- }
157
- if ( sourceCharPosition !== - 1 ) {
158
- attributes [ 'browser.script.source_char_position' ] = sourceCharPosition ;
159
- }
148
+ const { invoker, invokerType, sourceURL, sourceFunctionName, sourceCharPosition } = initialScript ;
149
+ attributes [ 'browser.script.invoker' ] = invoker ;
150
+ attributes [ 'browser.script.invoker_type' ] = invokerType ;
151
+ if ( sourceURL ) {
152
+ attributes [ 'code.filepath' ] = sourceURL ;
153
+ }
154
+ if ( sourceFunctionName ) {
155
+ attributes [ 'code.function' ] = sourceFunctionName ;
156
+ }
157
+ if ( sourceCharPosition !== - 1 ) {
158
+ attributes [ 'browser.script.source_char_position' ] = sourceCharPosition ;
160
159
}
161
160
162
161
const span = startInactiveSpan ( {
@@ -179,11 +178,10 @@ export function startTrackingLongAnimationFrames(): void {
179
178
*/
180
179
export function startTrackingInteractions ( ) : void {
181
180
addPerformanceInstrumentationHandler ( 'event' , ( { entries } ) => {
181
+ if ( ! getActiveSpan ( ) ) {
182
+ return ;
183
+ }
182
184
for ( const entry of entries ) {
183
- if ( ! getActiveSpan ( ) ) {
184
- return ;
185
- }
186
-
187
185
if ( entry . name === 'click' ) {
188
186
const startTime = msToSec ( ( browserPerformanceTimeOrigin as number ) + entry . startTime ) ;
189
187
const duration = msToSec ( entry . duration ) ;
0 commit comments