Using Microsoft Application Insights in an MVC application

This article is also available on the Microsoft TechNet Wiki.

Microsoft Application Insights is a new service in Microsoft Azure. It is currently in free preview and it is available in the new Portal.

With Application Insights you can view telemetry data from your resources, find problems with your deployed apps and improve availability. It is easy to configure, even for the novice.

This wiki article will show you how to use Application Insights within an MVC web application.

Prerequisites

Application Insights Tools

Before we create our MVC project we need to verify we have the correct version of the Application Insights Tools.

Open Visual Studio 2013.

Click on Tools > Extensions and Updates.

01

The Extensions and Updates dialog window will appear. Click Installed on the left hand menu.

Find Application Insights Tools for Visual Studio near the top of the list. Click on the package and confirm the Version number is 2.4 or higher.

02

NOTE: If you have version 1.3.2 installed then this is the deprecated package for working with Application Insights inside Visual Studio Online. To upgrade to the latest SDK, make sure you have Visual Studio 2013 Update 3 (or later).

Click the Close button to close the Extensions and Updates dialog window.

Create Project

Click File > New > Project. The New Project dialog box appears.

Click Visual C# under Templates and select Web. The Add Application Insights to Project check box will be visible on the right side of the dialog box.

NOTE: For this example I am using Visual C# and a web project. However, Application Insights also works with Store Apps templates, specifically Windows Apps and Windows Phone Apps. It does not currently support Universal Apps. As well, Application Insights also works with the corresponding Visual Basic project types.

03

NOTE: If Application Insights is unavailable, make sure you have Visual Studio 2013 Update 3 (or later), that the tools exist under Extensions and Updates, and that you have selected a valid project template.

Click the Add Application Insights to Project check box. The Sign in to Visual Studio dialog box will appear. Enter your credentials and click Continue.

04

NOTE: Signing in is a two-step process. First, your email will be verified. Then the Sign in to your Microsoft account dialog box will appear. Enter your Password and click Sign in to finish the process.

Once your account has been verified the Add Application Insights to Project check box will become checked and your Azure account information will appear. As well, the Send telemetry to list will also be available,

05

The Use different account link allows you to switch from the currently logged in Azure account to another.

The Send telemetry to field details which Application Insights resource will house the telemetry data created by this MVC web application. The list defaults to creating an Application Insights resource based on the name of the project inside of a default resource group. The paragraph below the Send telemetry to list details exactly what will happen.

Clicking the Send telemetry to list will display all available Application Insights resources for this subscription. (Please see the following article for information on how to create an Application Insights resource: http://social.technet.microsoft.com/wiki/contents/articles/30264.creating-a-microsoft-application-insights-resource.aspx)

Selecting an Application Insights resource that is already created will update the text below the list accordingly.

06

Clicking the Configure Settings link will raise the Configuration Settings for Application Insights dialog box. This dialog box allows for more fine grain control of both the Resource Group and Application Insights Resource settings, For example, if I wanted to continue using an existing Resource Group but needed to create a new Application Insights Resource based on the project name then I could do the following:

07

Once the Application Insights settings are finalized, give the project a Name and click OK.

On the second screen select the MVC project template. Make sure the Host in the Cloud check box is unchecked.

08

Click OK.

The project will be provisioned and the Application Insights package will be added to the project. To confirm that Application Insights exists in the project an ApplicationInsights.config file will now be available in the project’s Solution Explorer. As well, the References folder will house the appropriate files.

Existing Project

Application Insights can also be added to existing web or store applications.

Open a project you wish to add Application Insights to in Visual Studio 2013.

Right click the project name within the Solution Explorer and select Add Application Insights Telemetry.

09

The Add Application Insights to Project dialog box will appear. It contains all of the same settings fields as the one in the Create New project section.

10

Click the Add Application Insights to Project button once the settings are finalized. The Application Insights package will be added as if it were a new project.

Run Project

Hit F5 to run the default MVC application in the browser.

Notice that the Application Insights counter appears in the Visual Studio toolbar. As you click through the different pages of the default application the counter will rise. This is showing the developer the number of telemetry events being sent to the defined Application Insights resource. A toast message will also appear on the first time it is run containing a link to your configured Application Insights Resource in Microsoft Azure.

11

View Telemetry Data

Now that the telemetry data has been pushed to the Azure Portal it is time to view the results. There are three ways this can be done:

  • Click the Open Application Insights link in the Toast message which appears upon first running the application.
  • Right click the project name and select Open Application Insights.
  • Expand the ApplicationInsights.config file and double click the {Application Insights resource name} Overview file.

12

Once the Azure Preview Portal page appears sign in to Microsoft Azure.

Locate your Application Insights resource and open it.

The Application Health section will be at the top of the resource blade and the generated data from the project will appear in the Overview timeline charts.

Click one of the SERVER RESPONSE TIME, BROWSER PAGE LOAD TIME, or SERVER REQUESTS chart panes to launch the blade containing its metrics. You can continue to drill down further within each blade to retrieve more granular data.

13

NOTE: It may take a few minutes for data to appear. Be patient and refresh the page occasionally. If none appears then check your settings and re-run the project to generate new events.

Conclusion

As you can see from this article adding Microsoft Application Insights to your web projects is easy to do. The service provides in-depth metrics for your deployed applications allowing you to find performance issues or to diagnose problems quickly.

NOTE: Since Application Insights is in preview mode information in this document may change in the future.

See Also

TechNet article gets Wiki Ninjas spotlight

I received a nice surprise yesterday as my TechNet Wiki article entitled Creating a Microsoft Application Insights resource received the TNWiki Article Spotlight for the week. This was the topping on the cake after the article also won a Microsoft TechNet Guru Award in March 2015.

The Wiki Ninjas blog spotlights a different article each Tuesday and this week they chose mine. Both the article and my wiki piece received some nice comments as well.

Thanks to the Wiki Ninjas blog for the spotlight!

For those interested in Application Insights, I have written another, more in-depth TechNet Wiki article here: Using Microsoft Application Insights in an MVC application.

Related Articles:

Creating a Microsoft Application Insights resource

Microsoft Azure Technical Guru – March 2015

Getting started with Curah!

Curah!

I must admit that I had never heard of Curah! from Microsoft until a few weeks ago. Now that I have created my own account and played around with it I can see the potential of it.

Curah! allows you to “Curate the web and share what you know,” according to Microsoft. It is a portal to both share and discover collections of technical content. The premised is simple. You sign in at http://curah.microsoft.com with your Microsoft account and create a profile. Your profile and picture act as a sort of advertisement for your curations. People can look at your background to see if you have knowledge of the areas you are curating.

A curation is designed to target common user questions. It contains a title, description and tags. It also has links to websites, blog posts, videos, infographics, and basically anything else you want to share with others on your topic. You can include whatever you think people will need to learn about the subject. The links can be resources that you used to learn or they can be items you wish you knew about when you were learning your subject.

Curations are easy to create and once they are published become a collection of annotated links available for all to see. Your name remains on the curation. I created three curations easily enough and they were published in no time. I focused on topics I knew well and in the end I built curations on Application Insights, Azure eBooks, and .NET User Groups in Ontario. All of my curations can be seen under my profile.

If you only wish to use the site for technical content research then you do not need an account. You can search for any topic and it will scan curations by description and title. You can also filter curations by their tags.

So, give Curah! a try – either if you are looking to find a resource or if you would like to create your own curations to share your expertise.

Microsoft Azure Essentials free eBook series

Microsoft Press has recently started releasing a series of eBooks under the title Microsoft Azure Essentials. These books are all about Azure and they are written with the care and precision of traditional paper MS Press books. The best part though is that all of them are FREE.

Current books

There are three books currently in the series:
  

Fundamentals of AzureMicrosoft Azure Essentials: Fundamentals of Azure

Michael S. Collier and Robin E. Shahan
February 2015
246 pages

The first book in the series serves as an introduction to the world of Azure. It balances its approach to Azure by looking at seven key areas. It also shows how to navigate both the old Management Portal and the new Preview Portal.

I am currently working my way through this book right now and I can honestly say that it is an excellent read – both as refresher on the older technologies and as an introduction to new ones.
  

Microsoft Azure Essentials: Azure AutomationAzure Automation

Michael McKeown
March 2015
112 pages

The second book in the series is on Azure Automation. This is a timely topic as the world of dev ops has become huge. Azure Automation helps you with automating frequent tasks centered around continuous deployment.

Automation tasks are built using runbooks. They are created using Windows PowerShell Workflow and once completed are stored in Azure.

Using Azure to automate your tasks means you diminish the likelihood of errors and you can complete your work in a more timely manner.
  

Azure Machine LearningMicrosoft Azure Essentials: Azure Machine Learning

Jeff Barnes
April 2015
237 pages

The newest eBook in the Microsoft Azure Essentials series is Azure Machine Learning. The book details instructions on how the developer can create predictive analytics models and then deploy them so that they can be consumed as a web service.

The book talks about some common machine learning algorithms and also provides samples on how to use the service.
  

Conclusion

These are the first three books in the Microsoft Azure Essentials series. More books are slated on future topics and I for one cannot wait for the rest. Azure is moving so fast right now and they are adding so many new features that it can be hard to stay up to date. This series of books is a great way to do just that.

Microsoft Azure Technical Guru – March 2015

Last month I wrote an article for the TechNet Wiki entitled Creating a Microsoft Application Insights resource.

I then entered it into the Microsoft TechNet Guru Awards. These awards celebrate articles on TechNet that have been written in the previous month. According to the site, “the contributions are scored by a panel of judges (5 per category, 2-3 in each are MS experts).” After the judging is done, the top three places are awarded gold, silver and bronze medals.

I am excited to say that my article has won the silver medal for March 2015 in the Microsoft Azure category:

The Microsoft Azure category in the March 2015 Microsoft TechNet Guru Awards

The last column in the image above shows some of the comments judges made during the selection process. Thanks to them all for the kind words.

I am extremely happy to be a winner in the very first month I entered. I encourage everyone to contribute to the TechNet Wiki. For more information on how, please see these Getting Started and How to Contribute articles.

Related Articles:

Creating a Microsoft Application Insights resource

TechNet article gets Wiki Ninjas spotlight

Follow

Get every new post delivered to your Inbox.

Join 98 other followers