@@ -7,6 +7,7 @@ import type { Hub } from '../hub';
77import type { Span } from './span' ;
88import { SpanRecorder } from './span' ;
99import { Transaction } from './transaction' ;
10+ import { ensureTimestampInSeconds } from './utils' ;
1011
1112export const TRACING_DEFAULTS = {
1213 idleTimeout : 1000 ,
@@ -45,10 +46,12 @@ export class IdleTransactionSpanRecorder extends SpanRecorder {
4546 // We should make sure we do not push and pop activities for
4647 // the transaction that this span recorder belongs to.
4748 if ( span . spanId !== this . transactionSpanId ) {
48- // We patch span.finish() to pop an activity after setting an endTimestamp.
49- span . finish = ( endTimestamp ?: number ) => {
50- span . endTimestamp = typeof endTimestamp === 'number' ? endTimestamp : timestampInSeconds ( ) ;
49+ // We patch span.end() to pop an activity after setting an endTimestamp.
50+ // eslint-disable-next-line @typescript-eslint/unbound-method
51+ const originalEnd = span . end ;
52+ span . end = ( ...rest : unknown [ ] ) => {
5153 this . _popActivity ( span . spanId ) ;
54+ return originalEnd . apply ( span , rest ) ;
5255 } ;
5356
5457 // We should only push new activities if the span does not have an end timestamp.
@@ -129,13 +132,15 @@ export class IdleTransaction extends Transaction {
129132 if ( ! this . _finished ) {
130133 this . setStatus ( 'deadline_exceeded' ) ;
131134 this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 3 ] ;
132- this . finish ( ) ;
135+ this . end ( ) ;
133136 }
134137 } , this . _finalTimeout ) ;
135138 }
136139
137140 /** {@inheritDoc } */
138- public finish ( endTimestamp : number = timestampInSeconds ( ) ) : string | undefined {
141+ public end ( endTimestamp : number = timestampInSeconds ( ) ) : string | undefined {
142+ const endTimestampInS = ensureTimestampInSeconds ( endTimestamp ) ;
143+
139144 this . _finished = true ;
140145 this . activities = { } ;
141146
@@ -145,7 +150,7 @@ export class IdleTransaction extends Transaction {
145150
146151 if ( this . spanRecorder ) {
147152 DEBUG_BUILD &&
148- logger . log ( '[Tracing] finishing IdleTransaction' , new Date ( endTimestamp * 1000 ) . toISOString ( ) , this . op ) ;
153+ logger . log ( '[Tracing] finishing IdleTransaction' , new Date ( endTimestampInS * 1000 ) . toISOString ( ) , this . op ) ;
149154
150155 for ( const callback of this . _beforeFinishCallbacks ) {
151156 callback ( this , endTimestamp ) ;
@@ -159,13 +164,13 @@ export class IdleTransaction extends Transaction {
159164
160165 // We cancel all pending spans with status "cancelled" to indicate the idle transaction was finished early
161166 if ( ! span . endTimestamp ) {
162- span . endTimestamp = endTimestamp ;
167+ span . endTimestamp = endTimestampInS ;
163168 span . setStatus ( 'cancelled' ) ;
164169 DEBUG_BUILD &&
165170 logger . log ( '[Tracing] cancelling span since transaction ended early' , JSON . stringify ( span , undefined , 2 ) ) ;
166171 }
167172
168- const spanStartedBeforeTransactionFinish = span . startTimestamp < endTimestamp ;
173+ const spanStartedBeforeTransactionFinish = span . startTimestamp < endTimestampInS ;
169174
170175 // Add a delta with idle timeout so that we prevent false positives
171176 const timeoutWithMarginOfError = ( this . _finalTimeout + this . _idleTimeout ) / 1000 ;
@@ -196,7 +201,7 @@ export class IdleTransaction extends Transaction {
196201 }
197202 }
198203
199- return super . finish ( endTimestamp ) ;
204+ return super . end ( endTimestamp ) ;
200205 }
201206
202207 /**
@@ -244,7 +249,7 @@ export class IdleTransaction extends Transaction {
244249 * with the last child span.
245250 */
246251 public cancelIdleTimeout (
247- endTimestamp ?: Parameters < IdleTransaction [ 'finish ' ] > [ 0 ] ,
252+ endTimestamp ?: Parameters < IdleTransaction [ 'end ' ] > [ 0 ] ,
248253 {
249254 restartOnChildSpanChange,
250255 } : {
@@ -260,7 +265,7 @@ export class IdleTransaction extends Transaction {
260265
261266 if ( Object . keys ( this . activities ) . length === 0 && this . _idleTimeoutCanceledPermanently ) {
262267 this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 5 ] ;
263- this . finish ( endTimestamp ) ;
268+ this . end ( endTimestamp ) ;
264269 }
265270 }
266271 }
@@ -281,12 +286,12 @@ export class IdleTransaction extends Transaction {
281286 /**
282287 * Restarts idle timeout, if there is no running idle timeout it will start one.
283288 */
284- private _restartIdleTimeout ( endTimestamp ?: Parameters < IdleTransaction [ 'finish ' ] > [ 0 ] ) : void {
289+ private _restartIdleTimeout ( endTimestamp ?: Parameters < IdleTransaction [ 'end ' ] > [ 0 ] ) : void {
285290 this . cancelIdleTimeout ( ) ;
286291 this . _idleTimeoutID = setTimeout ( ( ) => {
287292 if ( ! this . _finished && Object . keys ( this . activities ) . length === 0 ) {
288293 this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 1 ] ;
289- this . finish ( endTimestamp ) ;
294+ this . end ( endTimestamp ) ;
290295 }
291296 } , this . _idleTimeout ) ;
292297 }
@@ -318,7 +323,7 @@ export class IdleTransaction extends Transaction {
318323 const endTimestamp = timestampInSeconds ( ) ;
319324 if ( this . _idleTimeoutCanceledPermanently ) {
320325 this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 5 ] ;
321- this . finish ( endTimestamp ) ;
326+ this . end ( endTimestamp ) ;
322327 } else {
323328 // We need to add the timeout here to have the real endtimestamp of the transaction
324329 // Remember timestampInSeconds is in seconds, timeout is in ms
@@ -351,7 +356,7 @@ export class IdleTransaction extends Transaction {
351356 DEBUG_BUILD && logger . log ( '[Tracing] Transaction finished because of no change for 3 heart beats' ) ;
352357 this . setStatus ( 'deadline_exceeded' ) ;
353358 this . _finishReason = IDLE_TRANSACTION_FINISH_REASONS [ 0 ] ;
354- this . finish ( ) ;
359+ this . end ( ) ;
355360 } else {
356361 this . _pingHeartbeat ( ) ;
357362 }
0 commit comments