File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
playground/Stress/Stress.ApiService Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -225,4 +225,16 @@ async IAsyncEnumerable<string> WriteOutput()
225225 return "Log with formatted data" ;
226226} ) ;
227227
228+ app . MapGet ( "/duplicate-spanid" , async ( ) =>
229+ {
230+ var traceCreator = new TraceCreator ( ) ;
231+ var span1 = traceCreator . CreateActivity ( "Test 1" , "0485b1947fe788bb" ) ;
232+ await Task . Delay ( 1000 ) ;
233+ span1 ? . Stop ( ) ;
234+ var span2 = traceCreator . CreateActivity ( "Test 2" , "0485b1947fe788bb" ) ;
235+ await Task . Delay ( 1000 ) ;
236+ span2 ? . Stop ( ) ;
237+ return $ "Created duplicate span IDs.";
238+ } ) ;
239+
228240app . Run ( ) ;
Original file line number Diff line number Diff line change 22// The .NET Foundation licenses this file to you under the MIT license.
33
44using System . Diagnostics ;
5+ using System . Reflection ;
56
67namespace Stress . ApiService ;
78
@@ -13,6 +14,22 @@ public class TraceCreator
1314
1415 private readonly List < Activity > _allActivities = new List < Activity > ( ) ;
1516
17+ public Activity ? CreateActivity ( string name , string ? spandId )
18+ {
19+ var activity = s_activitySource . StartActivity ( name , ActivityKind . Client ) ;
20+ if ( activity != null )
21+ {
22+ if ( spandId != null )
23+ {
24+ // Gross but it's the only way.
25+ typeof ( Activity ) . GetField ( "_spanId" , BindingFlags . Instance | BindingFlags . NonPublic ) ! . SetValue ( activity , spandId ) ;
26+ typeof ( Activity ) . GetField ( "_traceId" , BindingFlags . Instance | BindingFlags . NonPublic ) ! . SetValue ( activity , activity . TraceId . ToString ( ) ) ;
27+ }
28+ }
29+
30+ return activity ;
31+ }
32+
1633 public async Task CreateTraceAsync ( int count , bool createChildren )
1734 {
1835 var activityStack = new Stack < Activity > ( ) ;
You can’t perform that action at this time.
0 commit comments