Soru

Zorluk: OrtaConfigure Application Insights Instrumentation and Telemetry

You are deploying a C# .NET 8 microservice to Azure Container Apps. You need to enable Application Insights instrumentation using the SDK. Which two actions should you perform to ensure the SDK is correctly initialized and telemetry is successfully sent to your Azure Monitor resource?

  1. Call `builder.Services.AddApplicationInsightsTelemetry()` in the `Program.cs` file of your microservice.Cevap
  2. Set the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable in the Azure Container App configuration.Cevap
  3. C
    Instantiate `TelemetryClient` manually using `new TelemetryClient()` in your classes without registering dependency injection.
  4. D
    Initialize the SDK by invoking `TelemetryConfiguration.CreateDefault()` without assigning a connection string.

Cevap

Register the telemetry services in the dependency injection container and set the standard connection string environment variable.
To successfully configure Application Insights using the SDK, you must register the telemetry services within the service container and provide a valid destination. Calling the extension method on the service collection registers the required components, and setting the connection string environment variable tells the SDK where to send the telemetry.

Adım Adım Çözüm

1
Add the Application Insights SDK services to the dependency injection container.
The SDK components are registered and ready to collect telemetry.
The application requires these services to auto-collect dependency, request, and exception telemetry.
2
Define the connection string environment variable in the hosting environment.
The SDK resolves the connection string at runtime.
Without a valid connection string, the SDK cannot resolve the target endpoint and telemetry is not sent.

Anahtar Kavram

Application Insights SDK Initialization and Connection Configuration
Bu soruyu puanla