Soru

Zorluk: OrtaConfigure Application Insights Web Tests and Availability Monitoring

You are developing a custom availability monitoring tool as a scheduled console application that runs on an Azure Virtual Machine (VM). The application monitors an internal HTTP service and uses the Azure Application Insights SDK to track availability using the `TrackAvailability()` method.

You write the following C# code to log the test results:

csharp
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;

var configuration = TelemetryConfiguration.CreateDefault();
var telemetryClient = new TelemetryClient(configuration);

var availability = new AvailabilityTelemetry
{
Name = "InternalServiceCheck",
RunLocation = "AzureVM-EastUS",
Success = true
};

telemetryClient.TrackAvailability(availability);
telemetryClient.Flush();

During testing, you notice that availability metrics are not appearing in Application Insights. The connection string for Application Insights is stored in an Azure Key Vault secret.

Which two of the following configuration steps should you perform to resolve this issue and ensure the availability telemetry is securely sent to Application Insights? (Select two)

  1. Set the `ConnectionString` property of the `TelemetryConfiguration` object using the connection string value retrieved from Azure Key Vault.Cevap
  2. Assign a system-assigned managed identity to the Azure Virtual Machine and grant it the Key Vault Secrets User role on the Key Vault containing the connection string.Cevap
  3. C
    Generate a Shared Access Signature (SAS) token for the Application Insights resource and assign it to the `TelemetryConfiguration` object to authorize telemetry ingestion.
  4. D
    Use the default `TelemetryConfiguration.Active` static configuration without specifying a connection string, as Azure VMs automatically route Application Insights traffic.

Cevap

Assign a system-assigned managed identity to the Azure Virtual Machine, grant it the Key Vault Secrets User role on the Key Vault, and set the `ConnectionString` property of the `TelemetryConfiguration` object using the retrieved connection string.
To resolve the missing telemetry issue securely, you must retrieve the connection string from Key Vault and supply it to the Application Insights SDK. This is done by enabling a system-assigned managed identity on the Azure VM and granting it the Key Vault Secrets User role, allowing the application to fetch the secret at runtime. In the code, the retrieved connection string must be assigned to the `ConnectionString` property of the `TelemetryConfiguration` object passed to the `TelemetryClient` constructor.

Adım Adım Çözüm

1
Enable system-assigned managed identity on the Azure Virtual Machine hosting the console application.
The VM is assigned a unique identity in Microsoft Entra ID.
This identity allows the VM to authenticate to Azure resources like Key Vault without hardcoded credentials.
2
Grant the VM's managed identity the Key Vault Secrets User role on the Key Vault containing the Application Insights connection string.
The application running on the VM can retrieve the connection string secret using Azure Identity SDK.
By default, managed identities do not have access to Key Vault secrets, so explicit permission must be granted.
3
Retrieve the connection string in the application code and set it on the `TelemetryConfiguration.ConnectionString` property before instantiating the `TelemetryClient`.
The telemetry client is correctly initialized with the connection string.
Application Insights SDK requires the connection string to determine where to send the availability telemetry data.

Anahtar Kavram

Custom availability monitoring with the Application Insights SDK requires initializing the TelemetryClient with a valid connection string, which can be securely retrieved from Key Vault using a VM's managed identity.
Bu soruyu puanla