1
- /* eslint-disable max-lines, complexity */
1
+ /* eslint-disable max-lines */
2
2
import type { Hub , IdleTransaction } from '@sentry/core' ;
3
3
import {
4
4
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ,
@@ -9,14 +9,7 @@ import {
9
9
spanToJSON ,
10
10
startIdleTransaction ,
11
11
} from '@sentry/core' ;
12
- import type {
13
- EventProcessor ,
14
- Integration ,
15
- StartSpanOptions ,
16
- Transaction ,
17
- TransactionContext ,
18
- TransactionSource ,
19
- } from '@sentry/types' ;
12
+ import type { EventProcessor , Integration , Transaction , TransactionContext , TransactionSource } from '@sentry/types' ;
20
13
import { getDomElement , logger , tracingContextFromHeaders } from '@sentry/utils' ;
21
14
22
15
import { DEBUG_BUILD } from '../common/debug-build' ;
@@ -66,49 +59,28 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
66
59
*/
67
60
heartbeatInterval : number ;
68
61
69
- /**
70
- * If a span should be created on location (history) changes.
71
- * Default: true
72
- */
73
- spanOnLocationChange : boolean ;
74
-
75
- /**
76
- * If a span should be created on pageload.
77
- * Default: true
78
- */
79
- spanOnPageLoad : boolean ;
80
-
81
- /**
82
- * Flag spans where tabs moved to background with "cancelled". Browser background tab timing is
83
- * not suited towards doing precise measurements of operations. By default, we recommend that this option
84
- * be enabled as background transactions can mess up your statistics in nondeterministic ways.
85
- *
86
- * Default: true
87
- */
88
- markBackgroundSpan : boolean ;
89
-
90
62
/**
91
63
* Flag to enable/disable creation of `navigation` transaction on history changes.
64
+ *
92
65
* Default: true
93
- * @deprecated Configure `spanOnLocationChange` instead.
94
66
*/
95
- startTransactionOnLocationChange ? : boolean ;
67
+ startTransactionOnLocationChange : boolean ;
96
68
97
69
/**
98
70
* Flag to enable/disable creation of `pageload` transaction on first pageload.
71
+ *
99
72
* Default: true
100
- * @deprecated Configure `spanOnPageLoad` instead.
101
73
*/
102
- startTransactionOnPageLoad ? : boolean ;
74
+ startTransactionOnPageLoad : boolean ;
103
75
104
76
/**
105
77
* Flag Transactions where tabs moved to background with "cancelled". Browser background tab timing is
106
78
* not suited towards doing precise measurements of operations. By default, we recommend that this option
107
79
* be enabled as background transactions can mess up your statistics in nondeterministic ways.
80
+ *
108
81
* Default: true
109
- * @deprecated Configure `markBackgroundSpan` instead.
110
82
*/
111
- markBackgroundTransactions ? : boolean ;
83
+ markBackgroundTransactions : boolean ;
112
84
113
85
/**
114
86
* If true, Sentry will capture long tasks and add them to the corresponding transaction.
@@ -145,12 +117,6 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
145
117
onStartRouteTransaction : ( t : Transaction | undefined , ctx : TransactionContext , getCurrentHub : ( ) => Hub ) => void ;
146
118
} > ;
147
119
148
- /**
149
- * A callback which is called before a span for a pageload or navigation is started.
150
- * It receives the options passed to `startSpan`, and expects to return an updated options object.
151
- */
152
- beforeStartSpan ?: ( options : StartSpanOptions ) => StartSpanOptions ;
153
-
154
120
/**
155
121
* beforeNavigate is called before a pageload/navigation transaction is created and allows users to modify transaction
156
122
* context data, or drop the transaction entirely (by setting `sampled = false` in the context).
@@ -160,8 +126,6 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
160
126
* @param context: The context data which will be passed to `startTransaction` by default
161
127
*
162
128
* @returns A (potentially) modified context object, with `sampled = false` if the transaction should be dropped.
163
- *
164
- * @deprecated Use `beforeStartSpan` instead.
165
129
*/
166
130
beforeNavigate ?( this : void , context : TransactionContext ) : TransactionContext | undefined ;
167
131
@@ -179,10 +143,10 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
179
143
180
144
const DEFAULT_BROWSER_TRACING_OPTIONS : BrowserTracingOptions = {
181
145
...TRACING_DEFAULTS ,
146
+ markBackgroundTransactions : true ,
182
147
routingInstrumentation : instrumentRoutingWithDefaults ,
183
- spanOnLocationChange : true ,
184
- spanOnPageLoad : true ,
185
- markBackgroundSpan : true ,
148
+ startTransactionOnLocationChange : true ,
149
+ startTransactionOnPageLoad : true ,
186
150
enableLongTask : true ,
187
151
_experiments : { } ,
188
152
...defaultRequestInstrumentationOptions ,
@@ -226,42 +190,20 @@ export class BrowserTracing implements Integration {
226
190
227
191
private _hasSetTracePropagationTargets : boolean ;
228
192
229
- public constructor ( _options : Partial < BrowserTracingOptions > = { } ) {
193
+ public constructor ( _options ? : Partial < BrowserTracingOptions > ) {
230
194
this . name = BROWSER_TRACING_INTEGRATION_ID ;
231
195
this . _hasSetTracePropagationTargets = false ;
232
196
233
197
addTracingExtensions ( ) ;
234
198
235
199
if ( DEBUG_BUILD ) {
236
200
this . _hasSetTracePropagationTargets = ! ! (
201
+ _options &&
237
202
// eslint-disable-next-line deprecation/deprecation
238
203
( _options . tracePropagationTargets || _options . tracingOrigins )
239
204
) ;
240
205
}
241
206
242
- // Migrate legacy options
243
- // TODO v8: Remove this
244
- /* eslint-disable deprecation/deprecation */
245
- if ( typeof _options . startTransactionOnPageLoad === 'boolean' ) {
246
- _options . spanOnPageLoad = _options . startTransactionOnPageLoad ;
247
- }
248
- if ( typeof _options . startTransactionOnLocationChange === 'boolean' ) {
249
- _options . spanOnLocationChange = _options . startTransactionOnLocationChange ;
250
- }
251
- if ( typeof _options . markBackgroundTransactions === 'boolean' ) {
252
- _options . markBackgroundSpan = _options . markBackgroundTransactions ;
253
- }
254
- /* eslint-enable deprecation/deprecation */
255
-
256
- // TODO (v8): remove this block after tracingOrigins is removed
257
- // Set tracePropagationTargets to tracingOrigins if specified by the user
258
- // In case both are specified, tracePropagationTargets takes precedence
259
- // eslint-disable-next-line deprecation/deprecation
260
- if ( ! _options . tracePropagationTargets && _options . tracingOrigins ) {
261
- // eslint-disable-next-line deprecation/deprecation
262
- _options . tracePropagationTargets = _options . tracingOrigins ;
263
- }
264
-
265
207
this . options = {
266
208
...DEFAULT_BROWSER_TRACING_OPTIONS ,
267
209
..._options ,
@@ -273,6 +215,15 @@ export class BrowserTracing implements Integration {
273
215
this . options . enableLongTask = this . options . _experiments . enableLongTask ;
274
216
}
275
217
218
+ // TODO (v8): remove this block after tracingOrigins is removed
219
+ // Set tracePropagationTargets to tracingOrigins if specified by the user
220
+ // In case both are specified, tracePropagationTargets takes precedence
221
+ // eslint-disable-next-line deprecation/deprecation
222
+ if ( _options && ! _options . tracePropagationTargets && _options . tracingOrigins ) {
223
+ // eslint-disable-next-line deprecation/deprecation
224
+ this . options . tracePropagationTargets = _options . tracingOrigins ;
225
+ }
226
+
276
227
this . _collectWebVitals = startTrackingWebVitals ( ) ;
277
228
if ( this . options . enableLongTask ) {
278
229
startTrackingLongTasks ( ) ;
@@ -294,9 +245,9 @@ export class BrowserTracing implements Integration {
294
245
295
246
const {
296
247
routingInstrumentation : instrumentRouting ,
297
- spanOnPageLoad ,
298
- spanOnLocationChange ,
299
- markBackgroundSpan ,
248
+ startTransactionOnLocationChange ,
249
+ startTransactionOnPageLoad ,
250
+ markBackgroundTransactions ,
300
251
traceFetch,
301
252
traceXHR,
302
253
shouldCreateSpanForRequest,
@@ -332,11 +283,11 @@ export class BrowserTracing implements Integration {
332
283
333
284
return transaction ;
334
285
} ,
335
- spanOnPageLoad ,
336
- spanOnLocationChange ,
286
+ startTransactionOnPageLoad ,
287
+ startTransactionOnLocationChange ,
337
288
) ;
338
289
339
- if ( markBackgroundSpan ) {
290
+ if ( markBackgroundTransactions ) {
340
291
registerBackgroundTabDetection ( ) ;
341
292
}
342
293
@@ -363,14 +314,7 @@ export class BrowserTracing implements Integration {
363
314
364
315
const hub = this . _getCurrentHub ( ) ;
365
316
366
- const {
367
- // eslint-disable-next-line deprecation/deprecation
368
- beforeNavigate,
369
- beforeStartSpan,
370
- idleTimeout,
371
- finalTimeout,
372
- heartbeatInterval,
373
- } = this . options ;
317
+ const { beforeNavigate, idleTimeout, finalTimeout, heartbeatInterval } = this . options ;
374
318
375
319
const isPageloadTransaction = context . op === 'pageload' ;
376
320
@@ -392,11 +336,7 @@ export class BrowserTracing implements Integration {
392
336
trimEnd : true ,
393
337
} ;
394
338
395
- const contextAfterProcessing = beforeStartSpan ? beforeStartSpan ( expandedContext ) : expandedContext ;
396
-
397
- const modifiedContext =
398
- // eslint-disable-next-line deprecation/deprecation
399
- typeof beforeNavigate === 'function' ? beforeNavigate ( contextAfterProcessing ) : contextAfterProcessing ;
339
+ const modifiedContext = typeof beforeNavigate === 'function' ? beforeNavigate ( expandedContext ) : expandedContext ;
400
340
401
341
// For backwards compatibility reasons, beforeNavigate can return undefined to "drop" the transaction (prevent it
402
342
// from being sent to Sentry).
0 commit comments