dotnet / aspire

Tools, templates, and packages to accelerate building observable, production-ready apps
https://learn.microsoft.com/dotnet/aspire
MIT License
3.88k stars 469 forks source link

Azure Function not loaded with specific host settings - logging #6660

Open petrkasnal opened 4 days ago

petrkasnal commented 4 days ago

Is there an existing issue for this?

Describe the bug

When I use the Azure Function in Aspire, a strange behavior occurs when I have this block in host.json. It happened in the previous version 9.0 as I mention here and it happens now in version 9.1.0-preview.1.24561.5.

What happens is that Aspire starts and shows the function loading, which eventually doesn't load and after 120 seconds it throws Failed to start. I used the example repository for Azure Function in Aspire.

I prepared repository - https://github.com/petrkasnal/AspireHostProblem

{
  "version": "2.0",
  "logging": {
    "logLevel": {
      "Default": "Debug", // If enable function isnt load
      "System": "Information",
      "Microsoft": "Information"
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      },
      "enableLiveMetricsFilters": true
    }
  }
}
fail: Aspire.Hosting.Dcp.dcpctrl.ExecutableReconciler[0]
      timeout of 120 seconds exceeded waiting for the IDE to start a run session; you can set the DCP_IDE_REQUEST_TIMEOUT_SECONDS environment variable to override this timeout (in seconds)    {"Executable": {"name":"funcapp-czmfpfza"}, "Reconciliation": 2, "error": "Put \"https://localhost:64604/run_session?api-version=2024-04-23\": context deadline exceeded"}

Image

Expected Behavior

I would expect the logging settings to have no effect on Azure function execution. It's holding us back now because I have to keep overwriting it and that's not very convenient.

Steps To Reproduce

Open repository - https://github.com/petrkasnal/AspireHostProblem Run AzureFunctionsTest.AppHost project

If you edit host.json - comment line "Default": "Debug" and starts work

Exceptions (if any)

No response

.NET Version info

9.0.0-rc.2.24473.5

Anything else?

No response

captainsafia commented 3 days ago

@petrkasnal Thanks for reporting this issue! I took at stab and trying your repro and noticed the following exception at startup:

Microsoft.Azure.WebJobs.Extensions.EventHubs: EventHub account connection string with name 'eventhubs' does not exist in the settings. Make sure that it is a defined App Setting.

I believe this is related to the fact that the eventHubs resource is not configured by default in your sample:

builder.AddAzureFunctionsProject<Projects.AzureFunctionsTest_Functions>("funcapp")
    .WithReference(messaging)
    .WithReference(messaging2)
    .WithReference(messaging3)
    .WithReference(messaging4)
    .WithReference(messaging5)
    .WithReference(messaging6);
    //.WithReference(eventHubs);
    //.WithReference(serviceBus);

Once I re-enable the event hubs resource, things seem to work fine there.

You also mentioned that you're seeing the following DCP exception:

fail: Aspire.Hosting.Dcp.dcpctrl.ExecutableReconciler[0]
      timeout of 120 seconds exceeded waiting for the IDE to start a run session; you can set the DCP_IDE_REQUEST_TIMEOUT_SECONDS environment variable to override this timeout (in seconds)    {"Executable": {"name":"funcapp-czmfpfza"}, "Reconciliation": 2, "error": "Put \"https://localhost:64604/run_session?api-version=2024-04-23\": context deadline exceeded"}

In the past, I've seen this happen when the functions process fails to start. This might be related to the issues you are seeing in https://github.com/dotnet/aspire/issues/6661. Do you repro this when launching from the command line via dotnet run?

petrkasnal commented 3 days ago

I edited the repository. I left really just the function execution to show that it doesn't matter if something is attached to it.

builder.AddAzureFunctionsProject<Projects.AzureFunctionsTest_Functions>("funcapp");

If the Aspire starts, the function doesn't run. If a line is added to host.json as in the specification - "Default": "Debug", it will start immediately. Try and see. Issue #6661 is related to a different problem and is mine.

I just tried using dotnet run and unfortunately I don't use it, so I don't know if I'm doing it right. But it throws me this error in the console.I started thedotnet run project in Aspire. I don't think that has anything to do with it.

2024-11-14T10:26:57
 Unhandled exception: System.ComponentModel.Win32Exception (2): An error occurred trying to start process 'func' with working directory 'bin\Debug\net8.0\'. The system cannot find the file specified.
2024-11-14T10:26:57
    at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
2024-11-14T10:26:57
    at Microsoft.DotNet.Cli.Utils.Command.Execute(Action`1 processStarted)
2024-11-14T10:26:57
    at Microsoft.DotNet.Tools.Run.RunCommand.Execute()
2024-11-14T10:26:57
    at System.CommandLine.Invocation.InvocationPipeline.Invoke(ParseResult parseResult)
2024-11-14T10:26:57
    at System.CommandLine.ParseResult.Invoke()
2024-11-14T10:26:57
    at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, TimeSpan startupTime, ITelemetry telemetryClient)
captainsafia commented 3 days ago

@petrkasnal Can you verify what version of the Azure Functions Core Tools you are using? Running:

> func --version

should get this info.

petrkasnal commented 2 days ago

@captainsafia sure - 4.0.5907

captainsafia commented 2 days ago

@petrkasnal Ah, I see. Your version is about 6 months old. Can you try upgrading to the latest? It should be 4.6610.

petrkasnal commented 23 hours ago

@captainsafia I promoted the version. However, it didn't help, it's still the same.I tried running from visual studio and using dotnet run.