You are developing an ASP.NET Core Web API with the Application Insights SDK. To optimize resource consumption in a containerized environment, you must programmatically disable the collection of performance counters and disable adaptive sampling. Complete the code snippet by filling in the correct properties of the ApplicationInsightsServiceOptions class.
Answer:csharp
builder.Services.AddApplicationInsightsTelemetry(options =>
{
options.ConnectionString = builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"];
options.【EnablePerformanceCounterCollectionModule】 = false; // Disables performance counter collection
options.【EnableAdaptiveSampling】 = false; // Disables adaptive sampling
});
builder.Services.AddApplicationInsightsTelemetry(options =>
{
options.ConnectionString = builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"];
options.【EnablePerformanceCounterCollectionModule】 = false; // Disables performance counter collection
options.【EnableAdaptiveSampling】 = false; // Disables adaptive sampling
});
Answer
To programmatically disable performance counter collection, set the EnablePerformanceCounterCollectionModule property to false. To disable adaptive sampling, set the EnableAdaptiveSampling property to false.
The correct properties are EnablePerformanceCounterCollectionModule to toggle the OS performance counter collection module and EnableAdaptiveSampling to control the sampling logic applied to outbound telemetry data.
Step-by-Step Solution
Key Concept
Configuring default telemetry modules and behavior using ApplicationInsightsServiceOptions in ASP.NET Core.