I have an ASP .NET Core app with Application Insights added. I run it locally in debug mode, send in requests at a rate of 10 per second, then examine the telemetry. I see less than half of request
telemetry events from ASP and less than half of trace
events produced by ILogger
inside my own code. I know about adaptive sampling, but thought that trace
events are excluded from it by default? (seeing how applications logs become traces in App Insights). I tried adding explicit config to make sure no telemetry is lost, but so far it didn't work:
services.AddApplicationInsightsTelemetry((ApplicationInsightsServiceOptions opt) =>
{
opt.DeveloperMode = true;
opt.EnableAdaptiveSampling = false;
});
Can I somehow configure App Insights to gather 100% of telemetry in local debug?
Update after playing around with configuration and suggestions, I noticed that visual Studio debug session is limited to searching the last 250 events, and this is what deletes my telemetry.
CodePudding user response:
No, trace
events are not excluded by default.
There are two
AdaptiveSamplingTelemetryProcessor
nodes added by default, and one includes theEvent
type in sampling, while the other excludes theEvent
type from sampling.
There are certain rare events I always want to see. How can I get them past the sampling module?
The best way to achieve this is to write a custom TelemetryInitializer, which sets the
SamplingPercentage
to 100 on the telemetry item you want retained, as shown below. As initializers are guaranteed to be run before telemetry processors (including sampling), this ensures that all sampling techniques will ignore this item from any sampling considerations.
public class MyTelemetryInitializer : ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
if(somecondition)
{
((ISupportSampling)telemetry).SamplingPercentage = 100;
}
}
}
You can refer to Sampling - FAQs , ASP.NET Core Application Insights adaptive sampling, and Troubleshooting no data - Some of my telemetry is missing