elastic / apm-agent-dotnet

https://www.elastic.co/guide/en/apm/agent/dotnet/current/index.html
Apache License 2.0
586 stars 208 forks source link

[BUG] APM Agent stops working when using AddFilter #2402

Closed cosmin19 closed 3 months ago

cosmin19 commented 4 months ago

APM Agent version

The version of the Elastic.Apm nuget package used: 1.28.0

Environment

Operating system and version: Windows 11

.NET Framework/Core name and version (e.g. .NET 4.6.2, NET Core 3.1.100) : .NET 8

Application Target Framework(s) (e.g. net462, netcoreapp3.1): net8.0

Describe the bug

When using AddFilter on APM Agent, the Agent stops sending data to the server, stops creating transactions for HTTP requests, stops doing anything.

To Reproduce

  1. Create a new ASP.NET Core Web API project, targeting .NET 8
  2. Go to Program.cs and add
    builder.Services.AddAllElasticApm();
    Agent.AddFilter((ISpan span) =>
    {
    return span;
    });
  3. Go to the created Controller, in the Get method, and add:
    var currentTransaction = Agent.Tracer.CurrentTransaction;
  4. Put a breakpoint after this line and start the project
  5. Send a request the Get endpoint, stop at breakpoint and check currentTransaction variable. Observe that is null
  6. Go back to Program.cs class and remove AddFilter code
  7. Start the project and send a new request to Get method. Observe that currentTransaction now has a value

*Same behaviour for Agent.AddFilter((ITransaction transaction) => { ... });

Expected behavior

The Agent should create transactions and spans and send them to APM server.

Actual behavior

The Agent doesn't create transactions and spans

Mpdreamz commented 3 months ago

Thanks for reporting this one @cosmin19 and appologies for taking a bit to get to work on a fix.

I opened https://github.com/elastic/apm-agent-dotnet/pull/2418 to address this.