1
1
import { EventProcessor , Hub , Integration , Scope , Span , SpanContext } from '@sentry/types' ;
2
+ import { timestampWithMs } from '@sentry/utils' ;
2
3
3
4
/** JSDoc */
4
5
interface TransactionActivityOptions {
@@ -69,8 +70,8 @@ export class TransactionActivity implements Integration {
69
70
*/
70
71
private static _watchActivity ( ) : void {
71
72
const count = Object . keys ( TransactionActivity . _activities ) . length ;
73
+ clearTimeout ( TransactionActivity . _debounce ) ;
72
74
if ( count > 0 ) {
73
- clearTimeout ( TransactionActivity . _debounce ) ;
74
75
setTimeout ( ( ) => {
75
76
TransactionActivity . _watchActivity ( ) ;
76
77
} , 10 ) ;
@@ -79,7 +80,7 @@ export class TransactionActivity implements Integration {
79
80
TransactionActivity . _debounce = ( setTimeout ( ( ) => {
80
81
const active = TransactionActivity . _activeTransaction ;
81
82
if ( active ) {
82
- active . finish ( new Date ( ) . getTime ( ) / 1000 - ( timeout || 0 ) ) ;
83
+ active . finish ( timestampWithMs ( ) - ( timeout || 0 ) ) ;
83
84
}
84
85
} , timeout ) as any ) as number ; // TODO 500
85
86
}
@@ -89,6 +90,13 @@ export class TransactionActivity implements Integration {
89
90
* Starts a Transaction waiting for activity idle to finish
90
91
*/
91
92
public static startIdleTransaction ( name : string , spanContext ?: SpanContext ) : Span | undefined {
93
+ const activeTransaction = TransactionActivity . _activeTransaction ;
94
+
95
+ if ( activeTransaction ) {
96
+ // We need to finish any active transaction before starting a new
97
+ activeTransaction . finish ( ) ;
98
+ }
99
+
92
100
const _getCurrentHub = TransactionActivity . _getCurrentHub ;
93
101
if ( ! _getCurrentHub ) {
94
102
return undefined ;
@@ -113,6 +121,18 @@ export class TransactionActivity implements Integration {
113
121
return span ;
114
122
}
115
123
124
+ /**
125
+ * Update transaction
126
+ */
127
+ public static updateTransactionName ( name : string ) : void {
128
+ const activeTransaction = TransactionActivity . _activeTransaction ;
129
+ if ( ! activeTransaction ) {
130
+ return ;
131
+ }
132
+ // TODO
133
+ ( activeTransaction as any ) . transaction = name ;
134
+ }
135
+
116
136
/**
117
137
* Starts tracking for a specifc activity
118
138
*/
0 commit comments