@@ -1645,13 +1645,22 @@ export default function TraceManagerDebugger<
1645
1645
useEffect ( ( ) => {
1646
1646
// schedule updates asynchronously so we never call setState mid‐render
1647
1647
const schedule = ( fn : ( ) => void ) => void setTimeout ( fn , 0 )
1648
+ // Create a map to store spans for each trace by ID
1649
+ const traceEntriesMap = new Map <
1650
+ string ,
1651
+ SpanAndAnnotation < RelationSchemasT > [ ]
1652
+ > ( )
1648
1653
1649
1654
// Subscribe to trace-start events
1650
1655
const startSub = traceManager . when ( 'trace-start' ) . subscribe ( ( event ) => {
1651
1656
const trace = event . traceContext as AllPossibleTraces < RelationSchemasT >
1657
+ const traceId = trace . input . id
1658
+
1659
+ // Create a new entry array for this trace (or clear existing)
1660
+ traceEntriesMap . set ( traceId , [ ] )
1652
1661
1653
1662
const traceInfo : TraceInfo < RelationSchemasT > = {
1654
- traceId : trace . input . id ,
1663
+ traceId,
1655
1664
traceName : trace . definition . name ,
1656
1665
variant : trace . input . variant as string ,
1657
1666
state : trace . stateMachine . currentState ,
@@ -1805,23 +1814,29 @@ export default function TraceManagerDebugger<
1805
1814
} ) ,
1806
1815
)
1807
1816
} )
1808
-
1809
- const entries : SpanAndAnnotation < RelationSchemasT > [ ] = [ ]
1810
-
1811
1817
// Subscribe to add-span-to-recording for live info
1812
1818
const addSpanSub = traceManager
1813
1819
. when ( 'add-span-to-recording' )
1814
1820
. subscribe ( ( event ) => {
1821
+ // Add the span to the trace entries map regardless of current UI state
1822
+ const trace = event . traceContext
1823
+ const traceId = trace . input . id
1824
+
1825
+ // Get or initialize entries array for this specific trace
1826
+ if ( ! traceEntriesMap . has ( traceId ) ) {
1827
+ traceEntriesMap . set ( traceId , [ ] )
1828
+ }
1829
+ const entries = traceEntriesMap . get ( traceId ) !
1830
+ entries . push ( event . spanAndAnnotation )
1831
+
1832
+ // Now update the UI if this is the currently displayed trace
1815
1833
schedule (
1816
1834
( ) =>
1817
1835
void setCurrentTrace ( ( prevTrace ) => {
1818
1836
if ( ! prevTrace ) return prevTrace
1819
- if ( event . traceContext . input . id !== prevTrace . traceId ) {
1837
+ if ( traceId !== prevTrace . traceId ) {
1820
1838
return prevTrace
1821
1839
}
1822
- // Calculate live info from traceContext
1823
- const trace = event . traceContext
1824
- entries . push ( event . spanAndAnnotation )
1825
1840
1826
1841
const liveDuration =
1827
1842
entries . length > 0
0 commit comments