Application Insights Exceptions and Failures

10,708

Try removing all references to Application Insights, Clean the project. Then add the NuGet package Microsoft.ApplicationInsights.Web, currently at version 1.2.1.

PM> Install-Package Microsoft.ApplicationInsights.Web

This will install all the required dependencies. Once installed, create an Application Insights resource in your subscription (follow instructions at Add Application Insights SDK to monitor your ASP.NET app) and add the Instrumentation key to your app. I'd recommend putting the instrumentation key in your web.config settings:

  <appSettings>
    <add key="AppInsightsInstrumentationKey" value="your-key-value" />
  </appSettings>

and adding it to your application in Application_Start like:

TelemetryConfiguration.Active.InstrumentationKey = ConfigurationManager.AppSettings["AppInsightsInstrumentationKey"] ?? "some-default-key";

UPDATE ---

There is more troubleshooting information here.

  • If browser events are not being logged:
    • If there is a firewall in front of your browser client, you might have to open TCP ports 80 and 443 for outgoing traffic to dc.services.visualstudio.com and f5.services.visualstudio.com.
    • In your browser developer tools, look for the "track" entry on the network tab - it should be posting data to https://dc.services.visualstudio.com/v2/track (or fc...)
  • If server data is not recording:
    • Install Application Insights via the Azure Portal: browse to your WebApp >> Tools >> Extensions, then install the Application Insights extension.
Share:
10,708
Brent Arias
Author by

Brent Arias

Brent is a full-stack, hands-on software and cloud architect. He can be reached at [email protected]. LinkedIn profile My company AxisCode

Updated on June 21, 2022

Comments

  • Brent Arias
    Brent Arias almost 2 years

    I'm trying to work with Application Insights in the Azure preview portal and with Visual Studio 2015 Community edition. I'm encountering three different problems which I suspect are all related. I'm wondering if others are encountering these issues.

    In one of my test web applications, the App-Insight tool is partially working. In another I'm getting errors concerning irretrievable data. In the third, I'm running into deployment failures when I use App-Insight with resources in a new resource group.

    I will present all three in this question, because I suspect they may all have the same root cause.

    Partial Results

    The very first app I tried to retrofit with app-insight does actually work and display app-insight telemetry...or at least it mostly works. Half the telemetry data shows, and the rest does not make it.

    telemetry

    The sequence of setting this up was as follows:

    I started by installing the sample Mobile-MVC app that came with this MSDN Magazine article, from June 2015. After fiddling around with adding bootstrap to make responsive pages, I then decided to commit the code to VS online GIT and then deploy as an Azure web app.

    I then followed instructions to View logs in Application Insights and ran the application which succeeds in launching a browser and allowing me to interact with the site. However, during this exercise I get tons of exceptions showing in the Visual Studio output window. I've included a small snippet here, where I've bolded the most interesting two pieces:

    Exception thrown: 'System.MethodAccessException' in Microsoft.ApplicationInsights.Extensibility.DependencyCollector.dll Exception thrown: 'System.TypeInitializationException' in Microsoft.ApplicationInsights.Extensibility.DependencyCollector.dll Exception thrown: 'System.TypeInitializationException' in Microsoft.ApplicationInsights.Extensibility.DependencyCollector.dll ApplicationInsightsHttpModule failed at initialization with exception: System.TypeInitializationException: The type initializer for 'Microsoft.ApplicationInsights.Extensibility.DependencyCollector.Tracing.DependencyCollectorEventSource' threw an exception. ---> System.MethodAccessException: Attempt by method 'Microsoft.ApplicationInsights.Extensibility.DependencyCollector.Tracing.DependencyCollectorEventSource..ctor()' to access method 'Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.ApplicationNameProvider..ctor()' failed.
    at Microsoft.ApplicationInsights.Extensibility.DependencyCollector.Tracing.DependencyCollectorEventSource..ctor() at Microsoft.ApplicationInsights.Extensibility.DependencyCollector.Tracing.DependencyCollectorEventSource..cctor() --- End of inner exception stack trace --- at Microsoft.ApplicationInsights.Extensibility.DependencyCollector.DependencyTrackingTelemetryModule.Initialize(TelemetryConfiguration configuration) at Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryConfigurationFactory.InitializeComponents(IEnumerable components, TelemetryConfiguration configuration) at Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryConfigurationFactory.InitializeComponents(TelemetryConfiguration configuration) at Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryConfigurationFactory.Initialize(TelemetryConfiguration configuration) at Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.get_Active() at Microsoft.ApplicationInsights.Extensibility.Web.ApplicationInsightsHttpModule..ctor()

    [msg=Log Error];[msg=System.TypeLoadException: Could not load type 'Microsoft.ApplicationInsights.Channel.JsonSerializer' from assembly 'Microsoft.ApplicationInsights, Version=1.2.0.5639, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. at Microsoft.ApplicationInsights.Extensibility.Web.Implementation.TelemetrySerializer.d__0.MoveNext() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.ApplicationInsights.Extensibility.Web.Implementation.TelemetrySerializer.SerializeAsync(IEnumerable1 items) at Microsoft.ApplicationInsights.Extensibility.Web.Implementation.TelemetryBuffer.<>c__DisplayClass5.<FlushAsync>b__3() at System.Threading.Tasks.Task1.InnerInvoke() at System.Threading.Tasks.Task.Execute() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.ApplicationInsights.Extensibility.Web.Implementation.TelemetryBuffer.d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.ApplicationInsights.Extensibility.Implementation.TaskTimer.<>c__DisplayClass1.<b__0>d__3.MoveNext()]

    My Azure portal is receiving telemetry on some things, but not others. In short, the ability to produce telemetry is crippled, as suggested by the above exceptions.

    Now for the next problem.

    New Resource Group

    Using the preview portal, I created a brand new resource group called "SandBox". Again using the preview portal, I then made a brand new web application called "ScratchWeb" which I assigned to the "Sandbox" resource group.

    The deployment of the web resource eventually completes, but there is an associated application insight resource called ""Microsoft.WebSite3cb98c31-893c"" that automatically is created which experiences a dozen or so time-out errors before it eventually is declared as a failed deployment. Below I show an example of one of the timeout errors, as well as the final error which gives some key information.

    Operation Id
    1E2094CECE6531F1
    Tracking Id
    31283062-9061-4dcf-bd42-f9885abbf596
    Status
    GatewayTimeout
    Provisioning State
    Running
    Timestamp
    ‎9‎/‎28‎/‎2015‎ ‎10‎:‎37‎:‎59‎ ‎PM
    Duration
    PT30.7117477S
    Type
    microsoft.insights/components
    Resource Id
    /subscriptions/da769a1f-78d8-4d45-b9b3-c15ea0c89ca2/resourceGroups/SandBox/providers/microsoft.insights/components/ScratchWeb
    StatusMessage
    {"code":"GatewayTimeout","message":"Request timed out","innererror":{"diagnosticcontext":"034b642f-aece-494b-9ede-f8b015f5bfeb","time":"2015-09-29T05:37:59.8355234Z","data":"d0fe44bb-8317-4359-bf2c-160f1eb00433"}}
    Resource
    ScratchWeb
    

    And here is the final failure error message:

    Operation Id
    1E2094CECE6531F1
    Tracking Id
    08dbbf0a-0d4a-4692-9b1a-3603a984d40d
    Status
    Conflict
    Provisioning State
    Failed
    Timestamp
    ‎9‎/‎28‎/‎2015‎ ‎10‎:‎48‎:‎16‎ ‎PM
    Duration
    PT10M47.5300298S
    Type
    microsoft.insights/components
    Resource Id
    /subscriptions/da769a1f-78d8-4d45-b9b3-c15ea0c89ca2/resourceGroups/SandBox/providers/microsoft.insights/components/ScratchWeb
    StatusMessage
    {"code":"The component already existed in a different resource group.","message":"The component already existed in a different resource group.","innererror":{"diagnosticcontext":"9ea42d3d-4dbf-46e8-a188-eac09a4ddb09","time":"2015-09-29T05:48:15.7282268Z"}}
    Resource
    ScratchWeb
    

    Is this because the "Application Insights" preview is not capable of running in more than one resource group, or is it because my subscription doesn't allow it?

    The weirdest part is that once the deployment of the app-insights resource FINALLY failed, it nevertheless seems to have been created and is not visible inside my Application Insights resource collection.

    Now the last problem...

    Original Resource Group

    If I try to create a new web site in my existing, default web app resource group...then none of the aforementioned problems occurs. Unfortunately I get another problem. The "application insight" resource blade tells me "error retrieving data" when it tries to show me charts. On the other hand, Visual Studio tells me that everything is fine...it says something like "congratulations, you have published you first app insight data."

    no data no data

    So, in the end, I have only one web application with viewable App-Insight results, and those results are crippled. My attempt to create a 2nd working web app with app-insight was unsuccessful regardless if I used an existing resource group or tried a new one.

    With Visual Studio 2015 I used two different approaches to try adding the App-Insight SDK. I tried adding it to my web project after-the-fact, and I also tried adding it from a new project template. The only scenario where I got anything to work is when I instrumented my first web app "after-the-fact" with the App-Insight SDK. Unfortunately (1) those results were crippled and (2) as I've described above, I can't achieve even "crippled" results a second time. Thus right now the App-Insight capability is unworkable for me.