@@ -5,8 +5,11 @@ import {
55 isMatchingPattern ,
66 logger ,
77 supportsNativeFetch ,
8+ timestampWithMs ,
89} from '@sentry/utils' ;
910
11+ import { Span as SpanClass } from '../span' ;
12+
1013/**
1114 * Options for Tracing integration
1215 */
@@ -60,6 +63,15 @@ interface TracingOptions {
6063 * Default: 1
6164 */
6265 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 ;
6375}
6476
6577/** JSDoc */
@@ -114,6 +126,7 @@ export class Tracing implements Integration {
114126 const defaultTracingOrigins = [ 'localhost' , / ^ \/ / ] ;
115127 const defaults = {
116128 idleTimeout : 500 ,
129+ maxTransactionTimeout : 120000 ,
117130 shouldCreateSpanForRequest ( url : string ) : boolean {
118131 const origins = ( _options && _options . tracingOrigins ) || defaultTracingOrigins ;
119132 return (
@@ -249,24 +262,39 @@ export class Tracing implements Integration {
249262
250263 /**
251264 * Update transaction
265+ * @deprecated
252266 */
253267 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+ }
257280 }
258281 // TODO
259- ( activeTransaction as any ) . transaction = name ;
282+ // (activeTransaction as any).transaction = name;
260283 }
261284
262285 /**
263286 * Finshes the current active transaction
264287 */
265288 public static finishIdleTransaction ( ) : void {
266- const active = Tracing . _activeTransaction ;
289+ const active = Tracing . _activeTransaction as SpanClass ;
267290 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+ }
270298 }
271299 }
272300
0 commit comments