Skip to content

Commit d30303b

Browse files
Fix W3C tests
React to breaking change in .NET 10.
1 parent 43a12ac commit d30303b

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ public void W3CTraceContextTestSuiteAsync(string value)
3737
{
3838
// configure SDK
3939
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
40-
.AddAspNetCoreInstrumentation()
41-
.Build();
40+
.AddAspNetCoreInstrumentation()
41+
.Build();
42+
43+
#if NET10_0_OR_GREATER
44+
// See https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/10.0/default-trace-context-propagator
45+
System.Diagnostics.DistributedContextPropagator.Current = System.Diagnostics.DistributedContextPropagator.CreatePreW3CPropagator();
46+
#endif
4247

4348
var builder = WebApplication.CreateBuilder();
4449
using var app = builder.Build();
@@ -68,12 +73,23 @@ public void W3CTraceContextTestSuiteAsync(string value)
6873

6974
app.RunAsync("http://localhost:5000/");
7075

71-
string result = RunCommand("python", "trace-context/test/test.py http://localhost:5000/");
76+
(var stdout, var stderr) = RunCommand("python", "-W ignore trace-context/test/test.py http://localhost:5000/");
7277

7378
// Assert
74-
string lastLine = ParseLastLine(result);
79+
// TODO: after W3C Trace Context test suite passes, it might go in standard output
80+
string lastLine = ParseLastLine(stderr);
81+
82+
this.output.WriteLine("[stderr]" + stderr);
83+
this.output.WriteLine("[stdout]" + stdout);
84+
this.output.WriteLine("[result]" + lastLine);
85+
86+
Console.WriteLine("[stderr]" + stderr);
87+
Console.WriteLine("[stdout]" + stdout);
88+
Console.WriteLine("[result]" + lastLine);
7589

76-
this.output.WriteLine("result:" + result);
90+
Thread.Sleep(5_000);
91+
92+
this.output.WriteLine("DONE");
7793

7894
// Assert on the last line
7995
Assert.StartsWith("OK", lastLine, StringComparison.Ordinal);
@@ -82,9 +98,10 @@ public void W3CTraceContextTestSuiteAsync(string value)
8298
public void Dispose()
8399
{
84100
this.httpClient.Dispose();
101+
Thread.Sleep(5_000);
85102
}
86103

87-
private static string RunCommand(string command, string args)
104+
private static (string StdOut, string StdErr) RunCommand(string command, string args)
88105
{
89106
using var proc = new Process
90107
{
@@ -101,10 +118,12 @@ private static string RunCommand(string command, string args)
101118
};
102119
proc.Start();
103120

104-
// TODO: after W3C Trace Context test suite passes, it might go in standard output
105-
var results = proc.StandardError.ReadToEnd();
121+
var stdout = proc.StandardOutput.ReadToEnd();
122+
var stderr = proc.StandardError.ReadToEnd();
123+
106124
proc.WaitForExit();
107-
return results;
125+
126+
return (stdout, stderr);
108127
}
109128

110129
private static string ParseLastLine(string output)

0 commit comments

Comments
 (0)