88 startBrowserTracingPageLoadSpan ,
99 withErrorBoundary ,
1010} from '@sentry/react' ;
11- import type { Span , Transaction , TransactionContext } from '@sentry/types' ;
11+ import type { Span , StartSpanOptions , Transaction , TransactionContext } from '@sentry/types' ;
1212import { isNodeEnv , logger } from '@sentry/utils' ;
1313import * as React from 'react' ;
1414
@@ -41,16 +41,12 @@ export type RemixBrowserTracingIntegrationOptions = Partial<Parameters<typeof or
4141 useEffect ?: UseEffect ;
4242 useLocation ?: UseLocation ;
4343 useMatches ?: UseMatches ;
44- startTransactionOnPageLoad ?: boolean ;
45- startTransactionOnLocationChange ?: boolean ;
4644} ;
4745
4846const DEFAULT_TAGS = {
4947 'routing.instrumentation' : 'remix-router' ,
5048} as const ;
5149
52- let activeRootSpan : Span | undefined ;
53-
5450let _useEffect : UseEffect | undefined ;
5551let _useLocation : UseLocation | undefined ;
5652let _useMatches : UseMatches | undefined ;
@@ -77,6 +73,16 @@ export function startPageloadSpan(): void {
7773 return ;
7874 }
7975
76+ const spanContext : StartSpanOptions = {
77+ name : initPathName ,
78+ op : 'pageload' ,
79+ origin : 'auto.pageload.remix' ,
80+ tags : DEFAULT_TAGS ,
81+ metadata : {
82+ source : 'url' ,
83+ } ,
84+ } ;
85+
8086 // If _customStartTransaction is not defined, we know that we are using the browserTracingIntegration
8187 if ( ! _customStartTransaction ) {
8288 const client = getClient < BrowserClient > ( ) ;
@@ -85,31 +91,23 @@ export function startPageloadSpan(): void {
8591 return ;
8692 }
8793
88- startBrowserTracingPageLoadSpan ( client , {
89- name : initPathName ,
90- op : 'pageload' ,
91- origin : 'auto.pageload.remix' ,
92- tags : DEFAULT_TAGS ,
93- metadata : {
94- source : 'url' ,
95- } ,
96- } ) ;
97-
98- activeRootSpan = getActiveSpan ( ) ;
94+ startBrowserTracingPageLoadSpan ( client , spanContext ) ;
9995 } else {
100- activeRootSpan = _customStartTransaction ( {
101- name : initPathName ,
102- op : 'pageload' ,
103- origin : 'auto.pageload.remix' ,
104- tags : DEFAULT_TAGS ,
105- metadata : {
106- source : 'url' ,
107- } ,
108- } ) ;
96+ _customStartTransaction ( spanContext ) ;
10997 }
11098}
11199
112100function startNavigationSpan ( matches : RouteMatch < string > [ ] ) : void {
101+ const spanContext : StartSpanOptions = {
102+ name : matches [ matches . length - 1 ] . id ,
103+ op : 'navigation' ,
104+ origin : 'auto.navigation.remix' ,
105+ tags : DEFAULT_TAGS ,
106+ metadata : {
107+ source : 'route' ,
108+ } ,
109+ } ;
110+
113111 // If _customStartTransaction is not defined, we know that we are using the browserTracingIntegration
114112 if ( ! _customStartTransaction ) {
115113 const client = getClient < BrowserClient > ( ) ;
@@ -118,27 +116,9 @@ function startNavigationSpan(matches: RouteMatch<string>[]): void {
118116 return ;
119117 }
120118
121- startBrowserTracingNavigationSpan ( client , {
122- name : matches [ matches . length - 1 ] . id ,
123- op : 'navigation' ,
124- origin : 'auto.navigation.remix' ,
125- tags : DEFAULT_TAGS ,
126- metadata : {
127- source : 'route' ,
128- } ,
129- } ) ;
130-
131- activeRootSpan = getActiveSpan ( ) ;
119+ startBrowserTracingNavigationSpan ( client , spanContext ) ;
132120 } else {
133- activeRootSpan = _customStartTransaction ( {
134- name : matches [ matches . length - 1 ] . id ,
135- op : 'navigation' ,
136- origin : 'auto.navigation.remix' ,
137- tags : DEFAULT_TAGS ,
138- metadata : {
139- source : 'route' ,
140- } ,
141- } ) ;
121+ _customStartTransaction ( spanContext ) ;
142122 }
143123}
144124
@@ -208,6 +188,7 @@ export function withSentry<P extends Record<string, unknown>, R extends React.Co
208188
209189 _useEffect ( ( ) => {
210190 const activeRootSpan = getActiveSpan ( ) ;
191+
211192 if ( activeRootSpan && matches && matches . length ) {
212193 const transaction = getRootSpan ( activeRootSpan ) ;
213194
@@ -221,6 +202,8 @@ export function withSentry<P extends Record<string, unknown>, R extends React.Co
221202 } , [ ] ) ;
222203
223204 _useEffect ( ( ) => {
205+ const activeRootSpan = getActiveSpan ( ) ;
206+
224207 if ( isBaseLocation ) {
225208 if ( activeRootSpan ) {
226209 activeRootSpan . end ( ) ;
0 commit comments