@@ -5,8 +5,11 @@ import {
5
5
isMatchingPattern ,
6
6
logger ,
7
7
supportsNativeFetch ,
8
+ timestampWithMs ,
8
9
} from '@sentry/utils' ;
9
10
11
+ import { Span as SpanClass } from '../span' ;
12
+
10
13
/**
11
14
* Options for Tracing integration
12
15
*/
@@ -60,6 +63,15 @@ interface TracingOptions {
60
63
* Default: 1
61
64
*/
62
65
tracesSampleRate : number ;
66
+
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
+ * Time is in ms.
71
+ *
72
+ * Default: 120000
73
+ */
74
+ maxTransactionTimeout : number ;
63
75
}
64
76
65
77
/** JSDoc */
@@ -114,6 +126,7 @@ export class Tracing implements Integration {
114
126
const defaultTracingOrigins = [ 'localhost' , / ^ \/ / ] ;
115
127
const defaults = {
116
128
idleTimeout : 500 ,
129
+ maxTransactionTimeout : 120000 ,
117
130
shouldCreateSpanForRequest ( url : string ) : boolean {
118
131
const origins = ( _options && _options . tracingOrigins ) || defaultTracingOrigins ;
119
132
return (
@@ -249,24 +262,39 @@ export class Tracing implements Integration {
249
262
250
263
/**
251
264
* Update transaction
265
+ * @deprecated
252
266
*/
253
267
public static updateTransactionName ( name : string ) : void {
254
- const activeTransaction = Tracing . _activeTransaction ;
255
- if ( ! activeTransaction ) {
256
- return ;
268
+ // const activeTransaction = Tracing._activeTransaction;
269
+ // if (!activeTransaction) {
270
+ // return;
271
+ // }
272
+ const _getCurrentHub = Tracing . _getCurrentHub ;
273
+ if ( _getCurrentHub ) {
274
+ const hub = _getCurrentHub ( ) ;
275
+ if ( hub ) {
276
+ hub . configureScope ( scope => {
277
+ scope . setTransaction ( name ) ;
278
+ } ) ;
279
+ }
257
280
}
258
281
// TODO
259
- ( activeTransaction as any ) . transaction = name ;
282
+ // (activeTransaction as any).transaction = name;
260
283
}
261
284
262
285
/**
263
286
* Finshes the current active transaction
264
287
*/
265
288
public static finishIdleTransaction ( ) : void {
266
- const active = Tracing . _activeTransaction ;
289
+ const active = Tracing . _activeTransaction as SpanClass ;
267
290
if ( active ) {
268
- // true = use timestamp of last span
269
- active . finish ( true ) ;
291
+ if ( timestampWithMs ( ) > active . startTimestamp + Tracing . options . maxTransactionTimeout ) {
292
+ // If we reached the max timeout of the transaction, we will just not finish it and therefore discard it.
293
+ Tracing . _activeTransaction = undefined ;
294
+ } else {
295
+ // true = use timestamp of last span
296
+ active . finish ( true ) ;
297
+ }
270
298
}
271
299
}
272
300
0 commit comments