1- /* eslint-disable max-lines, complexity */
1+ /* eslint-disable max-lines */
22import type { IdleTransaction } from '@sentry/core' ;
3+ import { getActiveSpan } from '@sentry/core' ;
34import { getCurrentHub } from '@sentry/core' ;
45import {
56 SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ,
@@ -237,7 +238,6 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
237238 latestRouteName = finalContext . name ;
238239 latestRouteSource = getSource ( finalContext ) ;
239240
240- // eslint-disable-next-line deprecation/deprecation
241241 if ( finalContext . sampled === false ) {
242242 DEBUG_BUILD && logger . log ( `[Tracing] Will not send ${ finalContext . op } transaction because of beforeNavigate.` ) ;
243243 }
@@ -316,7 +316,10 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
316316 // If there's an open transaction on the scope, we need to finish it before creating an new one.
317317 activeSpan . end ( ) ;
318318 }
319- activeSpan = _createRouteTransaction ( context ) ;
319+ activeSpan = _createRouteTransaction ( {
320+ op : 'navigation' ,
321+ ...context ,
322+ } ) ;
320323 } ) ;
321324
322325 client . on ( 'startPageLoadSpan' , ( context : StartSpanOptions ) => {
@@ -325,7 +328,10 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
325328 // If there's an open transaction on the scope, we need to finish it before creating an new one.
326329 activeSpan . end ( ) ;
327330 }
328- activeSpan = _createRouteTransaction ( context ) ;
331+ activeSpan = _createRouteTransaction ( {
332+ op : 'pageload' ,
333+ ...context ,
334+ } ) ;
329335 } ) ;
330336 }
331337
@@ -334,7 +340,6 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
334340 name : WINDOW . location . pathname ,
335341 // pageload should always start at timeOrigin (and needs to be in s, not ms)
336342 startTimestamp : browserPerformanceTimeOrigin ? browserPerformanceTimeOrigin / 1000 : undefined ,
337- op : 'pageload' ,
338343 origin : 'auto.pageload.browser' ,
339344 attributes : {
340345 [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'url' ,
@@ -363,7 +368,6 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
363368 startingUrl = undefined ;
364369 const context : StartSpanOptions = {
365370 name : WINDOW . location . pathname ,
366- op : 'navigation' ,
367371 origin : 'auto.navigation.browser' ,
368372 attributes : {
369373 [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'url' ,
@@ -401,24 +405,32 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
401405 * Manually start a page load span.
402406 * This will only do something if the BrowserTracing integration has been setup.
403407 */
404- export function startBrowserTracingPageLoadSpan ( client : Client , spanOptions : StartSpanOptions ) : void {
408+ export function startBrowserTracingPageLoadSpan ( client : Client , spanOptions : StartSpanOptions ) : Span | undefined {
405409 if ( ! client . emit ) {
406410 return ;
407411 }
408412
409413 client . emit ( 'startPageLoadSpan' , spanOptions ) ;
414+
415+ const span = getActiveSpan ( ) ;
416+ const op = span && spanToJSON ( span ) . op ;
417+ return op === 'pageload' ? span : undefined ;
410418}
411419
412420/**
413421 * Manually start a navigation span.
414422 * This will only do something if the BrowserTracing integration has been setup.
415423 */
416- export function startBrowserTracingNavigationSpan ( client : Client , spanOptions : StartSpanOptions ) : void {
424+ export function startBrowserTracingNavigationSpan ( client : Client , spanOptions : StartSpanOptions ) : Span | undefined {
417425 if ( ! client . emit ) {
418426 return ;
419427 }
420428
421429 client . emit ( 'startNavigationSpan' , spanOptions ) ;
430+
431+ const span = getActiveSpan ( ) ;
432+ const op = span && spanToJSON ( span ) . op ;
433+ return op === 'navigation' ? span : undefined ;
422434}
423435
424436/** Returns the value of a meta tag */
0 commit comments