Skip to content

Commit 4df6a5e

Browse files
committed
Use static constructor for test initialization order
1 parent 6be2ae2 commit 4df6a5e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

dotnet/test/TelemetryTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ public class TelemetryTests : IDisposable
1313
private readonly ActivityListener _listener;
1414
private readonly List<Activity> _recordedActivities = new();
1515

16-
public TelemetryTests()
16+
// Static constructor ensures the AppContext switch is set before any code
17+
// accesses CopilotTelemetry.IsEnabled (which uses lazy evaluation)
18+
static TelemetryTests()
1719
{
18-
// Enable telemetry for tests
1920
AppContext.SetSwitch("GitHub.Copilot.EnableOpenTelemetry", true);
21+
}
2022

23+
public TelemetryTests()
24+
{
2125
// Set up an activity listener to capture spans
2226
_listener = new ActivityListener
2327
{
@@ -32,8 +36,6 @@ public TelemetryTests()
3236
public void Dispose()
3337
{
3438
_listener.Dispose();
35-
// Note: We can't easily reset the AppContext switch, but it won't affect other tests
36-
// since IsEnabled is lazily evaluated once
3739
}
3840

3941
[Fact]

0 commit comments

Comments
 (0)