@@ -15,6 +15,9 @@ public class DiagnosticTests
1515 [ Fact ]
1616 public async Task Session_TracksActivities ( )
1717 {
18+ // Ensure no ambient activity from previous tests
19+ Activity . Current = null ;
20+
1821 var activities = new List < Activity > ( ) ;
1922 var clientToServerLog = new List < string > ( ) ;
2023
@@ -32,6 +35,9 @@ await RunConnected(async (client, server) =>
3235 var tool = tools . First ( t => t . Name == "DoubleValue" ) ;
3336 await tool . InvokeAsync ( new ( ) { [ "amount" ] = 42 } , TestContext . Current . CancellationToken ) ;
3437 } , clientToServerLog ) ;
38+
39+ // Ensure all activities are flushed before disposal
40+ tracerProvider . ForceFlush ( ) ;
3541 }
3642
3743 Assert . NotEmpty ( activities ) ;
@@ -77,6 +83,9 @@ await RunConnected(async (client, server) =>
7783 [ Fact ]
7884 public async Task Session_FailedToolCall ( )
7985 {
86+ // Ensure no ambient activity from previous tests
87+ Activity . Current = null ;
88+
8089 var activities = new List < Activity > ( ) ;
8190
8291 using ( var tracerProvider = OpenTelemetry . Sdk . CreateTracerProviderBuilder ( )
@@ -89,6 +98,9 @@ await RunConnected(async (client, server) =>
8998 await client . CallToolAsync ( "Throw" , cancellationToken : TestContext . Current . CancellationToken ) ;
9099 await Assert . ThrowsAsync < McpProtocolException > ( async ( ) => await client . CallToolAsync ( "does-not-exist" , cancellationToken : TestContext . Current . CancellationToken ) ) ;
91100 } , [ ] ) ;
101+
102+ // Ensure all activities are flushed before disposal
103+ tracerProvider . ForceFlush ( ) ;
92104 }
93105
94106 Assert . NotEmpty ( activities ) ;
0 commit comments