I think that sampling is going to be the best way to handle this scenario. I noticed you have adaptive sampling turned off, but even with it on you may not see an effect even with it on at the default 5 items per second- the percentage retained is based on a rolling average, not the number in the specific second.
What I'm suggesting is to set a separate sample rate specifically for the heartbeat events- any exceptions would still be logged if the connection is lost and you can do this without affecting the sampling rate of any other telemetry items. App Insights will also adjust for sampling when calculating metrics- even if you only log one specific request, the metrics would still show that there were 20 made total.
Using the new SDK, I added this telemetry initializer to the code:
public class MyTelemetryInitializer : ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
if (telemetry is RequestTelemetry rt && rt.Name == "ServiceBusReceiver.Receive")
{
((ISupportSampling)telemetry).SamplingPercentage = 5;
}
}
}
and added it in the Program.cs file
services.AddSingleton<Microsoft.ApplicationInsights.Extensibility.ITelemetryInitializer, MyTelemetryInitializer>();
With that in place, I get the reduced traffic in the Request channel while keeping everything else.
The KQL to check sampling rates in App Insights is:
union requests,dependencies,pageViews,browserTimings,exceptions,traces
| where timestamp > ago(1d)
| summarize RetainedPercentage = 100/avg(itemCount) by bin(timestamp, 1h), itemType