I am trying to get Tracing using OpenTelemetry to work with HttpClient
in an integration test for an Asp.NET API.
Tracing works for everything else, we get traces from the API controllers and all other instrumented libraries.
Configuration looks like this:
webApplicationBuilder.Services.AddOpenTelemetryTracing(b =>
b.SetResourceBuilder(resourceBuilder)
.AddHttpClientInstrumentation()
.AddAspNetCoreInstrumentation()
.AddProtoActorInstrumentation()
.AddRedisInstrumentation()
.AddOtlpExporter(options =>
{
ConfigureOpenTelemetry(webApplicationBuilder, options);
})
);
But when calling the API using HttpClient. the current TraceId is not propagated.
The integration test uses a MyAppFactory : WebApplicationFactory<Program>
for the test.
And the HttpClient is constructed in the tests using the factory.CreateClient()
of the MyAppFactory.
If I check the Activity.Current.TraceId
inside my integration test. I get one value.
Then directly after, when I call the API using the HttpClient, the API controller reports a different TraceId.
There are also no w3c trace context headers in the Request
inside the controller method.
What am I missing here?