55 isMatchingPattern ,
66 logger ,
77 supportsNativeFetch ,
8- timestampWithMs ,
98} from '@sentry/utils' ;
109
1110import { Span as SpanClass } from '../span' ;
@@ -43,6 +42,7 @@ interface TracingOptions {
4342 /**
4443 * The time to wait in ms until the transaction will be finished. The transaction will use the end timestamp of
4544 * the last finished span as the endtime for the transaction.
45+ * Time is in ms.
4646 *
4747 * Default: 500
4848 */
@@ -65,14 +65,15 @@ interface TracingOptions {
6565 tracesSampleRate : number ;
6666
6767 /**
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.
7273 *
73- * Default: 600000 = 10min
74+ * Default: 600
7475 */
75- maxTransactionTimeout : number ;
76+ maxTransactionDuration : number ;
7677}
7778
7879/** JSDoc */
@@ -127,7 +128,7 @@ export class Tracing implements Integration {
127128 const defaultTracingOrigins = [ 'localhost' , / ^ \/ / ] ;
128129 const defaults = {
129130 idleTimeout : 500 ,
130- maxTransactionTimeout : 600000 ,
131+ maxTransactionDuration : 600 ,
131132 shouldCreateSpanForRequest ( url : string ) : boolean {
132133 const origins = ( _options && _options . tracingOrigins ) || defaultTracingOrigins ;
133134 return (
@@ -194,18 +195,21 @@ export class Tracing implements Integration {
194195 } ) ;
195196 }
196197
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
198199 addGlobalEventProcessor ( ( event : Event ) => {
199200 const self = getCurrentHub ( ) . getIntegration ( Tracing ) ;
200201 if ( ! self ) {
201202 return event ;
202203 }
203204
204205 if (
206+ Tracing . options . maxTransactionDuration !== 0 &&
207+ Tracing . _isEnabled ( ) &&
205208 event . type === 'transaction' &&
206209 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 )
209213 ) {
210214 return null ;
211215 }
@@ -302,16 +306,8 @@ export class Tracing implements Integration {
302306 public static finishIdleTransaction ( ) : void {
303307 const active = Tracing . _activeTransaction as SpanClass ;
304308 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 ) ;
315311 }
316312 }
317313
0 commit comments