File tree Expand file tree Collapse file tree 3 files changed +22
-9
lines changed
browser-utils/src/metrics Expand file tree Collapse file tree 3 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -238,13 +238,9 @@ export function listenForWebVitalReportEvents(
238238 }
239239 } ) ;
240240
241- const activeSpan = getActiveSpan ( ) ;
242- if ( activeSpan ) {
243- const rootSpan = getRootSpan ( activeSpan ) ;
244- const spanJSON = spanToJSON ( rootSpan ) ;
245- if ( spanJSON . op === 'pageload' ) {
246- pageloadSpanId = rootSpan . spanContext ( ) . spanId ;
247- }
248- }
241+ const unsubscribeAfterStartPageLoadSpan = client . on ( 'afterStartPageLoadSpan' , span => {
242+ pageloadSpanId = span . spanContext ( ) . spanId ;
243+ unsubscribeAfterStartPageLoadSpan ?.( ) ;
244+ } ) ;
249245 } , 0 ) ;
250246}
Original file line number Diff line number Diff line change @@ -644,7 +644,13 @@ export function startBrowserTracingPageLoadSpan(
644644 client . emit ( 'startPageLoadSpan' , spanOptions , traceOptions ) ;
645645 getCurrentScope ( ) . setTransactionName ( spanOptions . name ) ;
646646
647- return getActiveIdleSpan ( client ) ;
647+ const pageloadSpan = getActiveIdleSpan ( client ) ;
648+
649+ if ( pageloadSpan ) {
650+ client . emit ( 'afterStartPageLoadSpan' , pageloadSpan ) ;
651+ }
652+
653+ return pageloadSpan ;
648654}
649655
650656/**
Original file line number Diff line number Diff line change @@ -603,6 +603,12 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
603603 ) => void ,
604604 ) : ( ) => void ;
605605
606+ /**
607+ * A hook for the browser tracing integrations to trigger after the pageload span was started.
608+ * @returns {() => void } A function that, when executed, removes the registered callback.
609+ */
610+ public on ( hook : 'afterStartPageLoadSpan' , callback : ( span : Span ) => void ) : ( ) => void ;
611+
606612 /**
607613 * A hook for triggering right before a navigation span is started.
608614 * @returns {() => void } A function that, when executed, removes the registered callback.
@@ -791,6 +797,11 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
791797 traceOptions ?: { sentryTrace ?: string | undefined ; baggage ?: string | undefined } ,
792798 ) : void ;
793799
800+ /**
801+ * Emit a hook event for browser tracing integrations to trigger aafter the pageload span was started.
802+ */
803+ public emit ( hook : 'afterStartPageLoadSpan' , span : Span ) : void ;
804+
794805 /**
795806 * Emit a hook event for triggering right before a navigation span is started.
796807 */
You can’t perform that action at this time.
0 commit comments