Why does the Azure portal tell me to "Turn on Application Insights" while I have it installed via SDK NuGet package and configured correctly?

Frank van Eykelen 131 Reputation points
2021-01-22T11:39:26.9+00:00

However, when I click on any of the links to Application Insights from my app I only get the suggestion to "Enable Application Insights without redeploying your code", instead of a link to the linked AI resource:
59539-image.png

Our setup is one of the methods described in https://learn.microsoft.com/en-us/azure/azure-monitor/app/azure-web-apps?tabs=net

This is a problem for us because people looking at the app in the portal who don't know that it has the SDK installed will now think that the app doesn't have AI, and turn it on via the portal. Which will not change anything ("it will back off when it detects that the SDK is already added to the application" - source), but confusion is never a good thing.

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,660 questions
{count} votes

Accepted answer
  1. Frank van Eykelen 131 Reputation points
    2021-01-22T16:13:49.287+00:00

    This is useful - from https://stackoverflow.com/q/50717398/533460:

    I've come to conclusion based on Tseng's answer that it is best practice to use APPINSIGHTS_INSTRUMENTATIONKEY in both, in Azure portal and in appsettings.json.

    ASP.NET Core understands both APPINSIGHTS_INSTRUMENTATIONKEY and ApplicationInsights:InstrumentationKey, but Azure Portal only the first one and it has to be environment variable. If you used the second, and tried to read it from config somewhere in the code, you could easily end up with different values in Azure Portal and in your app running in Azure.

    Also, if you are manually reading the instrumentation key from configuration, you should first look at APPINSIGHTS_INSTRUMENTATIONKEY and then to ApplicationInsights:InstrumentationKey:

    var instrumentationKey= Configuration.GetSection("APPINSIGHTS_INSTRUMENTATIONKEY")?.Value
        ?? Configuration.GetSection("ApplicationInsights:InstrumentationKey")?.Value;
    

    because that's how services.AddApplicationInsightsTelemetry(Configuration); works as well. Just in case there would be different setting key in Azure Portal than in appsettings.json

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Stanislav Zhelyazkov 28,596 Reputation points MVP Volunteer Moderator
    2021-01-22T12:48:43.383+00:00

    Hi,
    Besides using the App Insights SDK app services integrates with App Insights by having extension (agent) that is installed (it is always installed just not configured). The App service probably detects that you have not installed that extension so you thus prompting you to do it.

    Official docs:
    If both agent-based monitoring and manual SDK-based instrumentation is detected, only the manual instrumentation settings will be honored. This is to prevent duplicate data from being sent. To learn more about this, check out the troubleshooting section below.

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


  2. Frank van Eykelen 131 Reputation points
    2021-01-22T16:06:21.95+00:00

    I found the solution - when I add an APPINSIGHTS_INSTRUMENTATIONKEY with the same value as ApplicationInsights:InstrumentationKey ...

    59712-image.png

    .. I get the link I expect:

    59713-image.png

    Next I'll try if it all works without "ApplicationInsights:InstrumentationKey", but my weekend has just begun! ;-)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.