Application Insights Reporting Duplicate Events for each Server Request
Asked Answered
M

1

7

I have an API App running under Azure App Service, with Application Insights installed to track server side telemetry of API calls. When viewing Application Insights in the Azure portal, I am seeing two events for every one server call. Each event has an exact duplicate with the same timestamp, response time, telemetry, etc. I have verified that only one event is in the web server logs, so I'm not accidentally calling the same function twice from the client.

Here are a couple of screenshots to illustrate:

enter image description here

enter image description here

What could be causing this? And how can I fix it?

Marienbad answered 13/5, 2016 at 23:55 Comment(9)
Did you add any manual instrumentation, such as calls to TrackRequest, or this is just auto-instrumentation you get my installing Application Insights? Can you check if Application Insights request tracking HTTP module is registered in your web.config and only once?Ejection
AI was added automatically by Visual Studio. There is some manual instrumentation in the form of TrackTrace and TrackException calls, but there are no calls to TrackRequest. I'll post the AI registration from my Web.config in the next comment.Marienbad
<system.web> <httpModules> <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" /> </httpModules> </system.web> <system.webServer> <modules> <remove name="ApplicationInsightsWebTracking" /> <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" /> </modules> </system.webServer>Marienbad
As you can see, it's in there twice. Once under <system.web><httpModules> and again under <system.webServer><modules>Marienbad
Can you reproduce the problem on a brand new Web API project and if so would you mind posting an issue on GitHub: github.com/Microsoft/ApplicationInsights-dotnet-server/issues/… attaching the project to the issue?Ejection
Have you added Application Insights extension to your Azure application? Can you please check if you have Microsoft.AI.HttpModule.dll in your application bin folder? If it's the case then you need to completely re-deploy your application to erase all files that don't belong to your actual application stamp.Unbiased
@YuliaSafarova Thanks for your reply. I checked and Microsoft.AI.HttpModule.dll is not in the application's bin folder.Marienbad
@YuliaSafarova In the VS Server Explorer, when looking at the deployed bin folder, there is a file called Microsoft.ApplicationInsights.Extensibility.HttpModule.dll. (This does not appear in my local build bin folder). Is this the file you mean? If so, how do I "completely re-deploy" my application. It is a production application accepting live traffic, so I can't just blow it away and start over.Marienbad
Yes, that's a previous name of the same file I mentioned. Can you just remove it from your production deployment and restart application to apply the change? It's safe. And, yes, you're right - it doesn't exist in your local folder as it was added by the extension installation. It seems that your scenario was: installed extension first and later on instrumented application with SDK and re-deployed the app. In this situation you'll end up with some leftovers from extension and to remove them choose "Settings->Remove additional files from destination" in case of deploying from VS.Unbiased
U
5

There is a one known scenario that may lead to the data duplication:

  1. Application is not onboarded to AI SDK is deployed as an Azure Web App
  2. AI Extension is installed to the app -> after this step you start to receive data without need to modify your code
  3. Later on you decided to use more powerful features of AI let's say custom event tracking and on-boarded your application to AI from VS and re-deployed.

Now you may end up in the situation when HTTP module is registered twice and you start to receive duplicate request data. It happens because AI nuget packages add HTTP module definition in web.config, but extension installation drops additional assembly into your application bin folder that registers HTTP module dynamically during app start - Microsoft.AI.HttpModule.dll (Microsoft.ApplicationInsights.Extensibility.HttpModule.dll in previous versions). To correctly handle this case you need to remove extension leftovers during your application deployment by choosing "Settings->Remove additional files from destination" in case of deploying from VS.

Unbiased answered 17/5, 2016 at 17:47 Comment(1)
Selecting the "Remove additional files form destination" option and re-deploying from Visual Studio solved the issue. Thank you!Marienbad

© 2022 - 2024 — McMap. All rights reserved.