Home > front end >  How to customize Application Insights
How to customize Application Insights

Time:10-08

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.

CodePudding user response:

You can add the below line for the given file formats

TelemetryConfiguration.Active.DisableTelemetry = true;

CodePudding user response:

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
        }
    }
}
  • Related