2
votes

I`m logging telemetry in Application Insights for a .NET Framework 4.7.2 web application running on Azure App Service.

A lot of telemetry comes from static file requests like .js and .css files and is not interesting to me. Since it incurs storage costs, it would be better not to log them at all.

One of the ideas towards a solution is to filter ITelemetry items in a class implementing the ITelemetryProcessor interface, based on the url of the request.

public void Process(ITelemetry item)
{
    if (item is RequestTelemetry request && request.Url.AbsolutePath.EndsWith(".js", StringComparison.OrdinalIgnoreCase))
    {
        return;
    }

    this.Next.Process(item);
}

I suspect there might be more reliable / more effective ways accomplish what I want. Anyone?

1
I have not tested your code, but that seems to be what MS recommends for filtering events. Are you having any errors with this approach?Brandon McClure

1 Answers

1
votes

You may try disabling processing of static files through managed handlers in web.config:

<modules runAllManagedModulesForAllRequests="true"> ... coupled with preCondition="managedHandler" on the AI-specific module.

This will ensure that AI module does not process requests to static files. If that fails, using Telemetry Processor as you suggested is the next best thing.