88

On Visual Studio I added application insight to a project which creates a ApplicationInsights.config and not sure what other files were added to the project.

Thing is, doing right click and press Add Application Insight was pretty straight forward. Now I'm looking with no success a way to remove the application insight for that project.

How can I achieve that ?

On production server, using DebugView, I see the telemetry logs, even after shutting down the Application Monitor Services on the server.

Any help is appreciated, I want to completely get rid of application insight on that application.

Anastasia Black
  • 1,890
  • 9
  • 21
Bart Calixto
  • 19,210
  • 11
  • 78
  • 114
  • 2
    I can't understand why Microsoft is trying to add creepy useless things like Application Insight to projects without asking? – Jalal Feb 16 '18 at 11:26
  • 1
    @Jalal Yeah it reminds me of installing any Apple product - corporate bloatware garbage IMO. – ne1410s Mar 02 '18 at 20:48

6 Answers6

94

I just wanted to add to the answers already given, having just gone through this process with an ASP.NET MVC 5 project.

Uninstall Using NuGet

As the other answers say, the best way to remove Application Insights is through Nuget: Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution.

I found it best to remove Microsoft.ApplicationInsights.Web and all its dependencies first, then Microsoft.ApplicationInsights.Javascript API.

This removed everything except:

  • the ApplicationInsights.config file,
  • a script snippet in _Layout.cshtml,

both of which I removed manually.

What Microsoft has to say

The Microsoft Azure documentation here: https://azure.microsoft.com/en-gb/documentation/articles/app-insights-troubleshoot-faq/, says:

What does Application Insights modify in my project?

The details depend on the type of project. For a web application:

Adds these files to your project:

  • ApplicationInsights.config.
  • ai.js

Installs these NuGet packages:

  • Application Insights API - the core API
  • Application Insights API for Web Applications - used to send telemetry from the server
  • Application Insights API for JavaScript Applications - used to send telemetry from the client

The packages include these assemblies:

  • Microsoft.ApplicationInsights
  • Microsoft.ApplicationInsights.Platform

Inserts items into:

  • Web.config
  • packages.config (New projects only - if you add Application Insights to an existing project, you have to do this manually.) Inserts snippets into the client and server code to initialize them with the Application Insights resource ID. For example, in an MVC app, code is inserted into the master page Views/Shared/_Layout.cshtml

Remove Manually

To remove Application Insights without NuGet, or if like me you don't trust it and want to know which files are removed, I followed these steps:

  • Remove application insights from the web.config, under system.webserver.modules, search for ApplicationInsightsWebTracking.

  • Remove all Microsoft.AI (Application Insights) prefixed references from project references.

  • Remove all Microsoft.ApplicationInsights packages from package.config.

  • Delete ApplicationInsights.config file.

  • Remove script from _Layout.cshtml:

    
    
    var appInsights=window.appInsights||function(config){
        function r(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},u=document,e=window,o="script",s=u.createElement(o),i,f;for(s.src=config.url||"//az416426.vo.msecnd.net/scripts/a/ai.0.js",u.getElementsByTagName(o)[0].parentNode.appendChild(s),t.cookie=u.cookie,t.queue=[],i=["Event","Exception","Metric","PageView","Trace"];i.length;)r("track"+i.pop());return r("setAuthenticatedUserContext"),r("clearAuthenticatedUserContext"),config.disableExceptionTracking||(i="onerror",r("_"+i),f=e[i],e[i]=function(config,r,u,e,o){var s=f&&f(config,r,u,e,o);return s!==!0&&t["_"+i](config,r,u,e,o),s}),t
    }({
        instrumentationKey:"RemovedKey"
    });
    
    window.appInsights=appInsights;
    appInsights.trackPageView();
    
    
    
  • Remove ai.0.15.0-build58334.js & ai.0.15.0-build58334.min.js from Scripts directory.

  • Clean & Rebuild all.

lance
  • 16,092
  • 19
  • 77
  • 136
Anthony
  • 1,776
  • 17
  • 29
  • 1
    Sometime ago I tried to remove it using Nuget, but it ended in a TOTAL MESS with the references... The suggested manual approach worked flawlessly! Thanks! – Tuco May 24 '16 at 17:18
  • 1
    Much appreciated, Anthony. The only insight I got from [ApplicationInsights](https://azure.microsoft.com/en-us/services/application-insights/) was that *Microsoft* builds tools that seem to serve no purpose other than to break my projects. –  Aug 31 '16 at 14:16
  • Thanks. I noticed there is also an ErrorHandler/AiHandleErrorAttribute.cs which is registered in the FilterConfig.cs – nullable Oct 30 '17 at 04:29
57

Unless I'm misunderstanding the question, you should only have to remove one extension and possibly one nuget package.

Uninstall the Application Insights Tools for Visual Studio extension and remove the Application Telemetry SDK for Services nuget package. The telemetry package is installed along with Application Insights but must be removed separately.

In my experience the telemetry package is not required if you wish to keep using Application Insights' other features. Removing the telemetry package will stop all telemetry logging but Application Insights will continue to report non-telemetry information just fine.

user1393477
  • 845
  • 10
  • 13
  • excellent, I wasn't aware of the telemetry SDK nuget package. THANKS! – Bart Calixto Apr 25 '14 at 19:59
  • 5
    This is not helpful answer, Uninstall "Application Insights Tools for Visual Studio" remove the application Insights and now when I create asp.net 4.6.1 MVC project it doesn't work. It show me error. – Anirudha Gupta Apr 06 '16 at 11:41
  • @GuptaAnirudha I'm actually here searching because I ran into the same issue. Did you find any way to make the templates work after removing the Insight Tools? – shortstuffsushi May 24 '16 at 15:57
  • @GuptaAnirudha If you, or anyone else know, I [posted a question](http://stackoverflow.com/q/37418603/1252541) asking as much. Feel free to drop an answer over there! – shortstuffsushi May 24 '16 at 16:03
  • 2
    @user1393477 What about Visual Studio 2015? I can't see any Application Insights Extension. – keft Dec 23 '16 at 15:36
  • 3
    The OP asked how to remove AI from an application, not from VS. – ProfK Apr 10 '17 at 17:47
50

I would prefer to do this:

UnInstall-Package Microsoft.ApplicationInsights.Web -RemoveDependencies
Roman
  • 624
  • 5
  • 8
13

If you use the NuGet Package Manager for the solution (Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution) you can search for ApplicationInsights and uninstall the package, and there is an option to remove dependencies. There may be several. This is the easiest way to cleanup ALL the dependencies, not just some.

David Allen
  • 829
  • 7
  • 15
  • I think that's the fastest way! I only needed to uninstall two of the ApplicationInsights dependencies, instead of manually uninstalling 8! Thanks @DavidAllen – hatsrumandcode Dec 15 '16 at 12:04
6

With a new ASP.Net Core 1.1 project:

  • Remove the Microsoft.ApplicationInsights.AspNetCore nuget package
  • Remove inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet from the _Layout.cshtml page
  • Remove @Html.Raw(JavaScriptSnippet.FullScript) from _Layout.cshtml
  • Remove .UseApplicationInsights()from program.cs
Bidjes
  • 166
  • 4
  • 10
2

I solved this by first uninstalling all Application Insight packages from (Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution)

Then ran

Uninstall-Package Microsoft.AspNet.TelemetryCorrelation -Version 1.0.0 -RemoveDependencies

in the Nuget console.

That fixed it for me.