If you did not read the first part here you should start before continuing: http://www.mynavblog.com/2020/02/29/telemetry-get-more-info-about-the-users-part-1/ .
In this part, I would like to show how I boosted the SDK provided by BCTech Team (I hope they do not mind – core functions are working the same way). The whole example you can find on my GitHub here: https://github.com/mynavblog/ApplicationInsights
Codeunit – Application Insights SDK
The main Codeunit – Application Insights SDK, is slightly changed by me. Still, there are all four types of tracking – Custom Event, Trace, Open Page (I changed the name) and Trace Exception.
I added to the Trace and Exception the severity level which is also sent to Application Insights (it can be one of Information, Warning, Error or Critical).
To the Open Page, I added also the type of the object which has been opened. You can choose from one of three options: Page, Report and Action. It will give you the possibility to track if the user hits the action or uses the report or the page.
In the Init() function, there is a switch to show the messages which you can use for debugging. If you want to see what will be sent and received from Application Insights, then you can set Debugging Boolean to true.
Here is an example of how the SDK changed.
Codeunit – Application Insights Mgt
In fact, you do not need to directly run procedures from the SDK Codeunit. To simplify the usage of the Application Insights with Business Central, I created a Codeunit Application Insights Mgt. Here you can find the full description of the functions: https://github.com/mynavblog/ApplicationInsights/blob/master/Readme.md
In short, you can in an easy way add properties and metrics. Also, you can easily emit CustomEvent, Exceptions (split by severity), Open Page, Open Report or Trigger Action, Trace (split by severity).
In this codeunit, you need to specify your Application Insights Key. And here is one comment – I did not want to complicate it too much to store this value. It is simply stored in the label (at least at this moment).
Here is an example of how the codeunit looks like
How to use
Below you can find how you can use the Application Insights Mgt. Codeunit. The code set one custom metric with value 12, and two properties. The name of the event is “My Event”.