I don't think this is supported out of the box, but you can write your own ITelemetryProcessor
.
See: https://docs.microsoft.com/en-us/azure/azure-monitor/app/api-filtering-sampling#filtering-itelemetryprocessor
Application Insights in .NET uses a chain of telemetry processors that you can use to filter telemetry, so you can write your own that checks the resultCode
(I think that's what Application Insights calls the HTTP status code, but you'll have to double check) of a request telemetry object, and approves it if it's 500 (or 5xx) but only has a 10% chance of sending it if it's 2xx or 3xx. You can override the OKToSend()
method to perform the above check on the ITelemetry
input, and return true / false accordingly.
Maybe something like (I wrote this in the browser, it won't necessarily work flawlessly as-is):
// Approves 500 errors and 10% of other telemetry objects
private bool OKtoSend (ITelemetry telemetry)
{
if (telemetry.ResponseCode == 500) {
return true;
} else {
Random rnd = new Random();
int filter = rnd.Next(1, 11);
return filter == 1;
}
}