Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Application Insights sampling with the ASP.NET Core libraries

I need to retain all telemetry since we use this for analytics.

According to this article I can run the following Analytics query to determine the rate of sampling:

requests 
 | where timestamp > ago(1d)
 | summarize 100/avg(itemCount) by bin(timestamp, 1h) 
 | render areachart 

The results indicate some heavily sampling, especially during the day where only around 1 in 10 items are retained:

Sampling

What confuses me is that the Azure Portal insdicates that sampling is set to 100%:

Azure Portal Insights

Perhaps this only reflects Ingestion sampling? Adaptive sampling could still be occurring on the server.

How do I disable sampling completely using the ASP.NET Core libraries for Application Insights? (i.e. Microsoft.ApplicationInsights.AspNetCore 1.0.2)

Currently, this is these are the only configuration I can find and there isn't anything on sampling:

var appInsightsConfiguration = new ConfigurationBuilder()
    .AddApplicationInsightsSettings(
        developerMode: false,
        instrumentationKey: Configuration["ApplicationInsights:InstrumentationKey"])
    .Build();

services.AddApplicationInsightsTelemetry(appInsightsConfiguration);
like image 598
Dave New Avatar asked Oct 20 '16 13:10

Dave New


People also ask

How do I disable sampling in application insights?

To switch off adaptive sampling, remove the AdaptiveSamplingTelemetryProcessor node(s) from ApplicationInsights.

How do I disable insights telemetry app?

It is enabled by default. To disable it within Visual Studio, you may want to use the actual Visual Studio settings to disable it. To disable it go to “TOOLS –> Options –> Projects and Solutions –> Web Projects” and check “Disable local Application Insights for Asp.Net Core web projects.”

How do you integrate application insights in .NET Core?

Open your project in Visual Studio. Go to Project > Add Application Insights Telemetry. Choose Azure Application Insights, then select Next. Choose your subscription and Application Insights instance (or create a new instance with Create new), then select Next.

Does application insights affect performance?

The Application Insights SDK and instrumentation is designed to be extremely lightweight and have minimal impact on the performance of your application.


1 Answers

You can disable sampling by using the ApplicationInsightsServiceOptions class.

A usage example:

var aiOptions = new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions();
aiOptions.EnableAdaptiveSampling = false;

services.AddApplicationInsightsTelemetry(Configuration, aiOptions);

See more details about sampling in the Application Insights ASP.NET Core Github documentation page.

Hope this helps,

Asaf

like image 133
Asaf Strassberg Avatar answered Sep 26 '22 00:09

Asaf Strassberg