Disable tracking dependencies in Azure Function Application Insights

Andrew Leader
3 min readJan 17, 2020

--

If you’ve set up Application Insights in Azure Functions, but you’re now raking up a $30/month or more bill in your Application Insights, it’s probably because Azure Functions logs every dependency (SQL, http calls, etc) and tons of traces by default.

As seen above, my custom events are barely reaching above 0.2 GB at peak usage, but the dependency logs (SQL calls, HTTP calls), messages, and requests are eating up 1 GB! It’s bad. My current bill for Application Insights is now $32. And I never look at or use the dependencies, requests, etc… I’m only using the custom events and exceptions!

Basically, each time a function was called, it would generate the following telemetry…

That’s a LOT of telemetry when all I’m interested in is the custom events I’m logging!

After implementing the fixes described below, I no longer have all the excessive telemetry, and just my custom events/exceptions… affordable!

How to disable the extra telemetry: Option 1

Assuming you’re using Azure Functions v2 or v3, the first thing you should try is using the host.json file in your function. This worked for my recently deployed v3 function (which I deployed January 2020 and later added this).

Some notes…

  • Using samplingSettings seems to be the key.
  • Their docs claim you should use samplingExcludedTypes, but it’s incorrect, excludedTypes as seen above is correct (see issue #47219)
  • Disabling the live metrics, dependency tracking, etc didn’t seem necessary, the samplingSettings seemed to be the 100% effective solution
  • Maybe if they had enableTracing and enableRequestTracking, you could use those, but until I used samplingSettings, traces (like function called) and HTTP requests were still being logged.

How to disable the extra telemetry: Option 2

Assuming you’re using Azure Functions v2 and the above didn’t work, you can try this… This worked for my v2 functions that were published back in November 2019.

  1. Install the Microsoft.Azure.Functions.Extensions NuGet package
  2. Add the following Startup.cs class to your Azure Function project

In the IsOkayToSend method, you can filter events however you’d like!

Alternative methods of disabling

You seemingly should be able to use the host.json and simply set enableDependencyTracking to false, however, it seems like Azure Functions has a bug where they’re ignoring the host.json. If I create a new Azure Function, settings in host.json (like log level) get respected. But in my existing Function app (which is also v2), they all just seem to get ignored. Oh well, code gives more control anyways.

--

--

Andrew Leader

Program manager on Windows Dev Platform, dev of Power Planner, rock climbing/hiking/skiing enthusiast, mountain rescue