Reputation: 542
I have a web application with Microsoft Application Insights. And I monitor all the requests, exceptions, perfomance, etc.
Is it possible to customize and disable the monitor of some requests?
I'd like to disable the monitor of some types of static files, like *.js, *.css, *.png.
Upvotes: 0
Views: 285
Reputation: 29711
Sure you can. One of your options is to use a telemetry filter. See the docs. An example that filters out requests based on a url is this:
/// <summary>
/// A Telemetry filter lets you define whether a telemetry item is dropped or not
/// </summary>
public class CustomTelemetryFilter : ITelemetryProcessor
{
private readonly ITelemetryProcessor _next;
public CustomTelemetryFilter(ITelemetryProcessor next)
{
_next = next;
}
public void Process(ITelemetry item)
{
// Example: process all telemetry except requests to .png files
var isRequestToUrlContainingSpecificText = item is RequestTelemetry request && request.Url.ToString().EndsWith(".png");
if (!isRequestToUrlContainingSpecificText)
_next.Process(item); // Process the item
else
{
// Item is dropped here
}
}
}
On the frontend you can also define a filter to stop telemetry from being send if it matches spcific criteria , see the docs
var filteringFunction = (envelope) => {
if (envelope.data.someField === 'tobefilteredout') {
return false;
}
return true;
};
...
appInsights.addTelemetryInitializer(filteringFunction);
Upvotes: 1
Reputation:
Thanks vivek nuna, after applying this setting
TelemetryConfiguration.Active.DisableTelemetry = true;
You can also enable AJAX request collection alltogether by using this setting:
disableAjaxTracking: false
Where dableAjaxTracking: [boolean] - If true, Ajax calls are not autocollected.
Upvotes: 0