Capturing Dynamics 365 client side performance telemetry with Azure Application Insights

Application Insights is a new performance monitoring tools that allow you to monitor the end user performance of an application. In the past, performance monitoring was more about monitoring servers and their performance. It’s very easy to track the CRM form client-side performance using Application Insights. The Application Insight is not expensive, the basic plan is free and 1 GB of data is included every month.

3

Follow the below steps to configure the Application Insights for Dynamics 365,

  1. Create an Application Insights in the Azure portal.
  2. Open the Application Insights and Click on the Getting started under the CONFIGURE menu and click on the MONITOR AND DIAGNOSE CLIENT-SIDE APPLICATION.

4

  1. In the Client application monitoring and diagnosis form, copy the instrumentation key and paste it in a notepad file.5
  2. Log in to Dynamics 365 and create a web resource for Application Insights and add the below-mentioned scripts. Update your Application Insights Instrumentation key in the highlighted area on the script.

 

if (ApplicationInsights === "undefined") {
 var ApplicationInsights = {};
}

ApplicationInsights = {
 trackApplicationInsight: function (entityName, properties) {
 var appInsights = window.appInsights || function (config) { function i(config) { t[config] = function () { var i = arguments; t.queue.push(function () { t[config].apply(t, i) }) } } var t = { config: config }, u = document, e = window, o = "script", s = "AuthenticatedUserContext", h = "start", c = "stop", l = "Track", a = l + "Event", v = l + "Page", y = u.createElement(o), r, f; y.src = config.url || "https://az416426.vo.msecnd.net/scripts/a/ai.0.js"; u.getElementsByTagName(o)[0].parentNode.appendChild(y); try { t.cookie = u.cookie } catch (p) { } for (t.queue = [], t.version = "1.0", r = ["Event", "Exception", "Metric", "PageView", "Trace", "Dependency"]; r.length;) i("track" + r.pop()); return i("set" + s), i("clear" + s), i(h + a), i(c + a), i(h + v), i(c + v), i("flush"), config.disableExceptionTracking || (r = "onerror", i("_" + r), f = e[r], e[r] = function (config, i, u, e, o) { var s = f && f(config, i, u, e, o); return s !== !0 && t["_" + r](config, i, u, e, o), s }), t }(
 {
 instrumentationKey: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
 });
 window.appInsights = appInsights;

appInsights.trackPageView(entityName, Xrm.Page.context.getClientUrl(), properties);
 }
}
  1. For whichever entity the performance telemetry needs to be captured add the below JavaScript code to the entity JavaScript web resource.
function contactOnLoad()
{
 var operationType = '';
 if (Xrm.Page.ui.getFormType() == 1) { operationType = 'Create'; } else { operationType = 'Update'; }

var properties = { User: Xrm.Page.context.getUserName(), ObjectId: Xrm.Page.data.entity.getId(), OperationType: operationType, TriggerEvent: 'Form Load' };
 ApplicationInsights.trackApplicationInsight('Contact', properties);
}

function contactOnSave()
{
 var operationType = '';
 if (Xrm.Page.ui.getFormType() == 1) { operationType = 'Create'; } else { operationType = 'Update'; }

var properties = { User: Xrm.Page.context.getUserName(), ObjectId: Xrm.Page.data.entity.getId(), OperationType: operationType, TriggerEvent: 'Form Save' };
 ApplicationInsights.trackApplicationInsight('Contact', properties);
}

 

  1. Add the created Application Insights web resource to the Entity Form Properties and add the JavaScript function to the form on-load and on-save event, so that the complete performance metrics will be captured by the Application Insights for these.

6

  1. You can add as much as details you want to capture by adding to the properties. These properties information will be captured as custom data in the Application Insights.
var properties = { User: Xrm.Page.context.getUserName(), ObjectId: Xrm.Page.data.entity.getId(), OperationType: operationType, TriggerEvent: 'Form Save' };

ApplicationInsights.trackApplicationInsight('Contact', properties);

 

7

  1. Now the client side performance telemetry will be captured on the on-load and on-save of the entity form. This function can be added to any events like button click, business process stage change, etc to capture the client side performance and exceptions
  2. Application Insights has lots of out of the box dashboards, charts and live metrices stream to monitor the metrices easily.

8

5 thoughts on “Capturing Dynamics 365 client side performance telemetry with Azure Application Insights

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s