5
5
isMatchingPattern ,
6
6
logger ,
7
7
supportsNativeFetch ,
8
- timestampWithMs ,
9
8
} from '@sentry/utils' ;
10
9
11
10
import { Span as SpanClass } from '../span' ;
@@ -43,6 +42,7 @@ interface TracingOptions {
43
42
/**
44
43
* The time to wait in ms until the transaction will be finished. The transaction will use the end timestamp of
45
44
* the last finished span as the endtime for the transaction.
45
+ * Time is in ms.
46
46
*
47
47
* Default: 500
48
48
*/
@@ -65,14 +65,15 @@ interface TracingOptions {
65
65
tracesSampleRate : number ;
66
66
67
67
/**
68
- * The maximum time a transaction can be before it will be dropped. This is for some edge cases where a browser
69
- * completely freezes the JS state and picks it up later. So after this timeout, the SDK will not send the event.
70
- * If you want to have an unlimited timeout set it to 0.
71
- * Time is in ms.
68
+ * The maximum duration of a transaction before it will be discarded. This is for some edge cases where a browser
69
+ * completely freezes the JS state and picks it up later (background tabs).
70
+ * So after this duration, the SDK will not send the event.
71
+ * If you want to have an unlimited duration set it to 0.
72
+ * Time is in seconds.
72
73
*
73
- * Default: 600000 = 10min
74
+ * Default: 600
74
75
*/
75
- maxTransactionTimeout : number ;
76
+ maxTransactionDuration : number ;
76
77
}
77
78
78
79
/** JSDoc */
@@ -127,7 +128,7 @@ export class Tracing implements Integration {
127
128
const defaultTracingOrigins = [ 'localhost' , / ^ \/ / ] ;
128
129
const defaults = {
129
130
idleTimeout : 500 ,
130
- maxTransactionTimeout : 600000 ,
131
+ maxTransactionDuration : 600 ,
131
132
shouldCreateSpanForRequest ( url : string ) : boolean {
132
133
const origins = ( _options && _options . tracingOrigins ) || defaultTracingOrigins ;
133
134
return (
@@ -194,18 +195,21 @@ export class Tracing implements Integration {
194
195
} ) ;
195
196
}
196
197
197
- // This EventProcessor makes sure that we never send an transaction that is older than maxTransactionTimeout
198
+ // This EventProcessor makes sure that the transaction is not longer than maxTransactionDuration
198
199
addGlobalEventProcessor ( ( event : Event ) => {
199
200
const self = getCurrentHub ( ) . getIntegration ( Tracing ) ;
200
201
if ( ! self ) {
201
202
return event ;
202
203
}
203
204
204
205
if (
206
+ Tracing . options . maxTransactionDuration !== 0 &&
207
+ Tracing . _isEnabled ( ) &&
205
208
event . type === 'transaction' &&
206
209
event . timestamp &&
207
- Tracing . options . maxTransactionTimeout !== 0 &&
208
- timestampWithMs ( ) > event . timestamp + Tracing . options . maxTransactionTimeout
210
+ event . start_timestamp &&
211
+ ( event . timestamp - event . start_timestamp > Tracing . options . maxTransactionDuration ||
212
+ event . timestamp - event . start_timestamp < 0 )
209
213
) {
210
214
return null ;
211
215
}
@@ -302,16 +306,8 @@ export class Tracing implements Integration {
302
306
public static finishIdleTransaction ( ) : void {
303
307
const active = Tracing . _activeTransaction as SpanClass ;
304
308
if ( active ) {
305
- if (
306
- Tracing . options . maxTransactionTimeout !== 0 &&
307
- timestampWithMs ( ) > active . startTimestamp + Tracing . options . maxTransactionTimeout
308
- ) {
309
- // If we reached the max timeout of the transaction, we will just not finish it and therefore discard it.
310
- Tracing . _activeTransaction = undefined ;
311
- } else {
312
- // true = use timestamp of last span
313
- active . finish ( true ) ;
314
- }
309
+ // true = use timestamp of last span
310
+ active . finish ( true ) ;
315
311
}
316
312
}
317
313
0 commit comments