Coding with Titans

so breaking things happens constantly, but never on purpose

HowTo: Azure ApplicationInsights into my WCF server

Here I would like to present a small recipe, that will let you enable monitoring of WCF server-side calls with Microsoft’s ApplicationInsights service. It might help you in analytics of:

  • what services are used mosts
  • what hours users are active
  • what are the response times
  • what is called far too often and needs optimization
  • and probably most important thing - what crashed, why, when with the callstack! It’s pretty straightforward and I split it into two parts.

First part - tasks are required to be done on the Azure side. For the foremost – you will need an Azure Account and an active subscription. I am assuming you already got one. Details are out of the subject for this tutorial. Even though Azure is a paid service, an ApplicationInsights till first million of actions is free as I remember correctly. Second part – how to update the server-side of an application to utilize the Application Insights service. It focuses on proper packages installation via NuGet and the configuration.

Let’s go then. Do it on Azure:

  • Login into Azure Portal.
  • Click on “Create a resource” and input “Application Insights” in a search field. Then click “Create” button.

Azure Create AppInsights resource

  • Select an “ASP.NET web application” and complete the process.
  • After few seconds, new service will be created, navigate to it.
  • What is really required to store/remember is called “Instrumentation key”. Obtain it from the “Properties” section or via “Essentials” part of the “Overview” section as shown below.

Azure AppInsights Overview

  • We are done here.

Now, it’s time to update the ASP.NET WCF application, to post metrics and call to Azure appropriately.

  • Open your solution in Visual Studio 2015 Community (or newer).
  • Navigate to “Tools –> NuGet Package Manager –> Package Manager Settings –> Package Source” as on picture below.
  • Add new source for AppInsights SDK (open-sourced and hosted on GitHub).

NuGet Sources

Name it anyhow you like, and use “” as source URL.

  • Install the package: “Microsoft.ApplicationInsights.Wcf” (Include prerelease should be checked). It should also download all other packages it depends on.

AppInsights Packages

  • Now, inside the Globa.asax file, update the “Application_Start” method. Enable the monitoring of the application by placing the “Instrumentation Key”. The value we got earlied from Azure Portal, when the cloud service itself was created.

TelemetryConfiguration.Active.InstrumentationKey = “my-instrumentation-key”;

AppInsights Instrumentation Key

  • All the other necessary configutaion could be tweaked via code or _ApplicationInsights.config _file, that was added to the project during packages installation. At this time, we don’t need to modify it anyhow.
  • So we are done. Now the new version of the application is ready to be deployed. Once this is finished, statistics will be uploaded and visible through poral almost in real time.

If you can visit the portal again after some time, instead of being empty, it should display content as follows:

Azure AppInsights working

That was it!