Edit

Troubleshoot Azure Monitor Application Insights logs in Azure Functions

Summary

This article helps you troubleshoot missing or incorrect Azure Monitor Application Insights logs in Azure Functions so you can restore reliable monitoring data.

You can closely monitor the function app through the integration between Azure Functions and Application Insights. And you can use Application Insights without any custom configuration.

If the Application Insights logs are missing, or if the data appears to be partial or inaccurate, use the following steps to resolve the issue.

Check configuration of function app

Follow these steps:

  1. Go to your function app in the Azure portal.
  2. Select Diagnose and solve problems to open Azure Functions diagnostics.
  3. In the Search bar, type Function Configuration Checks and open it.
  4. You see a diagnostic report of all function app configuration checks. For Application Insights, check the following:
    • Only one of the following connection settings exists:
      • APPINSIGHTS_INSTRUMENTATIONKEY Application Insights Instrumentation key.
      • APPLICATIONINSIGHTS_CONNECTION_STRING connection string. Use the APPLICATIONINSIGHTS_CONNECTION_STRING for more stable behavior. The ability to use APPINSIGHTS_INSTRUMENTATIONKEY was deprecated in 2025 and will be removed in future versions of Azure Functions.
    • The AzureWebJobsDashboard built-in logging is disabled, as recommended.
    • Sampling is enabled for the Azure Functions telemetry (enabled by default).

Use a supported Azure Functions runtime version

Use version 4 of the function app and runtime version 4.15.2xx or later. From this version onwards, you can track the log flows from Azure Functions to the Application Insights service. By monitoring the log flows, you can check for missing logs.

Custom application logs

By default, Azure Functions host sends custom application logs you write to Application Insights under the Worker category. However, some language stacks allow you to send the logs directly to Application Insights, which gives you full control over how logs you write are emitted. In this case, the logging pipeline changes from worker > Functions host > Application Insights to worker > Application Insights.

The following table summarizes the configuration options available for each stack:

Language stack Where to configure custom logs
.NET (in-process model) host.json
.NET (isolated model) Default (send custom logs to the Azure Functions host): host.json
To send logs directly to Application Insights, see Configure Application Insights in the HostBuilder.
Node.js host.json
Python host.json
Java Default (send custom logs to the Azure Functions host): host.json
To send logs directly to Application Insights, see Configure the Application Insights Java agent.
PowerShell host.json

When you configure custom application logs to be sent directly, the Azure Functions host no longer emits them, and host.json no longer controls their behavior. Similarly, the options exposed by each stack apply only to custom logs, and they don't change the behavior of the other runtime logs described in this article. In this case, to control the behavior of all logs, you might need to make changes in both configurations.

Logs are missing or partial

Application Insights collects log, performance, and error data. Use sampling configuration to reduce the volume of telemetry. Sampling is enabled by default with the settings shown in the following host.json example. Excluded types aren't sampled.

{
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "maxTelemetryItemsPerSecond" : 20,
        "excludedTypes": "Request;Exception"
      }
    }
  }
}

If you notice any partially missing logs, this condition might occur because of sampling. To determine the actual sampling rate, use a Log Analytics query that uses the required time interval shown in the following code snippet. If you observe that the TelemetrySavedPercentage for any sampling type is less than 100, then that type of telemetry is being sampled.

union requests,dependencies,pageViews,browserTimings,exceptions,traces
| where timestamp > todatetime("mm/dd/yyyy hh:mm:ss") and timestamp < todatetime("mm/dd/yyyy hh:mm:ss")
| summarize TelemetrySavedPercentage = 100/avg(itemCount), TelemetryDroppedPercentage = 100-100/avg(itemCount) by bin(timestamp, 1d), itemType
| sort by timestamp asc

For more information, see Data collection, retention, and storage in Application Insights.

Control volume and verbosity of logs

You can increase or suppress the logs that are written. To do this, use a combination of log level and categories as configured in host.json.

The Azure Functions logger includes a category for every log. The category indicates which part of the runtime code or your function code generated the log. For example:

  • The Host.Results and Function.<YOUR_FUNCTION_NAME> categories.
  • A log level is assigned to every log. The value indicates relative importance, such as Warning or Information.

For more information, see the other categories and log levels available.

You can configure how your application writes the logs by following the sample code snippet.

{
  "version": "2.0",
  "logging": {
    "logLevel": {
      "default": "Information", // catch all default, with modifications below for individual categories.
      "Function": "Warning", // Warning level from all Functions (except the ones configured below).
      "Host.Aggregator": "Trace", // Log all traces in the 'customMetrics' table of (and shown on Metrics/Alerts blade in AI) - use either this or Host.Results
      "Host.Results": "Error", // Error and Critical requests are only logged in the 'requests' table of the AI (and shown on Monitor Functions blade in Functions App) - use either this or Host.Aggregator
      "Function.Function1": "Information", //Information level logs from Function 1, logged in 'traces', 'dependencies' and 'customMetrics' tables of AI
      "Function.Function2.User": "Information" //user code logs from Function2, logged in 'traces' table of AI
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "maxTelemetryItemsPerSecond": 1,
        "excludedTypes": "Exception"
      }
    }
  }
}

To configure these values at the app settings level (to avoid redeployment on host.json changes), override specific host.json values by creating an equivalent value as an application setting. For more information, see Override host.json values.

For more examples about how to suppress logs, see functions-log-suppression.

The virtual network integrated function app doesn't generate any logs

If a function app is integrated with a virtual network, you must open port 443 for outgoing traffic in your server firewall to allow the Application Insights SDK or Application Insights Agent to send data to the portal for the following URLs:

  • dc.applicationinsights.azure.com
  • dc.applicationinsights.microsoft.com
  • dc.services.visualstudio.com
  • .in.applicationinsights.azure.com

For more information, see IP addresses used by Azure Monitor.