Microsoft’s Application Insights provides a basic application performance monitoring solution for .NET applications. For some types of .NET projects, Visual Studio will automatically add it to your solution. In this article, we are going to cover how to disable Application Insights.
When considering to remove a tool that helps with monitoring, it’s worth thinking why you might want to do this. Microsoft claims that the overhead of adding Application Insights to a project is quite low. In my experience, this is generally the case—the benefits typically outweigh any issues that may come from having them in place.
With that in mind, here are a few reasons why you might want to remove Application Insights from your application:
- Using Application Insights with Azure comes at a slight cost, depending on the traffic that the web application provides.
- When working with your application locally, you may find that the information provided is verbose.
- It may be unnecessary to use Application Insights for applications being hosted in development or staging environments since those environments will not have significant performance concerns.
Finally, you could just not want to use Application Insights for performance monitoring and may have other means of monitoring your application. For example, you may choose to look into Retrace, which is more fully featured and provides more functionality out of the box. Let me remind you again—if you’re going to skip performance monitoring with Application Insights for a production application, make sure you have something else in place!
Okay, perhaps calling it a virus is a little harsh. But on a brand new project for ASP.NET on the full .NET Framework, Visual Studio adds a bunch of junk to your project.
Below are a couple screenshots showing the ApplicationInsights.config and added project dependencies.
Removing Application Insights
So you’ve decided to remove Application Insights from your application. Let’s walk through the process. We’ll confirm the removal of Application Insights both on the .NET application and a deployed .NET application in Azure.
To follow through the rest of this guide, you’ll need
- Visual Studio 2017
- An Azure subscription
- A .NET application that both
- has Application Insights installed. A quick side note on this—if you’re using a .NET application running .NET Framework, Application Insights is likely installed by default; alternatively, with .NET Core, Application Insights must be explicitly installed.
- is optionally hosted in Azure.
For this guide, I’ve created a .NET Framework web application using the template provided with Visual Studio.
First, let’s verify that Application Insights is running for your application. After creating the web application, start debugging the app, which automatically brings you to the homepage:
Click a few links on the top of the application (such as About and Contact) and then head back to Visual Studio. You’ll click on the “Events” tab in “Diagnostic Tools” and see something like the following:
Great! We’ve confirmed that Application Insights is running for your application. Now let’s turn off debugging mode and get to removing the package that allows for Application Insights to run. Perform one of two options to remove Application Insights from the application:
- Use the Package Management Console (a little faster but uses the command line).
- Configure using the Visual Studio NuGet UI (a little slower, but more comfortable for users unfamiliar with the CLI).
Option #1: Using the Package Management Console
First, open the Package Management Console in Tools -> NuGet Package Manager -> Package Manager Console. Enter the following command:
Uninstall-Package Microsoft.ApplicationInsights.Web -RemoveDependencies
After entering that command, the Application Insights package (along with all of its dependencies) will be uninstalled from the project.
Option #2: Using the Visual Studio NuGet UI
First, right click on the Solution and click on “Manage NuGet Packages for Solution.” Clicking this will take you to a screen that allows you to edit all of the NuGet packages that are a part of the project. Since Application Insights is a NuGet package already configured for the application, we’re just going to remove it.
Click on the package called “Microsoft.ApplicationInsights.Web,” and then check the checkbox in the project listing on the right side to select all projects. You’ll also want to remove all dependencies when uninstalling, so click on “Options” and check the option to remove dependencies under “Uninstall Options.” Your screen should look like this:
Once you click on “Uninstall,” a dialog will display that shows all of the unnecessary dependencies to be removed from the application. Go ahead and approve their removal.
Verifying removal of Application Insights locally
Now that you’ve performed one of the two options to remove Application Insights from your application, let’s confirm that Application Insights was removed. Start up your application in Debug mode, and check the Diagnostics Tools section after clicking a few links in the application you are debugging (such as the About or Contact links on the top of the page).
After checking, if you don’t see any Application Insights events, then you have successfully removed the Application Insights SDK from your web application.
With ASP.NET Core, Application Insights behaves just a little differently. It is enabled by default. To disable it within Visual Studio, you may want to use the actual Visual Studio settings to disable it.
To disable it go to “TOOLS –> Options –> Projects and Solutions –> Web Projects” and check “Disable local Application Insights for Asp.Net Core web projects.”
Below is the image for disabling local App Insights.
Disabling Application Insights in some environments
If you want to just disable Application Insights in your development environment or for other scenarios, you can also just disable the telemetry in your code or leave the instrumentation key blank.
You can disable telemetry by using this code when your application starts up:
TelemetryConfiguration.Active.DisableTelemetry = true;
TelemetryDebugWriter.IsTracingDisabled = true;
If you want to disable it in just some environments, one recommendation is to set the <instrumentationKey> in ApplicationInsights.config to be blank. Then within your code, you can set the key to enable instrumentation. You may also want to do this if you want to use different keys for different environments.
#if !DEBUG Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = “instrumentation key”;
Removing Application Insights from your application in Azure
This next step applies only to Azure-deployed .NET applications. An Application Insights Azure resource needs to be removed. After logging into the Azure portal, let’s look at the deployed application:
This resource is a representation of the data your application sends to Azure to allow for monitoring events that occur in your running application. Leaving this running is unnecessary—removing Application Insights from the application makes this resource unusable.
If you are using a paid version of Application Insights, it is definitely important to disable the billing or delete the instance completely. All you need to do here is delete the Application Insights resource from Azure, and you’ll have removed Application Insights from Azure for that specific application.
If you are using an Azure App Service, you will also want to remove the site extension for Application Insights. To remove it, go to Extensions and then click on the Application Insights extension. You can then click delete to remove Application Insights.
Hopefully, this guide successfully walked you through how to remove Application Insights from your application. Application Insights provides some basic application performance monitoring capabilities. When you are ready to get even more insights into how your application is performing, be sure to check out our APM solution, Retrace. Give these steps a try and see if you can clean up your apps a bit and remove some unneeded clutter.
- What Is NullReferenceException? Object reference not set to an instance of an object - March 5, 2021
- ASP.NET Performance: 9 Types of Tools You Need to Know! - February 19, 2021
- What is LAMP Stack? - September 24, 2020
- What is C# used for? - September 18, 2020
- How to Create SQL Percentile Aggregates and Rollups With Postgresql and t-digest - August 10, 2020