@@ -17,6 +17,8 @@ public class CollectingTraceListener : TraceListener
1717
1818 private readonly ImmutableList < ( Guid RelatedActivityId , Guid CurrentActivityId ) > . Builder transfers = ImmutableList . CreateBuilder < ( Guid RelatedActivityId , Guid CurrentActivityId ) > ( ) ;
1919
20+ private readonly ImmutableList < ( JsonRpc . TraceEvents TraceEventId , Guid ActivityId ) > . Builder eventsWithActivityIds = ImmutableList . CreateBuilder < ( JsonRpc . TraceEvents TraceEventId , Guid ActivityId ) > ( ) ;
21+
2022 public override bool IsThreadSafe => false ;
2123
2224 public IReadOnlyList < string > Messages
@@ -63,6 +65,17 @@ public ImmutableList<JsonRpc.TraceEvents> Ids
6365 }
6466 }
6567
68+ public ImmutableList < ( JsonRpc . TraceEvents TraceEventId , Guid ActivityId ) > EventsWithActivityIds
69+ {
70+ get
71+ {
72+ lock ( this . eventsWithActivityIds )
73+ {
74+ return this . eventsWithActivityIds . ToImmutable ( ) ;
75+ }
76+ }
77+ }
78+
6679 public AsyncAutoResetEvent MessageReceived { get ; } = new AsyncAutoResetEvent ( ) ;
6780
6881 public override void TraceTransfer ( TraceEventCache ? eventCache , string source , int id , string ? message , Guid relatedActivityId )
@@ -87,6 +100,11 @@ public override void TraceEvent(TraceEventCache? eventCache, string source, Trac
87100 this . events . Add ( ( eventType , format is null ? null : string . Format ( CultureInfo . InvariantCulture , format , args ?? Array . Empty < object ? > ( ) ) ) ) ;
88101 }
89102
103+ lock ( this . eventsWithActivityIds )
104+ {
105+ this . eventsWithActivityIds . Add ( ( ( JsonRpc . TraceEvents ) id , Trace . CorrelationManager . ActivityId ) ) ;
106+ }
107+
90108 base . TraceEvent ( eventCache , source , eventType , id , format , args ) ;
91109 }
92110
@@ -102,6 +120,11 @@ public override void TraceEvent(TraceEventCache? eventCache, string source, Trac
102120 this . events . Add ( ( eventType , message ) ) ;
103121 }
104122
123+ lock ( this . eventsWithActivityIds )
124+ {
125+ this . eventsWithActivityIds . Add ( ( ( JsonRpc . TraceEvents ) id , Trace . CorrelationManager . ActivityId ) ) ;
126+ }
127+
105128 base . TraceEvent ( eventCache , source , eventType , id , message ) ;
106129 }
107130
@@ -117,6 +140,11 @@ public override void TraceEvent(TraceEventCache? eventCache, string source, Trac
117140 this . events . Add ( ( eventType , null ) ) ;
118141 }
119142
143+ lock ( this . eventsWithActivityIds )
144+ {
145+ this . eventsWithActivityIds . Add ( ( ( JsonRpc . TraceEvents ) id , Trace . CorrelationManager . ActivityId ) ) ;
146+ }
147+
120148 base . TraceEvent ( eventCache , source , eventType , id ) ;
121149 }
122150
0 commit comments