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?
- Call `builder.Services.AddApplicationInsightsTelemetry()` in the `Program.cs` file of your microservice.Answer
- Set the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable in the Azure Container App configuration.Answer
- CInstantiate `TelemetryClient` manually using `new TelemetryClient()` in your classes without registering dependency injection.
- DInitialize the SDK by invoking `TelemetryConfiguration.CreateDefault()` without assigning a connection string.
Answer
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.
Step-by-Step Solution
Key Concept
Application Insights SDK Initialization and Connection Configuration