Skip to content

Commit cc25394

Browse files
Move workaround
Move the workaround to a static constructor so it runs early enough to affect the tests.
1 parent c8d4575 commit cc25394

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

test/OpenTelemetry.Instrumentation.W3cTraceContext.Tests/W3CTraceContextTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ public sealed class W3CTraceContextTests : IDisposable
2424
private readonly HttpClient httpClient = new();
2525
private readonly ITestOutputHelper output;
2626

27+
#if NET10_0_OR_GREATER
28+
static W3CTraceContextTests()
29+
{
30+
// See https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/10.0/default-trace-context-propagator
31+
DistributedContextPropagator.Current = DistributedContextPropagator.CreatePreW3CPropagator();
32+
}
33+
#endif
34+
2735
public W3CTraceContextTests(ITestOutputHelper output)
2836
{
2937
this.output = output;
@@ -35,9 +43,6 @@ public W3CTraceContextTests(ITestOutputHelper output)
3543
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters", Justification = "Need to use SkipUnlessEnvVarFoundTheory")]
3644
public void W3CTraceContextTestSuiteAsync(string value)
3745
{
38-
// See https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/10.0/default-trace-context-propagator
39-
DistributedContextPropagator.Current = DistributedContextPropagator.CreatePreW3CPropagator();
40-
4146
// configure SDK
4247
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
4348
.AddAspNetCoreInstrumentation()

0 commit comments

Comments
 (0)