For those of you who are new to ‘Application Insights’, allow me to give you a quick intro! As the name suggests this nifty little tool helps you gain insight into your web application like user stats, error monitoring, etc. With just a few lines of code in your application, you can find out what users are doing with it, or help diagnose issues.
If you’re the voracious learner kind, you can read more about Application Insights from the official docs.
Now, let’s get to the interesting bit, how can you leverage all that monitoring goodness in your ServiceNow instance.
The Azure bit (not so much):
Assuming that you have your Azure application insights setup already (as we will not be covering that as part of this post). Head over to your Application Insights dashboard and copy over the instrumentation key. It should look something like this:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
The ServiceNow bit:
- Create a UI Script
- Create a self invoking function (yes! you can copy/paste the snippet),
(function() {
var d = document,
f = d.createTextNode('**Paste the SDK code here with the instrumentation key**'),
g = d.createElement('script'),
h = d.getElementByTagName('head')[0];
g.type='text/javascript';
g.appendChild(f);
h.insertBefore(g, h.firstChild);
} )();
- Head over to your Service Portal theme.
- JS include the UI Script onto your theme.
- Okay, all that’s great. Now how do I use this thing?!
- Wherever you would like to place the app insight tracking api in the widget client controller, do so as follows,
var insightsObj = {};
var user = $scope.user.name + '(' + $scope.user.user_name + ')';
insightsObj = {
title: 'Demo Insights Click',
user: user
}
appInsights.trackEvent(
{
name: "Demo Insights Event",
properties: insightsObj
}
);
And there you have it! Live metrics at your doorstep