Hi @avanlieshout,
based on the stack trace you pasted, the bug seems to be in span compression. In some scenarios you can end up with a high amount of very similar spans (in this case lots of similar database calls) and the agent tries to compress those spans into a single span which essentially aggregates multiple similar spans as a single span. Now - from what I see, this seems to go wrong and causing the issue.
As a workaround, could you please try to turn off span compression and see if that makes the error go away and also if by turning it off, you see those db statements? Docs on it can be found here: Core configuration options | APM .NET Agent Reference [1.x] | Elastic tldr: just set ELASTIC_APM_SPAN_COMPRESSION_ENABLED to false.
Sorry about the trouble!
I also opened a bug about this in the agent repo: NullReferenceException in span compression · Issue #1999 · elastic/apm-agent-dotnet · GitHub