C# Integration Testing with WebApplicationFactory fail due to missing CurrentTransaction

Hi @ all,

did somebody faced issues in dotnet Integration Testing that the Agent.Tracer.CurrentTransaction was null for the second test?

I'm using dotnet 8 and the Elastic.Apm.NetCoreAll Version=1.26.0 nuget package.
Within each of my tests I'm starting Rest API with the default WebApplicationFactory.
The integration test is calling a REST Endpoint which contains a call to Agent.Tracer.CurrentTransaction.

My tests contains multiple tests which always calls the same endpoint.
First test that is executed is successful and I see the trace within a local dockered Kibana/APM dashboard.
Second all further tests fail because the CurrentTransaction is null.
There is also an error within the logs that the "Agent" is already configured.

Running each test separately is successful.

As a work around I start the Test Application with WebApplicationFactory once on AssemblyInitialize, this solved most of the breaking tests, because it is only once started for the test run.

I'm wondering how the "Agent" singelton is implemented, that it is not disposed, when the host (in my case the WebApplicationFactory) shuts down.

Did anybody has a solution to "Dispose" the Agent, so I can start the WebApplicationFactory within each test instead of one global (need to configure different mocks for different cases).

If needed, I can provide a test sln to reproduce the case.

Kind regards,
Peter

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.