1
- /* eslint-disable max-lines, complexity */
1
+ /* eslint-disable max-lines */
2
2
import type { IdleTransaction } from '@sentry/core' ;
3
+ import { getActiveSpan } from '@sentry/core' ;
3
4
import { getCurrentHub } from '@sentry/core' ;
4
5
import {
5
6
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ,
@@ -237,7 +238,6 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
237
238
latestRouteName = finalContext . name ;
238
239
latestRouteSource = getSource ( finalContext ) ;
239
240
240
- // eslint-disable-next-line deprecation/deprecation
241
241
if ( finalContext . sampled === false ) {
242
242
DEBUG_BUILD && logger . log ( `[Tracing] Will not send ${ finalContext . op } transaction because of beforeNavigate.` ) ;
243
243
}
@@ -316,7 +316,10 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
316
316
// If there's an open transaction on the scope, we need to finish it before creating an new one.
317
317
activeSpan . end ( ) ;
318
318
}
319
- activeSpan = _createRouteTransaction ( context ) ;
319
+ activeSpan = _createRouteTransaction ( {
320
+ op : 'navigation' ,
321
+ ...context ,
322
+ } ) ;
320
323
} ) ;
321
324
322
325
client . on ( 'startPageLoadSpan' , ( context : StartSpanOptions ) => {
@@ -325,7 +328,10 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
325
328
// If there's an open transaction on the scope, we need to finish it before creating an new one.
326
329
activeSpan . end ( ) ;
327
330
}
328
- activeSpan = _createRouteTransaction ( context ) ;
331
+ activeSpan = _createRouteTransaction ( {
332
+ op : 'pageload' ,
333
+ ...context ,
334
+ } ) ;
329
335
} ) ;
330
336
}
331
337
@@ -334,7 +340,6 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
334
340
name : WINDOW . location . pathname ,
335
341
// pageload should always start at timeOrigin (and needs to be in s, not ms)
336
342
startTimestamp : browserPerformanceTimeOrigin ? browserPerformanceTimeOrigin / 1000 : undefined ,
337
- op : 'pageload' ,
338
343
origin : 'auto.pageload.browser' ,
339
344
attributes : {
340
345
[ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'url' ,
@@ -363,7 +368,6 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
363
368
startingUrl = undefined ;
364
369
const context : StartSpanOptions = {
365
370
name : WINDOW . location . pathname ,
366
- op : 'navigation' ,
367
371
origin : 'auto.navigation.browser' ,
368
372
attributes : {
369
373
[ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'url' ,
@@ -401,24 +405,32 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
401
405
* Manually start a page load span.
402
406
* This will only do something if the BrowserTracing integration has been setup.
403
407
*/
404
- export function startBrowserTracingPageLoadSpan ( client : Client , spanOptions : StartSpanOptions ) : void {
408
+ export function startBrowserTracingPageLoadSpan ( client : Client , spanOptions : StartSpanOptions ) : Span | undefined {
405
409
if ( ! client . emit ) {
406
410
return ;
407
411
}
408
412
409
413
client . emit ( 'startPageLoadSpan' , spanOptions ) ;
414
+
415
+ const span = getActiveSpan ( ) ;
416
+ const op = span && spanToJSON ( span ) . op ;
417
+ return op === 'pageload' ? span : undefined ;
410
418
}
411
419
412
420
/**
413
421
* Manually start a navigation span.
414
422
* This will only do something if the BrowserTracing integration has been setup.
415
423
*/
416
- export function startBrowserTracingNavigationSpan ( client : Client , spanOptions : StartSpanOptions ) : void {
424
+ export function startBrowserTracingNavigationSpan ( client : Client , spanOptions : StartSpanOptions ) : Span | undefined {
417
425
if ( ! client . emit ) {
418
426
return ;
419
427
}
420
428
421
429
client . emit ( 'startNavigationSpan' , spanOptions ) ;
430
+
431
+ const span = getActiveSpan ( ) ;
432
+ const op = span && spanToJSON ( span ) . op ;
433
+ return op === 'navigation' ? span : undefined ;
422
434
}
423
435
424
436
/** Returns the value of a meta tag */
0 commit comments