Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WebToolsE2E][Aspire] Running with new Azure Function + Aspire, the error appears: "Application Insights SDK has not been added. Please add and configure the Application Insights SDK..." #6452

Closed
v-bennettyue opened this issue Oct 23, 2024 · 12 comments
Assignees
Labels
area-integrations Issues pertaining to Aspire Integrations packages azure-functions Issues related to the Azure Functions integration external Issues that represent work that's external to this repo.
Milestone

Comments

@v-bennettyue
Copy link

v-bennettyue commented Oct 23, 2024

INSTALL STEPS

  1. Clean machine: Win11 x64 23h2 ENU
  2. Install Dev17.12 GA
  3. Install Aspire 9.0 GA
  4. Apply feed

REPRO STEPS

  1. New > Azure Function > .NET 9.0 Isolated (Preview) > Select "Http trigger" as Function, click "Enlist in Aspire orchestration" > Create
  2. Build and run

Note:

  1. This is the new Azure Functions, the contents of Program.cs file are as follows
    Image
  2. The AzureFunctionsTools version as follow:
    Image
  3. When I run the Azure Function alone, it succeeds

ACTUAL:
An error will occur:
Microsoft.Extensions.Options.OptionsValidationException: 'Application Insights SDK has not been added. Please add and configure the Application Insights SDK. See https://learn.microsoft.com/en-us/azure/azure-monitor/app/worker-service for more information.'
Image

EXPECTED
Run successfully

@captainsafia
Copy link
Member

@mattchenderson Our CTI testing team ran into this issue as well. Any chance there's an issue on the Functions repo we can cross-link to?

@v-bennettyue This is a known issue for now but let's use this to track eventually reverifying this scenario.

@captainsafia captainsafia added area-integrations Issues pertaining to Aspire Integrations packages azure-functions Issues related to the Azure Functions integration labels Oct 23, 2024
@captainsafia
Copy link
Member

Update: we think microsoft/ApplicationInsights-dotnet#2908 will resolve this. I'm trying to validate this now with a local build of those changes against the template.

@joperezr joperezr added the untriaged New issue has not been triaged label Oct 23, 2024
@balachir balachir added this to the 9.0 milestone Oct 24, 2024
@joperezr joperezr added external Issues that represent work that's external to this repo. and removed untriaged New issue has not been triaged labels Oct 24, 2024
@joperezr
Copy link
Member

Chatted about this during triage. For this one we will need to get a new version of App Insights SDK to nuget and then for the Functions templates to use that version.

@captainsafia
Copy link
Member

Unfortunately, it looks like it'll take a while for the root cause that was referenced above to be resolved.

For the time being, you can work around this problem by commenting out the following line in the Extensions.cs of the service defaults project.

builder.Services.ConfigureHttpClientDefaults(http =>
{
    // Turn on resilience by default
-    http.AddStandardResilienceHandler();
+   //http.AddStandardResilienceHandler();

    // Turn on service discovery by default
    http.AddServiceDiscovery();
});

This should help unblocking testing for related scenarios like #6297 and #6482.

@captainsafia
Copy link
Member

Unfortunately, it looks like it'll take a while for the root cause that was referenced above to be resolved.

@balachir Correcting myself here. The Functions team has pushed an update to their templates in VS that comments out the problematic code.

If you run this scenario again and ensure that you're using the latest version of the toolset, you shouldn't run into this issue anymore.

You can verify the version of the Functions templates you are running on by opening the only file in the %LocalAppData%/AzureFunctionsTools/Tags/v4/ and it should contain the following content:

Image

@v-bennettyue
Copy link
Author

@captainsafia @balachir This issue not repro on .net 9.0 Azure Functions + Aspire, the latest version of the toolset is 4.101.0.

@captainsafia
Copy link
Member

@captainsafia @balachir This issue not repro on .net 9.0 Azure Functions + Aspire, the latest version of the toolset is 4.101.0.

Great! Glad the new updates resolve this issue. Can we close this out or did you notice other problems?

@v-bennettyue
Copy link
Author

There is no other issue, close this issue as fixed.

@mwiedemeyer
Copy link

I've just created a new FunctionApp project in the latest VS preview with ga .net9 and got the same error.
The project/dependencies are up to date.

If I comment out http.AddStandardResilienceHandler(); in the ServiceDefaults project, it works fine. So it seems to be the same error as mentioned above.

@captainsafia
Copy link
Member

@mwiedemeyer This was resolved in the Functions templates by disabling the logic that brought in the Application insights SDK.

When you go to your project file do you observe that package references associated with Application Insights are commented out in the default template?

If they are not, your Visual Studio might be pulling an older version of the Azure Functions templates.

Try restarting Visual Studio or searching for Azure Functions in your options panel and selection "Check for toolset update".

@mwiedemeyer
Copy link

Sorry, my bad. You are right. I've updated the functions tools from within VS and now the packages and startup code is commented. However, if I enable it, I have the same error. So what is the idea how to use it with app insights?

@captainsafia
Copy link
Member

@mwiedemeyer Yes, this is an unfortunate issue with the way the Application Insight SDK registers its dependencies. This bug is tracked on the Applicaton Insights SDK over at microsoft/ApplicationInsights-dotnet#2879. There's currently a PR open to resolve this in a future version of the SDK over at microsoft/ApplicationInsights-dotnet#2908.

In the meantime, you can workaround this issue by temporarily disabling the http.AddStandardResilienceHandler(); call in the default ServiceDefaults project.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-integrations Issues pertaining to Aspire Integrations packages azure-functions Issues related to the Azure Functions integration external Issues that represent work that's external to this repo.
Projects
None yet
Development

No branches or pull requests

5 participants