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
}
@@ -315,7 +315,10 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
315
315
// If there's an open transaction on the scope, we need to finish it before creating an new one.
316
316
activeSpan . end ( ) ;
317
317
}
318
- activeSpan = _createRouteTransaction ( context ) ;
318
+ activeSpan = _createRouteTransaction ( {
319
+ op : 'navigation' ,
320
+ ...context ,
321
+ } ) ;
319
322
} ) ;
320
323
321
324
client . on ( 'startPageLoadSpan' , ( context : StartSpanOptions ) => {
@@ -324,15 +327,17 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
324
327
// If there's an open transaction on the scope, we need to finish it before creating an new one.
325
328
activeSpan . end ( ) ;
326
329
}
327
- activeSpan = _createRouteTransaction ( context ) ;
330
+ activeSpan = _createRouteTransaction ( {
331
+ op : 'pageload' ,
332
+ ...context ,
333
+ } ) ;
328
334
} ) ;
329
335
330
336
if ( options . instrumentPageLoad ) {
331
337
const context : StartSpanOptions = {
332
338
name : WINDOW . location . pathname ,
333
339
// pageload should always start at timeOrigin (and needs to be in s, not ms)
334
340
startTimestamp : browserPerformanceTimeOrigin ? browserPerformanceTimeOrigin / 1000 : undefined ,
335
- op : 'pageload' ,
336
341
origin : 'auto.pageload.browser' ,
337
342
attributes : {
338
343
[ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'url' ,
@@ -361,7 +366,6 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
361
366
startingUrl = undefined ;
362
367
const context : StartSpanOptions = {
363
368
name : WINDOW . location . pathname ,
364
- op : 'navigation' ,
365
369
origin : 'auto.navigation.browser' ,
366
370
attributes : {
367
371
[ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'url' ,
@@ -399,16 +403,24 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
399
403
* Manually start a page load span.
400
404
* This will only do something if the BrowserTracing integration has been setup.
401
405
*/
402
- export function startBrowserTracingPageLoadSpan ( client : Client , spanOptions : StartSpanOptions ) : void {
406
+ export function startBrowserTracingPageLoadSpan ( client : Client , spanOptions : StartSpanOptions ) : Span | undefined {
403
407
client . emit ( 'startPageLoadSpan' , spanOptions ) ;
408
+
409
+ const span = getActiveSpan ( ) ;
410
+ const op = span && spanToJSON ( span ) . op ;
411
+ return op === 'pageload' ? span : undefined ;
404
412
}
405
413
406
414
/**
407
415
* Manually start a navigation span.
408
416
* This will only do something if the BrowserTracing integration has been setup.
409
417
*/
410
- export function startBrowserTracingNavigationSpan ( client : Client , spanOptions : StartSpanOptions ) : void {
418
+ export function startBrowserTracingNavigationSpan ( client : Client , spanOptions : StartSpanOptions ) : Span | undefined {
411
419
client . emit ( 'startNavigationSpan' , spanOptions ) ;
420
+
421
+ const span = getActiveSpan ( ) ;
422
+ const op = span && spanToJSON ( span ) . op ;
423
+ return op === 'navigation' ? span : undefined ;
412
424
}
413
425
414
426
/** Returns the value of a meta tag */
0 commit comments