Search code examples
azure-functionsazure-application-insights.net-8.0azure-functions-isolated

Some Azure function logs are missing from Application Insights


We are experiencing some logging issues after upgrading one of our Azure Functions (v4) to .NET 8 and isolated worker; Some (not all) error level logs are only appearing in the function log stream for "App Insights Logs", and not in Application Insights trace logs.

Note that sampling is (or should be) disabled, ref. Azure function app not always send log to application insight.

When running the app locally and connecting it to Application Insights, all the logs appear when querying for traces.

Program.cs:

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services =>
    {
        // Other service configurations not included
        services.ConfigureFunctionsApplicationInsights();
        services.AddApplicationInsightsTelemetryWorkerService();
    })
    .ConfigureLogging(logging =>
    {
    logging.Services.Configure<LoggerFilterOptions>(options =>
    {
            var defaultRule = options.Rules.FirstOrDefault(rule =>
                  rule.ProviderName == "Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider");
            if (defaultRule is not null)
            {
                options.Rules.Remove(defaultRule);
            }
        });
    })
    .Build();

host.Run();

host.json:

{
  "version": "2.0",
  "logging": {
    "logLevel": {
      "default": "Warning",
      "Function": "Information",
      "<project-namespace>": "Information"
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": false
      }
    }
  }
}

Edit - added screenshots of log stream and application insights logs. Log stream with error

Application insights logs without error


Solution

  • It seems that Application Insights is now (after upgrading) catching the error as an Exception instead of a trace - probably since one of the custom dimensions contain an Exception.

    Thanks to @Pavan for getting me to check the transaction search!