What is telemetry? It is an automated communication process from multiple data sources. Telemetry helps you to understand what's going on with your software – Does anybody use it? How do they use it? And if something went wrong, then when and why did that happen? In some cases, you will know about the problem even earlier than your customer.
When you report to Microsoft regarding some issues with your environment, they always check the telemetry because it will tell them more than you will.
To be clear, you will be familiar with Change Log in Business Central. It is a table where system logs record changes, provided you have set up it before. Telemetry behaves like that. It logs a user's actions and environment events and sends them to cloud storage. You have a set of default events that are being logged automatically, and you could collect the telemetry using code. It is a record in the log of an event. Detailed or not, it depends.
Environment telemetry in the Admin portal has quite limited opportunities in terms of analysis, so in this chapter, we will use some extra tools for this process. The following topics will be covered:
After this chapter, you will be able to set up the telemetry on a tenant or extension level and analyze it with the different tools.
Important Note
There is an official Microsoft repository on GitHub with multiple telemetry samples at https://aka.ms/bctelemetrysamples.
We will have an initial encounter with the telemetry and you will understand how to analyze it using the Admin portal.
Here, in the Admin portal, you can find only top-level events from your environments with filters by date and time. Detailed telemetry is available in Application Insights and we will get to know this in the sections that follow.
First of all, open the Admin portal and click on the Telemetry tab.
To obtain the telemetry, perform the following steps:
Important Note
The Admin portal telemetry contains only top-level AL events and any errors from calls through the telemetry stack.
The Telemetry tab consists of these columns:
AppObjectType: CodeUnit AppObjectId: 1310
AL CallStack:
"O365 Activities Dictionary"(CodeUnit 1310).OnRun(Trigger) line 12 - Base Application by Microsoft
You can sort the telemetry records by clicking on the column name, for instance, to get records with a higher severity level.
Unfortunately, the filtering and selection possibilities offered by the Admin portal telemetry are quite poor, so in the next section, we will learn how to use advanced telemetry in Application Insights.
Application Insights is a feature of Azure Monitor, which provides you with the possibility to monitor application performance and usage. If you want to use it, you need to create this resource in the Azure (not Admin) portal and link it to your environment or extension.
Important Note
You have only 5 GB of free telemetry data per month. Every extra gigabyte of data will cost you approximately USD 2–3 per month. Remember that some events, such as HTTP calls, could create a lot of telemetry data (several gigabytes per day), but you can always limit it in Application Insights. If you are a partner, and combining telemetry from different customers in Application Insights, you will exceed your free limit very quickly.
To begin your work with Application Insights, you need to create it as a resource in the Azure portal. Also, you must have an active Azure subscription:
Important Note
Your environment will revert to the Preparing status and will be inactive and won't restart for some time. Users might be kicked off. Please do not set this up during business hours.
Important Note
You can use the same Application Insights to collect the telemetry from different apps and environments. More than that, it is not tenant-dependent. You could use Application Insights in your tenant and collect the telemetry from tenants of different customers. Remember that it could be costly.
Now everything is ready and we can start to work with the telemetry.
Azure Application Insights retains your telemetry as a log record. The number of records per day is individual for any customer, but you will have a lot of data in any case. In this section, we will learn the main features of Application Insights and how to select and filter the data:
Now we can move on to the next section and learn how to analyze the telemetry.
In this section, we will learn how to find the requisite events with KQL and create telemetry alerts.
Let's open Application Insights in the Azure portal, select Logs, and open the query window. Start printing and just select variants from the drop-down menu.
First of all, we can check our logs for errors. Severity levels in Application Insights have different values than in the Admin portal.
To find the errors, we need to select traces according to the third severity level. Therefore, print traces and press Enter. The new line will start with the | symbol. Print where severityLevel == 3. Choose the time interval that you want to analyze. You should get something like this:
Expand the record and check for the customDimensions element. Here you can see many important values, such as TenantId (if you collect the telemetry for different tenants), environmentName, and companyName.
To filter the telemetry additionally by tenant ID, you can apply the next request:
traces
| where severityLevel == 3 and customDimensions.aadTenantId == 'Your Tenant ID'
Look at the eventId value under customDimensions (LC0045). Each event type in the system has its own ID. You can use this parameter to filter the required event types. Here are some event IDs that may help you:
Now we can construct queries that are more interesting. For example, let's find unsuccessful Business Central API calls for the last hour. The query will be next:
traces
| where customDimensions.eventId == 'RT0008' and customDimensions.httpStatusCode == 400
And the result is:
You can use telemetry for your code analysis. If you run the next query:
traces
| where customDimensions.eventId == 'RT0018'
You will see the long-running AL operations and get the objects with a call stack where your code could not work optimally and requires a lot of time to execute.
If you assigned an Application Insights connection string to your app, you can monitor who installed, uninstalled, or updated your app using the following event IDs: LC0010, LC0016, and LC0022.
More information about telemetry event codes is available here:
If you have created a new functionality and want to know whether users opened it, you can monitor pageViews instead of traces. This request will show you the number of your page views:
pageViews
| where customDimensions.alObjectId == <<your page object ID>>
From Business Central 2022 Release Wave 1, you can assign a telemetry ID to the user card and find this ID in the telemetry traces to troubleshoot the user's problems. The ID is only included in traces that occur in the context of the user's session.
By the way, you are not limited to pre-defined telemetry events. For your extension, you may log custom events using the standard LogMessage procedure. You can place them anywhere you need them. To test this, you can create a new project in the VS Code and perform the following steps:
trigger OnOpenPage();
var
CustDimension: Dictionary of [Text, Text];
begin
CustDimension.Add('result', 'failed');
CustDimension.Add('reason', 'critical error in code');
LogMessage('AB0001',
'This is an error message test',
Verbosity::Error,
DATACLASSIFICATION::SystemMetadata,
TelemetryScope::ExtensionPublisher,
CustDimension);
end;
Here, CustDimension is a text dictionary where you can place all the requisite metrics, AB0001 is a custom event ID (you can fill it as you wish, but remember not to use standard IDs), and Verbosity is the severity level.
You can also use a simplified variant of the LogMessage procedure without a text dictionary and with one or two dimensions like this:
trigger OnOpenPage();
begin
LogMessage('AB0001',
'This is an error message test',
Verbosity::Error,
DATACLASSIFICATION::SystemMetadata,
TelemetryScope::ExtensionPublisher,
'result', 'failed',
'reason', 'critical error in code');
end;
As in the previous code sample, this will create a telemetry record with two custom dimensions – result and reason, but you do not need to declare a dictionary type variable.
Finally, you have come to the end of this chapter! This material was more complex than in the previous chapters. Telemetry setup and analysis require advanced skills and now you have them. You can collect the telemetry from the environment or from the extension. You know where to find your telemetry and how to select the necessary records and analyze them. More than that, you can create your own telemetry wherever you need it. Remember that with telemetry, you can learn about issues with your apps earlier than your customers.
In the next chapter, we will learn how to report issues and outages within your environment to Microsoft.