@@ -13,7 +13,7 @@ import {
13
13
registerRequestInstrumentation ,
14
14
RequestInstrumentationOptions ,
15
15
} from './request' ;
16
- import { defaultBeforeNavigate , defaultRoutingInstrumentation } from './router' ;
16
+ import { defaultRoutingInstrumentation } from './router' ;
17
17
18
18
export const DEFAULT_MAX_TRANSACTION_DURATION_SECONDS = 600 ;
19
19
@@ -66,7 +66,7 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
66
66
*
67
67
* If undefined is returned, a pageload/navigation transaction will not be created.
68
68
*/
69
- beforeNavigate ( context : TransactionContext ) : TransactionContext | undefined ;
69
+ beforeNavigate ? ( context : TransactionContext ) : TransactionContext | undefined ;
70
70
71
71
/**
72
72
* Instrumentation that creates routing change transactions. By default creates
@@ -80,7 +80,6 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
80
80
}
81
81
82
82
const DEFAULT_BROWSER_TRACING_OPTIONS = {
83
- beforeNavigate : defaultBeforeNavigate ,
84
83
idleTimeout : DEFAULT_IDLE_TIMEOUT ,
85
84
markBackgroundTransactions : true ,
86
85
maxTransactionDuration : DEFAULT_MAX_TRANSACTION_DURATION_SECONDS ,
@@ -189,20 +188,21 @@ export class BrowserTracing implements Integration {
189
188
const { beforeNavigate, idleTimeout, maxTransactionDuration } = this . options ;
190
189
191
190
// if beforeNavigate returns undefined, we should not start a transaction.
192
- const ctx = beforeNavigate ( {
191
+ const expandedContext = {
193
192
...context ,
194
193
...getHeaderContext ( ) ,
195
194
trimEnd : true ,
196
- } ) ;
195
+ } ;
196
+ const modifiedContext = typeof beforeNavigate === 'function' ? beforeNavigate ( expandedContext ) : expandedContext ;
197
197
198
- if ( ctx === undefined ) {
198
+ if ( modifiedContext === undefined ) {
199
199
logger . log ( `[Tracing] Did not create ${ context . op } idleTransaction due to beforeNavigate` ) ;
200
200
return undefined ;
201
201
}
202
202
203
203
const hub = this . _getCurrentHub ( ) ;
204
- logger . log ( `[Tracing] starting ${ ctx . op } idleTransaction on scope` ) ;
205
- const idleTransaction = startIdleTransaction ( hub , ctx , idleTimeout , true ) ;
204
+ logger . log ( `[Tracing] starting ${ modifiedContext . op } idleTransaction on scope` ) ;
205
+ const idleTransaction = startIdleTransaction ( hub , modifiedContext , idleTimeout , true ) ;
206
206
idleTransaction . registerBeforeFinishCallback ( ( transaction , endTimestamp ) => {
207
207
this . _metrics . addPerformanceEntries ( transaction ) ;
208
208
adjustTransactionDuration ( secToMs ( maxTransactionDuration ) , transaction , endTimestamp ) ;
0 commit comments