Hieu Le
Hieu Le

Reputation: 1132

How to temporary stop logging RequestTrackingTelemetryModule in Application Insights for ASP.NET MVC(.NET Full)

How can we stop logging specific module such as RequestTrackingTelemetryModule in ASP.NET MVC (.NET Full, not .NET Core)

I have tried to remove

<Add Type="Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule, Microsoft.AI.Web">

in ApplicationInsights.config but it throws me a strange exception

I am using Azure Web App for both staging and live environments. So I just want to stop logging request information on live environment since it cost too much.

Thanks for helping!

Upvotes: 1

Views: 766

Answers (1)

Ivan Glasenberg
Ivan Glasenberg

Reputation: 30035

You can use ITelemetryProcessor, and following this link.

Add a custom class which implements ITelemetryProcessor:

public class MyTelemetryProcessor : ITelemetryProcessor
{
    private ITelemetryProcessor Next { get; set; }

    public MyTelemetryProcessor(ITelemetryProcessor next)
    {
        this.Next = next;
    }

    public void Process(ITelemetry telemetry)
    {

        RequestTelemetry request = telemetry as RequestTelemetry;

        if (request != null)
        {
            return;
        }

        if (request == null)
        {
            this.Next.Process(telemetry);
        }
    }
}

Then in the ApplicationInsights.config, add this:

<TelemetryProcessors>
    <Add Type="WebApplicationMVC.MyTelemetryProcessor, WebApplicationMVC">
      <!-- Set public property -->     
    </Add>
  </TelemetryProcessors>

the screenshot:

enter image description here

It did filter out all the requests from app insights data, test result as below:

enter image description here

Upvotes: 1

Related Questions