Application Insights Exceptions and Failures - c#

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.
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."
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.

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.

Related

How to track down AppInsights internal error

Some general setup of my system:
Windows x64
.net 3.1
AspNet.Core
Serilog + AppInsights writer
Recently, we started to observe many trace logs like below. I think something went wrong when we try to write log into AppInsights. But we can see our logs. It seems we have everything we wanted logging into AppInsights correctly. But we also have this unwanted trace message logged in as well, and there are a lot of them.
This trace message happens on my local machine, in our Azure AKS environment. But the stack trace is too short to help locating the origin of the error.
AI (Internal): [Microsoft-ApplicationInsights-Core] [msg=Log Error];[msg=Exception while initializing Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers.ClientIpHeaderTelemetryInitializer, exception message - System.ObjectDisposedException: Request has finished and HttpContext disposed.
Object name: 'HttpContext'.
at Microsoft.AspNetCore.Http.DefaultHttpContext.ThrowContextDisposed()
at Microsoft.AspNetCore.Http.DefaultHttpContext.get_Features()
at Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers.TelemetryInitializerBase.Initialize(ITelemetry telemetry)
at Microsoft.ApplicationInsights.TelemetryClient.Initialize(ITelemetry telemetry)]
I tried to create an environment, with Asp.net core application & .net3.1 for track down the logs (Request, exceptions, users, failure, trace etc.)
Here are the steps i followed : Added application insight telemetry to my application and install the NuGet package Microsoft.ApplicationInsights.AspNetcore
And in startup.cs under services.AddControllersWithViews(); add
services.AddApplicationInsightsTelemetry(Configuration["APPINSIGHTS_CONNECTIONSTRING"]);
After deploy the app to azure and for tracing the logs go to my created Application insights> Transaction search>view data ,Where we can see all of our logs as below also to identify if there is any error occurs.
Also we can download all our logs and track down for the application using kudu-console.
Go to App service>Advance tools>Go
For more information please refer the below links:
.MS DOC | Explore .NET/.NET Core and Python trace logs in Application Insights
.SO Thread | Application Insights not showing stack trace for errors
.Blog| Using Azure Application Insights For Exception Logging In C#

diagnostics not working in web role for Azure SDK 2.5.1

I am working with Azure SDK 2.5.1, mainly on the new designed diagnostics stuffs. However, I found I cannot get it run for my web role.
So, I created a cloud service project, added a web role. Then, I appended one Trace message at the end of Application_Start in Global.asax.cs:
Trace.TraceInformaction("Application_Start end.");
After that, I right clicked the WebRole and opened the Properties tab. In the diagnostics config window:
General: I choose 'Custom plan', also specified the storage account, keep the 'Disk Quota in MB' as default '4096'
Application Logs: 'Log level' switch to 'All', others kept as default
Other tabs are in default config settings
After I deployed the project to cloud, I found some unexpected things:
There is no WADLogsTable exists in Table storage. That's very strange, if I use a Worker Role, it would work as expected. So in web role, I just cannot find the Trace logging?
For the performance counters, since I am using the default config with 8 counters, I can only see 8 in WADPerformanceCountersTable table storage. In my assumption, over time, there would be more and more values of this 8 counters transferred to this table. But it was just not happened, after several hours, it still had that 8 counter values.
I just thought the diagnostics for Web Role just crashed or not working at all. Meanwhile, I checked the logs located at "C:\Logs\Plugins\Microsoft.Azure.Diagnostics.PaaSDiagnostics\1.4.0.0\DiagnosticsPlugin.log" in server, at the end of this file there is an exception said some diagnostics process exit:
DiagnosticsPlugin.exe Error: 0 : [4/25/2015 5:38:21 AM] System.ArgumentException: An item with the same key has already been added.
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Microsoft.Azure.Plugins.Diagnostics.dll.PluginConfigurationSettingsProvider.LoadWadXMLConfig(String fullConfig)
DiagnosticsPlugin.exe Error: 0 : [4/25/2015 5:38:21 AM] Failed to load configuration file
DiagnosticsPlugin.exe Information: 0 : [4/25/2015 5:38:21 AM] DiagnosticPlugin.exe exit with code -105
From MSDN, the code -105 means:
The Diagnostics plugin cannot open the Diagnostics configuration file.
This is an internal error that should only happen if the Diagnostics
plugin is manually invoked, incorrectly, on the VM.
It doesn't make sense, I did nothing to the VM.
As I said above, I just did very tiny changes to the scaffold code generated by Visual Studio 2013. Did I do something wrong or it's a bug for Azure SDK 2.5?
By the way, it seems everything is ok for Worker Role.
Quote from MSDN forum:
Hey folks jumping it late here but just wanted to confirm that there was an issue with the initial 1.4.0.0 diagnostics extension where the plugin could crash on the web role under certain circumstances.
The issue has since been resolved with 1.4.1.0. If you re-apply the extension on the role you should automatically get the latest version which fixes the issue.
At early stage, the diagnostics in SDK 2.5.1 has some internal issue inside, but Microsoft already fixed it.
Anyway, we have newer version can be applied, so this is not a problem anymore, just in case you meet this issue too.

Exception for path of "/null" being thrown on all controller index methods

As of today all branches of our codebase (old and new), our staging environment and our live environment are all throwing the following exception when the Index method of any Controller is viewed in a browser:
System.Web.HttpException: The controller for path '/null' was not found or does not implement IController.
To clarify, this is even happening on code that has long since been checked in and has not been edited, when I open the project and browse to the homepage of the application. Other members of the team are also experiencing this on their own branches as of this morning too.
The exception is thrown but the respective Index page is rendered as you'd expect so the exception being thrown is silent to the user.
It looks to have started happening on our production site at just after midnight. No publish was undertaken and no Windows Updates were installed on the server. I did install yesterday's wave of Windows Updates on my own PC. I'm baffled! Any ideas?

ASP.NET errors display my local development folder?

I have a inherited asp.net project. I never had this issue in others projects,so this is completly new for me.
In my web.config, I put that the errors in customErrors mode="Off", and any error in the app is displayed on the screen.
The problem, is that the errors, displayed my develop local directory folder, when the site is published on other server...
Exameple:
ASP.NET Error
The connection of the server it's Close.
Error in C:\Develop\myProject\file.cs\MethodName() <- ?¿
Someone know what's happening?
Thanks
The stack trace information shown when there is an error is fetched from the symbol information being produced during compilation. It is stored in the pdb-files. The symbol information refers to the location of the files during compilation. When deployed, the source .cs files are not even present on the target system, it just shows what's in the pdb.
This is completely normal behaviour and nothing to worry about.
As others have noted you should never leave customerrors off on a production server as the stack trace might reveal sensitive information.
By setting the customErrors mode="Off" will expose all exceptions thrown and exposes the errors thrown YSOD (Yellow Screen of Death)
If you want to hide these then set the option to "On" and then this will only show your custom error message/page. If you still need to see these error's then set it to RemoteOnly and this will show the YSOD on the local machine the site is deployed too but show the Custom Errors to everyone else.
As for showing your development folders this is because it is just using the information where the dll's were compiled.

Publishing my Website to my Local Disk Causes Exceptions to show Paths including my Local Disk

I've published my website many times. But didn't think about this though until I came across this issue. So I decided to publish my WAP project to a local folder on my C drive first. Then used FTP to upload it to my shared host on discountasp.net. I noticed during runtime that the stack trace was referencing that local folder still and erroring out.
Anyone know what config settings are affected when publishing? Obviously something is still pointing to my local C drive and I've searched my entire solution and don't see why.
Here's the runtime error I get when my code tries to run in discountasp.net's web server
Cannot write into the public directory - check permissions
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: ScrewTurn.Wiki.PluginFramework.InvalidConfigurationException: Cannot write into the public directory - check permissions
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidConfigurationException: Cannot write into the public directory - check permissions]
ScrewTurn.Wiki.SettingsStorageProvider.Init(IHostV30 host, String config) in C:\www\Wiki\Screwturn3_0_2_509\Core\SettingsStorageProvider.cs:90
ScrewTurn.Wiki.StartupTools.Startup() in C:\www\Wiki\Screwturn3_0_2_509\Core\StartupTools.cs:69
ScrewTurn.Wiki.Global.Application_BeginRequest(Object sender, EventArgs e) in C:\www\Wiki\Screwturn3_0_2_509\WebApplication\Global.asax.cs:29
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Discountasp says it's not a permission issue but obviously it is.
The .pdb file is what's pointing to your local directory, that's not to say anything in the site is, that's an unrelated issue. Wherever the project was compiled ad the .pdb files created, those are the paths that will appear in the stack trace.
These directory entries have no bearing on where the application is actually deployed, it's mainly just so you can see where the class that errored out is located (and hopefully you as a developer can go "oh yeah, that damn class again"). If you posted the stack we may be able to help...but the fact that the directory points to your C:\ drive is nothing to worry about, this is absolutely normal.

Categories