Elastic-apm-agent in .net 6 generates a lot of Microsoft-Windows-DotNETRuntime/ExceptionThrown events

We use prometheus-net.DotNetMetrics for system monitoring in ASP .net6 application. And when we started using Elastic Apm agent for .net , the dotnet_exceptions_total metric began to show increased values for System.NotSupportedException exceptions. We tried v1.18.0 and v 1.28.4 agent versions.

dotnet-trace shows, that the reason is in DataFlow (Task Parallel library). Exceptions have message:

This member is not supported on this dataflow block. The block is
intended for a specific purpose that does not utilize this member.

These exceptions are catched in DataFlow, but create noise in the metric and can affect performance.

Source code, where exception is cached:

We have this problem in kubernetes pods, but not in the local machine under the Windows.

Has anyone encountered such a problem?

Thanks for bringing this to our attention @tselofan.

We only use a plain BatchBlock which definitely implements block.Completion.

I had a quick peek at the differences of BatchBlock/SourceCore and the various BlockOption
between .NET and .NET core but could not spot anything obvious.

I created a channel based payload sender in this draft PR: Elastic.Apm.Ingest, new PayloadSender implementation by Mpdreamz · Pull Request #2171 · elastic/apm-agent-dotnet · GitHub

It might be worth finishing that exercise to move us of TPL in the long run.

Thanks for your answer! My research has shown the following:
The reason is in targetBlock which is of type ReceiveTarget.

And the main problem is that the exception occurs when DataflowEtwProvider eventsource is enabled. So it tries to collect tracing data.

I think it is not usual behaviour and I need to disabled it. First of all I think that I need to find which EventSource enabled it.

The reason was in prometheus-net library. In version 7.0.0 it subscribed to all eventsources in app domain.

I upgraded it to version 8 and the problem went away.

Thank you for your participation!

1 Like