How to: Optimizing logging costs of Azure Functions
Our partner's product relies on a microservice ecosystem deployed to Azure. It uses plenty of different Azure components and most importantly Azure Functions. We quickly found out that Azure automatically deploys logging components that provide important surveillance and debugging tools. However they can sometimes be unnecessary and easily costly in a small environment. Here is a small walkthrough on how to disable App Insights from new Azure Functions.
How to disable App Insights for 2.x Azure Functions
2.x runtime for Azure Functions started logging to Application Insights recently and the logging will be set up automatically when a function is created. App Insights is a powerful tool that Azure has put a lot of emphasis into. However, it may become costly for environments where extensive logging is not needed.
To remove the connection, it's necessary to delete
APPLICATIONINSIGHTS_CONNECTION_STRING from the function configuration (see image 1). Deleting these application settings will remove the function's ability to connect with Application Insights. Thus, Application Insights will be disabled, and data will no longer be logged for this function.
How to log information when Application Insights is disabled
If code in the Azure Function logs information (i.e.
log.LogInformation() in .NET), this logged information will be stored in the Kudu function logs accessible at
https://<functionAppName>.scm.azurewebsites.net/DebugConsole and more specifically
D:\home\LogFiles\Application\Functions\function\<functionName> in the folder structure.
How to re-enable Application Insights
To re-enable Application Insights, there is an option to "Turn on Application Insights" on the "Application Insights" tab (see image 2). A link between the function and a selected Application Insights resource needs to be applied. This will recreate the deleted application settings for your function.