2

I want to sample apply Adaptive Sampling only to "Dependency" itemType. I used the below code to achieve this,

builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond: 250, includedTypes: "Dependency");

But the problem is the Adaptive Sampling is being applied to all the itemTypes instead of just sampling only "Dependency". Did anyone face the same problem?

1 Answers1

0

Update:

As per the method UseAdaptiveSampling definition:

enter image description here

So you can use it as below:

 builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond: 250, includedTypes: "Dependency", excludedTypes: "Event;Exception;PageView;Request;Trace");

Original answer:

Please take a look at Configure sampling settings -> Important section as below:

If you use this method to configure sampling, please make sure to set the aiOptions.EnableAdaptiveSampling property to false when calling AddApplicationInsightsTelemetry().

So change your code like below:

    //other code

    builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond:250, includedTypes: "Dependency");

    //add the following code
    var aiOptions = new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions();
    aiOptions.EnableAdaptiveSampling = false;
    services.AddApplicationInsightsTelemetry(aiOptions);

    //other code
Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60
  • Does disabling AdaptiveSampling after doing this builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond:250, includedTypes: "Dependency");, will not disable AdaptiveSampling completely? – Venkata Anusha Apr 22 '20 at 21:48
  • @VenkataAnusha, this should work as per the doc. And also, I find a more direct solution, please see the updated answer. – Ivan Glasenberg Apr 23 '20 at 02:04
  • I tried the code you mentioned above, it is disabling the sampling all together. Even dependecy is not being sampled. – Venkata Anusha Apr 23 '20 at 22:33
  • and are you using asp.net core web app? and let me know the version of .net core as well as the nuget version of application insights. – Ivan Glasenberg Apr 24 '20 at 02:35
  • and one more thing I should mention, if the data volume is not very large, it will not be sampled. But the thing confused me is that they provide maxTelemetryItemsPerSecond in sdk, so I need to confirm this from MS support. – Ivan Glasenberg Apr 24 '20 at 09:10
  • These are the versions I am using, ASP.NET Core Razor Language Services 15.8.31590 Nuget Package manager 4.6.0 And the data volume is reaching Threshold, so that should be fine. This code you mentioned above, after setting includeTypes, setting EnableAdaptivesampling to False. – Venkata Anusha Apr 24 '20 at 18:06
  • @VenkataAnusha,a quick update, I did reach out to the support team, but no feedback till now:(. – Ivan Glasenberg May 08 '20 at 05:40
  • Old thread, but since the conversation above is confusing, I came to say that this answer is the way to go. – Léon Pelletier Jun 08 '23 at 14:44