1
- import {
2
- DEFAULT_DEBOUNCE_DURATION ,
3
- DEFAULT_INTERACTIVE_TIMEOUT_DURATION ,
4
- } from './constants'
5
1
import type {
6
2
AllPossibleRequiredSpanSeenEvents ,
7
3
AllPossibleStateTransitionEvents ,
8
4
AllPossibleTraceStartEvents ,
9
5
} from './debugTypes'
10
- import { isSuppressedError } from './debugUtils'
6
+ import {
7
+ extractTimingOffsets ,
8
+ formatMatcher ,
9
+ getComputedResults ,
10
+ getConfigSummary ,
11
+ isSuppressedError ,
12
+ } from './debugUtils'
11
13
import type { SpanMatcherFn } from './matchSpan'
12
- import { createTraceRecording } from './recordingComputeUtils'
13
14
import type { FinalTransition , OnEnterStatePayload } from './Trace'
14
15
import { isTerminalState } from './Trace'
15
16
import type { TraceManager } from './TraceManager'
@@ -34,73 +35,6 @@ interface ConsoleLike {
34
35
// Add other console methods if needed (warn, error, etc.)
35
36
}
36
37
37
- /**
38
- * Formats a SpanMatcherFn into a more readable string representation.
39
- * This is a basic implementation and can be significantly improved
40
- * based on the actual structure of `matcher.fromDefinition`.
41
- *
42
- * @param matcher The matcher function to format.
43
- * @param index Optional index for generic naming.
44
- * @returns A string representation of the matcher.
45
- */
46
- export function formatMatcher <
47
- SelectedRelationNameT extends keyof RelationSchemasT ,
48
- RelationSchemasT extends RelationSchemasBase < RelationSchemasT > ,
49
- VariantsT extends string ,
50
- > (
51
- matcher : SpanMatcherFn < SelectedRelationNameT , RelationSchemasT , VariantsT > ,
52
- index ?: number ,
53
- ) : string {
54
- // Check if the matcher has attached definition info
55
- if ( matcher . fromDefinition ) {
56
- // Attempt to create a more descriptive name from the definition
57
- // This part needs customization based on how 'fromDefinition' is structured.
58
- // Example: Check for specific properties like 'name', 'type', 'label' etc.
59
- const def = matcher . fromDefinition
60
- const parts : string [ ] = [ ]
61
-
62
- if ( typeof def === 'object' && def !== null ) {
63
- // Example: Prioritize 'label' if it exists
64
- if ( 'label' in def && typeof def . label === 'string' ) {
65
- return `Label: "${ def . label } "`
66
- }
67
- // Example: Use 'name' if it exists
68
- if ( 'name' in def ) {
69
- if ( typeof def . name === 'string' ) {
70
- parts . push ( `Name: "${ def . name } "` )
71
- } else if ( def . name instanceof RegExp ) {
72
- parts . push ( `Name: /${ def . name . source } /${ def . name . flags } ` )
73
- }
74
- }
75
- // Example: Add type if present
76
- if ( 'type' in def && typeof def . type === 'string' ) {
77
- parts . push ( `Type: ${ def . type } ` )
78
- }
79
- // Add other relevant properties from your definition structure
80
- }
81
-
82
- if ( parts . length > 0 ) {
83
- return parts . join ( ', ' )
84
- }
85
-
86
- // Fallback: Stringify the definition (can be verbose)
87
- try {
88
- const defString = JSON . stringify ( def )
89
- // Limit length to avoid overly long strings
90
- return defString . length > 100
91
- ? // eslint-disable-next-line no-magic-numbers
92
- `${ defString . slice ( 0 , 97 ) } ...`
93
- : defString
94
- } catch {
95
- // Fallback if stringify fails
96
- return `Matcher Definition #${ index ?? '?' } `
97
- }
98
- }
99
-
100
- // Fallback if no definition info is available
101
- return `Matcher #${ index ?? '?' } `
102
- }
103
-
104
38
/**
105
39
* Options for configuring the ConsoleTraceLogger
106
40
*/
@@ -156,45 +90,6 @@ interface TraceInfo<RelationSchemasT> {
156
90
requiredSpans : { name : string ; isMatched : boolean ; matcher : Function } [ ]
157
91
}
158
92
159
- /**
160
- * Extract timing offsets from a transition object
161
- */
162
- const extractTimingOffsets = < RelationSchemasT > (
163
- transition : OnEnterStatePayload < RelationSchemasT > ,
164
- ) => {
165
- // ... (implementation unchanged) ...
166
- let lastRequiredSpanOffset : number | undefined
167
- let completeSpanOffset : number | undefined
168
- let cpuIdleSpanOffset : number | undefined
169
-
170
- if (
171
- 'lastRequiredSpanAndAnnotation' in transition &&
172
- transition . lastRequiredSpanAndAnnotation
173
- ) {
174
- lastRequiredSpanOffset =
175
- transition . lastRequiredSpanAndAnnotation . annotation
176
- . operationRelativeEndTime
177
- }
178
-
179
- if (
180
- 'completeSpanAndAnnotation' in transition &&
181
- transition . completeSpanAndAnnotation
182
- ) {
183
- completeSpanOffset =
184
- transition . completeSpanAndAnnotation . annotation . operationRelativeEndTime
185
- }
186
-
187
- if (
188
- 'cpuIdleSpanAndAnnotation' in transition &&
189
- transition . cpuIdleSpanAndAnnotation
190
- ) {
191
- cpuIdleSpanOffset =
192
- transition . cpuIdleSpanAndAnnotation . annotation . operationRelativeEndTime
193
- }
194
-
195
- return { lastRequiredSpanOffset, completeSpanOffset, cpuIdleSpanOffset }
196
- }
197
-
198
93
/**
199
94
* Format timestamp to readable time
200
95
*/
@@ -474,16 +369,7 @@ export function createConsoleTraceLogger<
474
369
}
475
370
log ( ` Required spans: ${ requiredSpans . length } ` )
476
371
// Log config summary
477
- const variantConfig = trace . definition . variants [ trace . input . variant ]
478
- const timeout = variantConfig ?. timeout
479
- const debounce =
480
- trace . definition . debounceWindow ?? DEFAULT_DEBOUNCE_DURATION
481
- const interactive =
482
- typeof trace . definition . captureInteractive === 'object'
483
- ? trace . definition . captureInteractive . timeout
484
- : trace . definition . captureInteractive
485
- ? DEFAULT_INTERACTIVE_TIMEOUT_DURATION
486
- : undefined
372
+ const { timeout, debounce, interactive } = getConfigSummary ( trace )
487
373
log (
488
374
` Config: Timeout=${ timeout } ms, Debounce=${ debounce } ms${
489
375
interactive ? `, Interactive=${ interactive } ms` : ''
@@ -550,12 +436,13 @@ export function createConsoleTraceLogger<
550
436
logTimingInfo ( transition )
551
437
// Log computed values and spans
552
438
try {
553
- const rec = createTraceRecording ( trace , transition )
554
- const computedVals = rec . computedValues
555
- const { computedSpans } = rec
556
- if ( computedVals && Object . keys ( computedVals ) . length > 0 ) {
439
+ const { computedValues, computedSpans } = getComputedResults (
440
+ trace ,
441
+ transition ,
442
+ )
443
+ if ( computedValues && Object . keys ( computedValues ) . length > 0 ) {
557
444
log (
558
- ` Computed Values: ${ Object . entries ( computedVals )
445
+ ` Computed Values: ${ Object . entries ( computedValues )
559
446
. map ( ( [ k , v ] ) => `${ k } =${ v } ` )
560
447
. join ( ', ' ) } `,
561
448
)
@@ -587,15 +474,13 @@ export function createConsoleTraceLogger<
587
474
logTimingInfo ( transition )
588
475
// Log computed values and spans
589
476
try {
590
- const rec = createTraceRecording (
477
+ const { computedValues , computedSpans } = getComputedResults (
591
478
trace ,
592
479
transition as FinalTransition < RelationSchemasT > ,
593
480
)
594
- const computedVals = rec . computedValues
595
- const { computedSpans } = rec
596
- if ( computedVals && Object . keys ( computedVals ) . length > 0 ) {
481
+ if ( computedValues && Object . keys ( computedValues ) . length > 0 ) {
597
482
log (
598
- ` Computed Values: ${ Object . entries ( computedVals )
483
+ ` Computed Values: ${ Object . entries ( computedValues )
599
484
. map ( ( [ k , v ] ) => `${ k } =${ v } ` )
600
485
. join ( ', ' ) } `,
601
486
)
0 commit comments