Question

Difficulty: MediumConfigure Application Insights Instrumentation and Telemetry

A team is migrating an on-premises web application to a C# .NET 8 Minimal API hosted on Azure Kubernetes Service (AKS). The containerized application includes the `Microsoft.ApplicationInsights.AspNetCore` package.

In the `Program.cs` file, the team registers telemetry using the following code:
csharp
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddApplicationInsightsTelemetry();

During testing in the AKS cluster, the team notices that no telemetry data is populated in the Azure Portal, although the application starts up and processes HTTP requests without any exceptions. The Kubernetes deployment manifest currently defines only the `APPINSIGHTS_INSTRUMENTATIONKEY` environment variable.

Which action must the team take to ensure telemetry is sent successfully?

  1. A
    Modify the configuration to pass the legacy key directly to the telemetry configuration by setting the InstrumentationKey property in Program.cs.
  2. B
    Grant the managed identity of the AKS cluster the Monitoring Metrics Publisher role on the target Application Insights resource.
  3. Define an environment variable named APPLICATIONINSIGHTS_CONNECTION_STRING in the Kubernetes deployment manifest containing the resource's connection string.Answer
  4. D
    Configure a Key Vault reference in appsettings.json using the @Microsoft.KeyVault syntax to map the legacy key.

Answer

Define an environment variable named APPLICATIONINSIGHTS_CONNECTION_STRING in the Kubernetes deployment manifest containing the resource's connection string.
Defining the APPLICATIONINSIGHTS_CONNECTION_STRING environment variable is the correct approach. Modern Application Insights SDKs look for this specific environment variable when initializing via AddApplicationInsightsTelemetry without explicit code parameters. The connection string contains the target ingestion endpoint and instrumentation key, which are required for successful data transmission.

Step-by-Step Solution

1
Analyze the telemetry initialization pattern.
The code calls `builder.Services.AddApplicationInsightsTelemetry()` without arguments, which relies on standard environment variables or configuration keys to locate the connection string.
Understanding how the Application Insights SDK retrieves its target configuration is essential to finding the missing configuration point.
2
Identify the configuration source in the Kubernetes environment.
The Kubernetes manifest currently only defines the legacy `APPINSIGHTS_INSTRUMENTATIONKEY` variable, which is deprecated and not automatically mapped to the connection string required by modern .NET SDKs.
Since the connection string is not set, the telemetry SDK will initialize without a destination, resulting in no telemetry being sent to Azure Monitor.
3
Map the correct environment variable for modern Application Insights configuration.
Define `APPLICATIONINSIGHTS_CONNECTION_STRING` containing the full connection string from the Azure Portal.
Modern SDKs require a connection string to enable features like secure ingestion endpoints and regional endpoint routing.

Key Concept

Application Insights SDK requires a valid connection string to ingest telemetry, which is conventionally configured using the APPLICATIONINSIGHTS_CONNECTION_STRING environment variable in containerized environments like AKS.
Rate this question