Why do I need both APPINSIGHTS_INSTRUMENTATIONKEY and APPLICATIONINSIGHTS_CONNECTION_STRING in my Azure Function configuration?
Asked Answered
R

4

33

APPINSIGHTS_INSTRUMENTATIONKEY contains the instrumentation key for Application Insights.

APPLICATIONINSIGHTS_CONNECTION_STRING contains the instrumentation key for Application Insights prefixed with InstrumentationKey=.

That seems pointless unless each value enables certain features with Application Insights.

Rags answered 15/3, 2020 at 9:45 Comment(0)
A
28

Looking at the release notes for SDK Version 2.0.12998:

App Insights configuration will use the APPLICATIONINSIGHTS_CONNECTION_STRING app setting if it is set (APPINSIGHTS_INSTRUMENTATIONKEY is the fallback and continues to work as-is).

Furthermore, if you read the documentation for App Insights Connection String, you will notice that when you use connection string, you can specify custom endpoints. This is not possible if you just specify the instrumentation key. In that case, SDK will connect to default endpoints.

Axel answered 15/3, 2020 at 9:53 Comment(4)
Thank you. That is great news. I was confused because when reading this article, it tells me to add both of them. So that is just wrong? learn.microsoft.com/en-us/azure/azure-monitor/app/…Rags
Honestly, I don't know. Out of curiosity I researched for this question and provided the answer :). Two things: 1) I noticed that the document you referenced is older than the release notes I linked in my answer. So it is quite possible that they forgot to update the document and 2) If you scroll all the way to the bottom of the documentation link you shared, you'll see that you can open up a Github issue for this documentation page. I would recommend doing that so that if the documentation is incorrect, Microsoft will get it corrected.Axel
Thank you. It says in GitHub that they prefer feedback directly on the article so I have done that instead. Thanks a lot.Rags
Note the connection strings docs page linked in the answer now says (at the top): "Important: We don't recommend setting both Connection String and Instrumentation key. In the event that a user does set both, whichever was set last will take precedence."Susquehanna
T
7

One important thing to note is that if APPINSIGHTS_INSTRUMENTATIONKEY is removed from the Azure Function's configuration, the "Logs" entry in the "Monitoring" section in the Azure portal does not show logs anymore and instead asks you again to connect to an Application Insights resource. If you do so, the portal recreates the APPINSIGHTS_INSTRUMENTATIONKEY config setting.

This seems like a bug in the Azure portal since metrics and logs do continue to be collected. Also, funny enough "Log stream" continues to work as well.

Treenatreenail answered 15/6, 2020 at 13:48 Comment(2)
AFAIK Log stream doesn't use AppInsights.Xylophagous
It is using both now. The source can be selected from the drop-down menu.Atronna
E
4

APPINSIGHTS_INSTRUMENTATIONKEY is deprecated:

On March 31, 2025, support for instrumentation key ingestion will end. Instrumentation key ingestion will continue to work, but we'll no longer provide updates or support for the feature. Transition to connection strings to take advantage of new capabilities.

And if you use APPINSIGHTS_INSTRUMENTATIONKEY you should migrate to APPLICATIONINSIGHTS_CONNECTION_STRING.

This means that we need just APPLICATIONINSIGHTS_CONNECTION_STRING.

Exequatur answered 6/3, 2023 at 9:19 Comment(0)
H
0

You'll only need to set the application insights connection string. Either in your appsettings.json

{
  "ApplicationInsights": {
    "ConnectionString" : "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://{region}.in.applicationinsights.azure.com/;LiveEndpoint=https://{region}.livediagnostics.monitor.azure.com/"
    }
}

Or as an environment parameter. In Azure under settings-> configuration -> application settings:

  {
    "name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
    "value": "InstrumentationKey=xxxxxx-xxxx-xxxx-xxxx-xxxxx;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/",
    "slotSetting": true
  },
Hypostyle answered 13/9, 2023 at 13:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.