Application Insights for Server less Computing | CloudFronts

Application Insights for Server less Computing

Posted On January 4, 2021 by Yogesh Gore Posted in 

Application insights is cloud service is use to monitor Azure Cloud Service App for availability, performance, failures, and usage by combining data from Application Insights SDKs with Azure Diagnostics data from your cloud services.

Application Insights collects log, performance, and error data, and automatically detects performance anomalies. Application Insights includes powerful analytics tools to help you diagnose issues and to understand how your functions are used. When you have the visibility into your application data, you can continuously improve performance and usability. You can even use Application Insights during local function app project development.

How to create Application insights resource workspace?

  • Search for Application Insights in Azure and click on create. Select the required configurations as shown below and click on next.
  • Add the Tags.
  • Review and Click on Create.

Integration of Application Insights with Azure Function

Application insights can quickly be hooked up an Azure Function App. You create an instance of Application Insights, obtain the instrumentation key and set in the application settings.

Note that when deploying a function to a Function App the Application Insights is enabled and you do not have to do anything.

Once this setting has been saved the Function App automatically will send information to Application Insights, without any code changes. If you open Application Insights instance and click “Live Metrics” you will see a near-live view of what is coming from your Function App.

In the file host.json, for the filed “Function”, set its value to Trace. Then LogTrace() can be logged into application insights.

Sample host.json for Azure function v2, which can log trace messages to Application Insights:


  “version”: “2.0”,

  “logging”: {

    “fileLoggingMode”: “always”,

    “logLevel”: {

      “default”: “Information”,

      “Host.Results”: “Error”,

      “Function”: “Trace”,

      “Host.Aggregator”: “Trace”




And if you publish your function app with visual studio, you can modify your host.json file as per the above before publishing.

And if you want to change the log level in azure portal, please follow this:

In Azure portal, navigate to your function app -> in the function app settings, make sure enable the Read/Write, then change log level to trace in the host.json.

Log levels and categories

When you write traces from your application code, you should assign a log level to the traces. Log levels provide a way for you to limit the amount of data that is collected from your traces.


Trace0Logs that contain the most detailed messages. These messages may contain sensitive application data. These messages are disabled by default and should never be enabled in a production environment.
Debug1Logs that are used for interactive investigation during development. These logs should primarily contain information useful for debugging and have no long-term value.
Information2Logs that track the general flow of the application. These logs should have long-term value.
Warning3Logs that highlight an abnormal or unexpected event in the application flow, but don’t otherwise cause the application execution to stop.
Error4Logs that highlight when the current flow of execution is stopped because of a failure. These errors should indicate a failure in the current activity, not an application-wide failure.
Critical5Logs that describe an unrecoverable application or system crash, or a catastrophic failure that requires immediate attention.
None6Disables logging for the specified category.

A log level is assigned to every log. The value is an integer that indicates relative importance:

Logging in Azure function

In your function code, you can write output to logs that appear as traces in Application Insights. The recommended way to write to the logs is to include a parameter of type ILogger and we can trace it using log object of ILogger class for older version of azure function we can use TraceWriter.

Following code writes log to application insights

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, ILogger logger)


    logger.LogInformation(“Request for item with key={itemKey}.”, id);


Share Story :