Azure / azure-functions-dotnet-worker

Azure Functions out-of-process .NET language worker
MIT License
403 stars 166 forks source link

Function never completes when removing applicationInsights in host.json #2250

Open mumurug-MSFT opened 5 months ago

mumurug-MSFT commented 5 months ago

Description

I have created an Azure Function in Visual Studio with default template and made changes for ASP.NET core integration as described in doc: https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide?tabs=windows#aspnet-core-integration.

If I comment out applicationInsights in host.JSON, then Azure functions stuck in executing and never completes. applicationInsights is not mandatory as per my understanding from https://learn.microsoft.com/en-us/azure/azure-functions/functions-host-json#applicationinsights and appears to be a bug.

Output: image

Core Tools Version: 4.0.5504 Function Runtime Version: 4.28.3.21820

Steps to reproduce

Create a new Azure Function in Visual Studio (default template) and make changes as below:

host.json

{
  "version": "2.0",

  "logging": {
    //"applicationInsights": {
    //  "samplingSettings": {
    //    "isEnabled": true,
    //    "excludedTypes": "Request"
    //  },
    //  "enableLiveMetricsFilters": true
    //}
  }
}

Program.cs

using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services =>
    {
        //services.AddApplicationInsightsTelemetryWorkerService();
        //services.ConfigureFunctionsApplicationInsights();
    })
    .Build();

host.Run();

Function1.cs

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace FunctionApp1
{
    public class Function1
    {
        //private readonly ILogger<Function1> _logger;

        //public Function1(ILogger<Function1> logger)
        //{
        //    _logger = logger;
        //}

        [Function("Function1")]
        public IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req)
        {
            //_logger.LogInformation("C# HTTP trigger function processed a request.");
            return new OkObjectResult("Welcome to Azure Functions!");
        }
    }
}

Output: image

The issue was submitted based on discussion: https://learn.microsoft.com/en-us/answers/questions/1517505/azure-function-requires-applicationinsight-logging

brokenfunction.zip

mattchenderson commented 1 week ago

@mumurug-MSFT Does this reproduce if you remove the section instead of adding comments in JSON? Comments in JSON are generally not safe.

aishwaryabh commented 1 day ago

This issue does not repro if you remove the commented out section in the JSON