Application Insights Developer Mode not working in ASP.NET Core 3.1

Viewed 1455

I'm using Application Insights in ASP.NET Core 3.1 application with the below code.

 public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            ApplicationInsightsServiceOptions aiOptions = new ApplicationInsightsServiceOptions();
            aiOptions.DeveloperMode = true;
            services.AddApplicationInsightsTelemetry(aiOptions);
        }

As you can see i have enabled Developer mode to ensure that the telemetry data is pushed immediately (instead of waiting for 2-5 mins). However, it doesn't seem to be working.

Any ideas on how to make it work?

2 Answers

DeveloperMode simply means SDK channel will not buffer telemetry items in memory. Regular behavior is telemetry is buffered in memory, and once every 30 secs or when buffer has 500 items, they get pushed to backend. Developer mode simply causes every item to be sent without buffering.

The telemetry will be visible in Azure portal typically in 3-10 minutes (depending on backend/indexing/etc. delays, not controlled by SDK). By enabling developer mode, only the SDK level buffering is disabled, leading to a max "gain" of 30 sec. Telemetry can still take several minutes to show up in portal.

(The intention behind behind developer mode is to show data instantly in local. i.e Visual Studio itself shows telemetry while debugging. For that Developer is not required to be explicitly enabled. Attaching a debugger automatically enables developer mode)

Did it work before you enable the developer mode?

When you register application insights into the DI container like this

services.AddApplicationInsightsTelemetry()

It automatically assumes that you have in appsettings.json file a json object with the instrumentation key

  "ApplicationInsights": {
    "InstrumentationKey": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  },

Same when you deploy it as an azure web app, it automatically creates a configuration variable for you.

I would suggest that you pass your instrumentation key into your ApplicationInsightsServiceOptions explicitly to make sure it is loaded properly.

ApplicationInsightsServiceOptions aiOptions = new ApplicationInsightsServiceOptions();
aiOptions.InstrumentationKey("xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
aiOptions.DeveloperMode = true;
services.AddApplicationInsightsTelemetry(aiOptions);
Related