ASP.NET 4.6.2 Application Insight Dynamic Flag to reduce telemetry

67 Views Asked by At

I have multiple applications that are using ASP.NET 4.6.2 and I am looking towards Application Inishgts to capture telemetry and logging data. Since this is ASP.NET 4.6.2 there is no app.config where I can toggle the LogLevel and I could not find any details on how I can dynamically set the level of logging and telemetry information to reduce the amount of data being passed to App Insights.

To make this configuration dynamics is another item that I could not find information on, which will come in handy on Production environment where I want to limit the information and change configuration without having to restart the application.

Thanks for you help.

I am looking into sampling, but then I might miss out on important information and will not have complete picture to debug issues.

2

There are 2 best solutions below

0
Peter Bons On

There are limited mechanisms that can be used to reduce telemetry:

If you want to decide at runtime what telemetry to let pass and what to discard using a telemetry processor would be a great option as each and every telemetry item is passed through the processor.

A simple & naive implementation could be:

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

    // next will point to the next TelemetryProcessor in the chain.
    public ReduceTelemetryFilter(ITelemetryProcessor next)
    {
        this.Next = next;
    }

    public void Process(ITelemetry item)
    {
        // To filter out an item, return without calling the next processor.
        if (!OKtoSend(item)) { return; }

        this.Next.Process(item);
    }

    private bool OKtoSend (ITelemetry item)
    {
        // some logic
    }
}

This gives you full control and you get the option to base your decision on the type, content and/or severity of the telemetry item.

0
Suresh Chikkam On

Since this is ASP .NET 4.6.2 there is no app.config where I can toggle the LogLevel.

Yes, I agree but instead of relying on the app.config file, you can configure Application Insights directly in the code.

  • Here I created a ASP .NET 4.6.2 web application and configured Global.asax.cs that you can check below.

Code:

using System;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;

namespace WebApplication13
{
    public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // Enable Application Insights
            TelemetryConfiguration.Active.InstrumentationKey = "instrumentation-key";

            // Additional telemetry initializers if needed
            TelemetryConfiguration.Active.TelemetryInitializers.Add(new Microsoft.ApplicationInsights.DependencyCollector.HttpDependenciesParsingTelemetryInitializer());
            TelemetryConfiguration.Active.TelemetryInitializers.Add(new Microsoft.ApplicationInsights.WindowsServer.AzureRoleEnvironmentTelemetryInitializer());
        }
    }
}

enter image description here

  • Install all the above packages which I have highlighted by this I can be able to get the logs.

enter image description here