One of the toughest tasks in the development life cycle begins after deployment to monitor the performance of the application in order to know how it’s behaving on the server: whether it's working properly or if some services have stopped and many more scaling problems. Microsoft Azure has given us a very very useful service to handle all such problems – Application Insight.
Application Insight is an analytics service that continuously monitors your live Web Application. It monitors clients, servers and any third party services you are using. It also detects triage, diagnoses problems, system failures, detects performance issues, and has proactive detection in case of any failure. This also provides the capabilities to write your own events, metrics, and traces. Thus, basically we can say that Application Insight is designed to make the developers' lives easy and helps continuously to improve the availability, performance and usability of our app. "App Insights" is not only a code based plugin, it's a lot more. It provides you with a very rich user interface, where you can analyze, filter and segment the data. You can also make custom dashboards.
The Prerequisites for Application Insights are,
- Visual Studio 2013 Service pack 3 or later
- A subscription to Microsoft Azure
- Azure Cloud Services
To add Application Insight in any existing .NET Web Application, right click on the Solution and make use of Add application Insight telemetry, as shown below:
Afterwards, you will see the following login screen:
Thus, the command did three things:
- Added the Application Insights Web SDK NuGet package to your project. To see it in Visual Studio, right-click your project and choose Manage NuGet Packages.
- Create an Application Insights resource in the Azure portal. This is where you'll see your data. It retrieves the instrumentation key, which identifies the resource.
After this, you will see that the ApplicationInsights.config is added in your solution.
After this integration is done successfully, it automatically tracks telemetry from your Application and its context.
Telemetry initializers set the context properties that are sent along with the every item of telemetry.
We can write our own Initializers to set the context properties.
Public class AppInsightsContextInitializer
- Microsoft.ApplicationInsights.Extensibility.ITelemetryInitializer
- {
- public void Initialize(Microsoft.ApplicationInsights.Channel.ITelemetry telemetry)
- {
- telemetry.Context.Component.Version = typeof(MvcApplication).Assembly.GetName().Version.ToString();
- telemetry.Context.Properties["AppName"] = “abc”
- }
- }
In Global.ascx file, you can write the code to initialize,
- protected void Application_Start()
- {
-
- TelemetryConfiguration.Active.TelemetryInitializers.Add(new AppInsightsContextInitializer());
- TelemetryConfiguration.Active.InstrumentationKey = “Your Instrumentation Key”
- }
- JavaScript telemetry initializers - Insert a telemetry initializer for javascripts
- <script type="text/javascript">
-
- ...({
- instrumentationKey: "your instrumentation key"
- });
- window.appInsights = appInsights;
-
-
-
-
-
-
- appInsights.queue.push(function () {
- appInsights.context.addTelemetryInitializer(function (envelope) {
- var telemetryItem = envelope.data.baseData;
-
-
- if (envelope.name == Microsoft.ApplicationInsights.Telemetry.PageView.envelopeType) {
-
- telemetryItem.url = "URL CENSORED";
- }
-
-
- telemetryItem.properties = telemetryItem.properties || {};
- telemetryItem.properties["globalProperty"] = "boo";
-
-
- telemetryItem.measurements = telemetryItem.measurements || {};
- telemetryItem.measurements["globalMetric"] = 100;
- });
- });
-
-
-
- appInsights.trackPageView();
- </script>
Once it is installed, you can see the app insight details.
This will redirect to the Azure Portal site, where you can login and see the Application performance details.
Thus, the Application Insights do these three things mainly:
- Detect Server side Performance, issue failure.
- Monitor client Side Application (JS).
- Provide telemetric data.
Please follow this for more details.