8
8
startBrowserTracingPageLoadSpan ,
9
9
withErrorBoundary ,
10
10
} from '@sentry/react' ;
11
- import type { Span , Transaction , TransactionContext } from '@sentry/types' ;
11
+ import type { Span , StartSpanOptions , Transaction , TransactionContext } from '@sentry/types' ;
12
12
import { isNodeEnv , logger } from '@sentry/utils' ;
13
13
import * as React from 'react' ;
14
14
@@ -41,16 +41,12 @@ export type RemixBrowserTracingIntegrationOptions = Partial<Parameters<typeof or
41
41
useEffect ?: UseEffect ;
42
42
useLocation ?: UseLocation ;
43
43
useMatches ?: UseMatches ;
44
- startTransactionOnPageLoad ?: boolean ;
45
- startTransactionOnLocationChange ?: boolean ;
46
44
} ;
47
45
48
46
const DEFAULT_TAGS = {
49
47
'routing.instrumentation' : 'remix-router' ,
50
48
} as const ;
51
49
52
- let activeRootSpan : Span | undefined ;
53
-
54
50
let _useEffect : UseEffect | undefined ;
55
51
let _useLocation : UseLocation | undefined ;
56
52
let _useMatches : UseMatches | undefined ;
@@ -77,6 +73,16 @@ export function startPageloadSpan(): void {
77
73
return ;
78
74
}
79
75
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
+
80
86
// If _customStartTransaction is not defined, we know that we are using the browserTracingIntegration
81
87
if ( ! _customStartTransaction ) {
82
88
const client = getClient < BrowserClient > ( ) ;
@@ -85,31 +91,23 @@ export function startPageloadSpan(): void {
85
91
return ;
86
92
}
87
93
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 ) ;
99
95
} 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 ) ;
109
97
}
110
98
}
111
99
112
100
function 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
+
113
111
// If _customStartTransaction is not defined, we know that we are using the browserTracingIntegration
114
112
if ( ! _customStartTransaction ) {
115
113
const client = getClient < BrowserClient > ( ) ;
@@ -118,27 +116,9 @@ function startNavigationSpan(matches: RouteMatch<string>[]): void {
118
116
return ;
119
117
}
120
118
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 ) ;
132
120
} 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 ) ;
142
122
}
143
123
}
144
124
@@ -208,6 +188,7 @@ export function withSentry<P extends Record<string, unknown>, R extends React.Co
208
188
209
189
_useEffect ( ( ) => {
210
190
const activeRootSpan = getActiveSpan ( ) ;
191
+
211
192
if ( activeRootSpan && matches && matches . length ) {
212
193
const transaction = getRootSpan ( activeRootSpan ) ;
213
194
@@ -221,6 +202,8 @@ export function withSentry<P extends Record<string, unknown>, R extends React.Co
221
202
} , [ ] ) ;
222
203
223
204
_useEffect ( ( ) => {
205
+ const activeRootSpan = getActiveSpan ( ) ;
206
+
224
207
if ( isBaseLocation ) {
225
208
if ( activeRootSpan ) {
226
209
activeRootSpan . end ( ) ;
0 commit comments