@@ -265,14 +265,14 @@ export class TraceStateMachine<
265
265
* if we have long tasks before FMP, we want to use them as a potential grouping post FMP.
266
266
*/
267
267
debouncingSpanBuffer : SpanAndAnnotation < RelationSchemasT > [ ] = [ ]
268
- #provisionalBuffer : SpanAndAnnotation < RelationSchemasT > [ ] = [ ]
268
+ #draftBuffer : SpanAndAnnotation < RelationSchemasT > [ ] = [ ]
269
269
270
270
// eslint-disable-next-line consistent-return
271
- #processProvisionalBuffer ( ) : Transition < RelationSchemasT > | void {
271
+ #processDraftBuffer ( ) : Transition < RelationSchemasT > | void {
272
272
// process items in the buffer (stick the relatedTo in the entries) (if its empty, well we can skip this!)
273
273
let span : SpanAndAnnotation < RelationSchemasT > | undefined
274
274
// eslint-disable-next-line no-cond-assign
275
- while ( ( span = this . #provisionalBuffer . shift ( ) ) ) {
275
+ while ( ( span = this . #draftBuffer . shift ( ) ) ) {
276
276
const transition = this . emit ( 'onProcessSpan' , span )
277
277
if ( transition ) return transition
278
278
}
@@ -316,6 +316,7 @@ export class TraceStateMachine<
316
316
for ( const doesSpanMatch of this . #context. definition
317
317
. interruptOnSpans ) {
318
318
if ( doesSpanMatch ( spanAndAnnotation , this . #context) ) {
319
+ // TODO: do we want to record this span? Nothing else is being recorded at this point and is instead going into the buffer
319
320
return {
320
321
transitionToState : 'complete' ,
321
322
interruptionReason : doesSpanMatch . requiredSpan
@@ -329,7 +330,7 @@ export class TraceStateMachine<
329
330
}
330
331
331
332
// else, add into span buffer
332
- this . #provisionalBuffer . push ( spanAndAnnotation )
333
+ this . #draftBuffer . push ( spanAndAnnotation )
333
334
return undefined
334
335
} ,
335
336
@@ -352,7 +353,7 @@ export class TraceStateMachine<
352
353
353
354
active : {
354
355
onEnterState : ( _transition : OnEnterActive ) => {
355
- const nextTransition = this . #processProvisionalBuffer ( )
356
+ const nextTransition = this . #processDraftBuffer ( )
356
357
if ( nextTransition ) return nextTransition
357
358
358
359
return undefined
@@ -381,6 +382,8 @@ export class TraceStateMachine<
381
382
for ( const doesSpanMatch of this . #context. definition
382
383
. interruptOnSpans ) {
383
384
if ( doesSpanMatch ( spanAndAnnotation , this . #context) ) {
385
+ // still record the span that interrupted the trace
386
+ this . sideEffectFns . addSpanToRecording ( spanAndAnnotation )
384
387
return {
385
388
transitionToState : 'interrupted' ,
386
389
interruptionReason : doesSpanMatch . requiredSpan
@@ -509,11 +512,13 @@ export class TraceStateMachine<
509
512
}
510
513
}
511
514
515
+ // The debouncing buffer will be used to correctly group the spans into clusters when calculating the cpu idle in the waiting-for-interactive state
516
+ // We record the spans here as well, so that they are included even if we never make it out of the debouncing state
512
517
this . debouncingSpanBuffer . push ( spanAndAnnotation )
518
+ this . sideEffectFns . addSpanToRecording ( spanAndAnnotation )
513
519
514
520
if ( spanEndTimeEpoch > this . #debounceDeadline) {
515
521
// done debouncing
516
- this . sideEffectFns . addSpanToRecording ( spanAndAnnotation )
517
522
return { transitionToState : 'waiting-for-interactive' }
518
523
}
519
524
@@ -544,8 +549,6 @@ export class TraceStateMachine<
544
549
}
545
550
}
546
551
547
- this . sideEffectFns . addSpanToRecording ( spanAndAnnotation )
548
-
549
552
// does span satisfy any of the "debouncedOn" and if so, restart our debounce timer
550
553
if ( this . #context. definition . debounceOnSpans ) {
551
554
for ( const doesSpanMatch of this . #context. definition
@@ -807,14 +810,14 @@ export class TraceStateMachine<
807
810
// terminal states:
808
811
interrupted : {
809
812
onEnterState : ( transition : OnEnterInterrupted ) => {
810
- // depending on the reason, if we're coming from draft, we want to flush the provisional buffer:
813
+ // depending on the reason, if we're coming from draft, we want to flush the buffer:
811
814
if (
812
815
transition . transitionFromState === 'draft' &&
813
816
! isInvalidTraceInterruptionReason ( transition . interruptionReason )
814
817
) {
815
818
let span : SpanAndAnnotation < RelationSchemasT > | undefined
816
819
// eslint-disable-next-line no-cond-assign
817
- while ( ( span = this . #provisionalBuffer . shift ( ) ) ) {
820
+ while ( ( span = this . #draftBuffer . shift ( ) ) ) {
818
821
this . sideEffectFns . addSpanToRecording ( span )
819
822
}
820
823
}
0 commit comments