How to Fix Application insights Live Metrics stream on Azure Mobile Apps
By: Date: 28 October 2016 Categories: Uncategorized Tags: , , ,

When running the web API on a local machine with app insights enabled, we could see a nice set of graphs as shown here below:

clip_image002

But when I deploy this to the Azure Mobile services, this results in a page that only shows the dependency calls, bet never any incoming requests and also no request duration. You only see a first request and after this the incoming requests are a flat liner.

clip_image001

After some inquiries at the app insights team, I got the information that since Azure Mobile Services is using OWIN, because the app insights HTTP modules are not loaded since that is not allowed and finally because performance counters are not exposed to the web application, these metrics will not show. After going back and forth on this, I got information that it would be possible to at least get the info for the requests on the screen, by adding a small piece of middleware, that can track the request instead of the standard HttpModule that is normally instantiated, but not allowed in a Mobile app.

So the only thing I needed to do is create a middleware component like the following:

And an extension method to register the middleware in the request pipeline at startup in the Startup class:

In the application startup class, ensure that you register this handler as the first as follows:

And that is it!

When you now deploy tot the azure mobile app, you will see the live metrics as we expect. We still don’t have the memory consumption and CPU usage stats, but this now at least shows all incoming requests in real time

Hope this helps!

Marcel

3 thoughts on “How to Fix Application insights Live Metrics stream on Azure Mobile Apps

  1. Thank you Marcelo for your excellent post!

    I have the same problem, but using a Web API in MVC 5, and implementing the request handler solved my problem.

    Good work!

  2. Marcel, great article!

    Was this an Azure mobile App or an Azure Mobile Service? I recently migrated my Azure mobile service using the migrate button on the portable. I am able to see my custom event tracking but no live stream. Is this related to having been an AMS originally or does AI just not support live streaming for Azure mobile “anything”?

    -Bob

  3. Integrating the owin mobile app inside asp.net core should be possible and by simply adding the appinsights configuration in the root of your app.

Leave a Reply

Your email address will not be published. Required fields are marked *