Reputation: 6907
I have a question about Azure Application Insights Sampling.
I do require sampling at 10%, which I know I can achieve easily on Application Insights using applicationinsights.json
. But I also have a use case where I do not want to sample (filter out) certain requests depending on a parameter. For e.g. let's say I hit a manual test request, then I do not want it to get filtered by sampling. Another use case, let's say for a specific user, I do not want the request to get filtered.
But the config for this is not static, which means, I cannot fix this during startup in the applicationinsights.json
. I need to decide it at the request level. I will need to check some request parameters, and based on them, I will decide whether to sample or not sample this request.
Is this possible to achieve? Could you please share code/docs if it is?
Upvotes: 2
Views: 978
Reputation: 1161
I believe it is accomplished by providing a custom TelemetryInitializer.
See the question "There are certain rare events I always want to see. How can I get them past the sampling module?" in the sampling document: https://learn.microsoft.com/en-us/azure/azure-monitor/app/sampling
public class MyTelemetryInitializer : ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
if (somecondition)
{
((ISupportSampling)telemetry).SamplingPercentage = 100;
}
}
}
Upvotes: 1