How to disable adaptive sampling while passing instrumentationKey in AddApplicationInsightsTelemetryWorkerService()

21 Views Asked by At

Currently what I did in startup class is:

services.AddApplicationInsightsTelemetryWorkerService(<MyAppInsightsInstrumentationKey>);

According to official example, to disable adaptive sampling we should pass the ApplicationInsightsServiceOptions to services.AddApplicationInsightsTelemetryWorkerService(): Link

using Microsoft.ApplicationInsights.WorkerService;

public void ConfigureServices(IServiceCollection services)
{
    var aiOptions = new ApplicationInsightsServiceOptions();
    // Disables adaptive sampling.
    aiOptions.EnableAdaptiveSampling = false;

    // Disables QuickPulse (Live Metrics stream).
    aiOptions.EnableQuickPulseMetricStream = false;
    services.AddApplicationInsightsTelemetryWorkerService(aiOptions);
}

Since I am already passing the instrumentationKey. What's the proper way to disable adaptive sampling in my case?

1

There are 1 best solutions below

0
Vanderwood On

Find the answer:

var aiOptions = new ApplicationInsightsServiceOptions
{
    // Disables adaptive sampling.
    EnableAdaptiveSampling = false,
    // Disables QuickPulse (Live Metrics stream).
    EnableQuickPulseMetricStream = false,
    InstrumentationKey = <MyInstrumentationKey>
};
services.AddApplicationInsightsTelemetryWorkerService(aiOptions);