Search code examples
traceasp.net-core-2.0azure-application-insights

Reduce trace data in Application Insights with ASP.NET Core 2.0


I have two ASP.NET Core 2.0 Web Apps running similar code, both with Application Insights enabled.

Site "A" targets the netcoreapp2.0 framework. It generates huge amounts of "Trace" data when I look at data volume management, and quickly generates many gigabytes of data per day. I can't afford that, and honestly don't even know what it does for me or how to look at that data. I have set data sampling to 8%, and it still hits my desired 1 GB limit before the day is over.

Site "B" targets the net47 framework (full .NET Framework). This web app generates almost no "Trace" data, and is a much more manageable amount of data. My medium-traffic site stays comfortably under my desired 1 GB limit per day with no data sampling.

Site B handles about twice the traffic of Site A, and also has many more dependency calls -- so this has nothing to do with traffic, it is definitely a configuration difference between the sites.

Question 1: Why does targeting netcoreapp2.0 cause Application Insights to generate extreme amounts of Trace data compared to targeting net47?

Question 2: How do I prevent Application Insights from generating this very costly Trace data when targeting netcoreapp2.0? Or more generally, how do I control Application Insights Trace data collection in an ASP.NET Core 2.0 web app?


Solution

  • After poking around further, I stumbled upon this comment on a github issue:

    https://github.com/Microsoft/ApplicationInsights-aspnetcore/issues/523#issuecomment-341285608

    It seems that Application Insights does indeed register its own ILogger in an asp.net core application, and it turns all logging into AI trace data. That is a massive amount of data if you don't set it to Warning or higher, so beware!

    You can set the logging level or disable it like other loggers in asp.net core.