Search code examples
azure-application-insightsazure-appservice

Azure AppInsights not properly initialized


I have an issue with App Insights for an App Service, it seems to be wrongly initialized. For the context, I have two app services (test, prod) running .NET api + Angular SPA. Both are deployed the same way, the only difference is the publish configuration (Staging and Release) that only change the Angular app build config.

I setup logging and application insights for my App this way :

builder.Logging.AddAzureWebAppDiagnostics();
builder.Services.Configure<AzureFileLoggerOptions>(options =>
{
    options.FileName = "azure-diagnostics-";
    options.FileSizeLimit = 50 * 1024;
    options.RetainedFileCountLimit = 5;
});
builder.Logging.AddApplicationInsights(
    config => config.ConnectionString = builder.Configuration.GetConnectionString("APPLICATIONINSIGHTS_CONNECTION_STRING"),
    _ => { }
);

For the test app service, there is no problem, I can access traces in AppInsights -> test-app-insights -> logs -> run query for traces

For the production app service, I have no traces available. The thing is, the code is the same indeed, and I double checked the configuration they seem the same.

However, I saw that my test app has configuration that my production app doesn't have. That configuration is, I assume, generated by app insights.

This is the test app service configuration :

[
  {
    "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
    "value": "<key>",
    "slotSetting": true
  },
  {
    "name": "APPINSIGHTS_PROFILERFEATURE_VERSION",
    "value": "1.0.0",
    "slotSetting": true
  },
  {
    "name": "APPINSIGHTS_SNAPSHOTFEATURE_VERSION",
    "value": "1.0.0",
    "slotSetting": true
  },
  {
    "name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
    "value": "<connection-string>",
    "slotSetting": false
  },
  {
    "name": "APPLICATIONINSIGHTS_ENABLESQLQUERYCOLLECTION",
    "value": "disabled",
    "slotSetting": false
  },
  {
    "name": "ApplicationInsightsAgent_EXTENSION_VERSION",
    "value": "~2",
    "slotSetting": true
  },
  {
    "name": "DiagnosticServices_EXTENSION_VERSION",
    "value": "~3",
    "slotSetting": true
  },
  {
    "name": "DISABLE_APPINSIGHTS_SDK",
    "value": "disabled",
    "slotSetting": false
  },
  {
    "name": "IGNORE_APPINSIGHTS_SDK",
    "value": "disabled",
    "slotSetting": false
  },
  {
    "name": "InstrumentationEngine_EXTENSION_VERSION",
    "value": "disabled",
    "slotSetting": true
  },
  {
    "name": "SnapshotDebugger_EXTENSION_VERSION",
    "value": "disabled",
    "slotSetting": true
  },
  {
    "name": "WEBSITE_APPINSIGHTS_ENCRYPTEDAPIKEY",
    "value": "{\"ApiKey\":\"<api-key>",\"AppId\":\"<app-id>\"}",
    "slotSetting": false
  },
  {
    "name": "WEBSITE_HTTPLOGGING_RETENTION_DAYS",
    "value": "30",
    "slotSetting": false
  },
  {
    "name": "XDT_MicrosoftApplicationInsights_BaseExtensions",
    "value": "disabled",
    "slotSetting": true
  },
  {
    "name": "XDT_MicrosoftApplicationInsights_Mode",
    "value": "recommended",
    "slotSetting": true
  },
  {
    "name": "XDT_MicrosoftApplicationInsights_PreemptSdk",
    "value": "disabled",
    "slotSetting": true
  }
]

This is the production app service configuration :

[
  {
    "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
    "value": "<key>", // double checked the value -> ok
    "slotSetting": false
  },
  {
    "name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
    "value": "<connection-string>", // double checked the value -> ok
    "slotSetting": false
  },
  {
    "name": "ApplicationInsightsAgent_EXTENSION_VERSION",
    "value": "~2", // Was at 3 at the beggining, I tried changing it to two to see if any changes would happen. Did not.
    "slotSetting": false
  },
  {
    "name": "WEBSITE_HTTPLOGGING_RETENTION_DAYS",
    "value": "30",
    "slotSetting": false
  },
  {
    "name": "XDT_MicrosoftApplicationInsights_Mode",
    "value": "Recommended",
    "slotSetting": false
  }
]

Indeed, there is a problem with the configuration which, for the test app service, was generated when I deployed the version of my web app with the App Insights configuration update (see .NET code above).

What can be the source of this issue ? What can I double check ? I also tried restarting the App Service, that did not fix the issue. At the moment I did not try to add the missing configurations manually, as I am not sure about how it will behave as it seems to be generated by App Insights, to avoid any conflicts and also to be sure I will have the right values for the configurations

Please feel free to ask any needed information. I will update the post accordingly Thanks


Solution

  • Ok so not sure about how it worked out

    I decided to deleted my app insights resources for production, disable app insights on my app service and clean the remaining related configurations.

    Then I enabled back again, and it worked just fine. No more configurations issues, no more logs not showing up.

    I post this answer so that people can find that possible solution which is, if I didn't just miss it, not showed somewhere on Azure help or so. Indeed, it may depend on if you can delete your app insights for business reasons.

    Please feel free to add any other advice.