I previously wrote a blog post on one way to monitor licensing usage with Azure Application Insights. With the 10.0.30 update for D365 Finance and Operations that is available, it is easier now with new functionality added.
The functionality once enabled using Feature Management, is under System Administration - Setup - Monitoring and telemetry parameters where you can choose the different types of telemetry to log.
After you select the types of telemetry, you need to enter the LCS Environment Id, Environment Mode, and the Application Insights Instrumentation Key.
After doing these steps. the environment will start sending out all Form runs which are Page views, User sessions, and X exception information. You can also log Custom events and metrics. To log custom metrics, enable the first telemetry type named Custom metrics. Logging custom metrics is useful for knowing how long a certain process ran or perhaps you are interested in the number of records a particular process updated. Logging custom metrics and events is a developer experience because you will need to use a X Extension class or Event Handler class to call the logMetric or logEvent methods in the SysGlobalTelemetry class. You can implement whatever type of metric you are interested in so this is where you can really take advantage of the feature.
You can choose which telemetry types you want to log. For example, in the use case of my previous blog post we only want to log an event when the Pending vendor invoice form is used or initialized by an end user. Let's say I would also like to log a custom metric for how long the form's init method would take to run. To do this I would run through the below steps in my development environment.
1. Make a reference to the Monitoring and Telemetry package from your custom code package:
2. Create an Extension class using the Chain of Command pattern to wrap the init method of the form object for the Pending vendor invoice form (VendEditInvoice), The following code snippet uses a Stopwatch class to start before the init() method is called and then stops. Then the custom metric sends the milliseconds value to the static logMetric method. This code also sends the name of the form to the logEvent method. In this case, we are not sending all Page views to App Insights. We are just sending the custom metric and the event of accessing our form.
[ExtensionOf(formStr(VendEditInvoice))] internal final class CPR_VendEditInvoice_Form_MonTelem_Extension { void init() { real timeCounter; System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); next init(); stopwatch.Stop(); timeCounter = stopwatch.get_ElapsedMilliseconds(); // Log a custom event to application insights using SysGlobalTelemetry from Monitoring and Telemetry package // send the name of the Vendor invoice form SysGlobalTelemetry::logEvent(this.form().name()); // Log a custom metric to application insights using SysGlobalTelemetry from Monitoring and Telemetry package // send the time it took in milliseconds for all init methods on Vendor invoice form to run SysGlobalTelemetry::logMetric('Vendor invoice custom metric', timeCounter); } }
3. Be sure the Custom metrics and User sessions telemetry types are enabled. After a few minutes of using the VendEditInvoice form several times, the data can be viewed in Application Insights. The below shows the name of the custom metric I passed to App Insights along with the average load time.
An important consideration to logging your telemetry data to Application Insights is cost. This link will take you to a calculator to get an idea of pricing for the amount of data you send and the length of time the data needs to be stored. It is important to be granular with what you want to capture if you can. Whether that is limiting the telemetry types, using a specific custom metric or event, and length of time you wish to enable the telemetry type(s) are factors to consider. Use the calculator to get some estimates and the chat button for more questions on cost.
This new functionality in 10.0.30 (PU54) will help with the monitoring story for your D365 Finance and Operations environments. I am already seeing some neat blog posts elsewhere on the topic that go further into the viewing of the captured data. Also, our D365 Fast Track team has a custom solution based on this feature that you can take a look at here if interested to learn more. Be on the lookout also as the product team is working on adding more functionality to this feature.
*This post is locked for comments