Analyzing long running AL methods telemetry

APPLIES TO: Business Central 2020 release wave 2 and later, version 17.1. Available in extension telemetry starting with version 18.1.

The Business Central Server server will emit telemetry about the execution time of long running AL methods, including the time spent in the database. Through version 28, the signal also includes extension execution metrics, including event subscriber counts. As a partner, this data gives you insight into bad performing code and enables you to troubleshoot performance issues caused by extensions.

Starting with version 29, the extensionInfo dimension is empty. The long-running AL method event (RT0018) continues to include method execution times and SQL metrics.

Note

To collect this telemetry for Business Central on-premises, the AL Function Timing and AL Function Logging Threshold - Application Insights settings must be configured on the Business Central Server instance. Learn more in Configuring Business Central Server. With Business Central online, this telemetry is enabled with a specific threshold on a case-by-case basis by the service.

General dimensions

The following table explains the general dimensions included in the trace. The table lists the dimensions that are specific to Business Central.

DimensionDescription or value
messageOperation exceeded time threshold (AL method)
severityLevel2
user_IdThe user telemetry ID for the user. From the user card, you can use user_Id to identify the user who triggered this telemetry event. Learn more in Assign a telemetry ID to users.

Custom dimensions

This table describes the different dimensions of an Operation exceeded time threshold (AL method) operation.

Column (key)Description or value
aadTenantIdSpecifies the Microsoft Entra tenant ID when using Microsoft Entra authentication. For on-premises, if you aren't using Microsoft Entra authentication, this value is common.
alMethodThe name of the long running AL method.
alObjectIdThe ID of the AL object that executed the AL method.
alObjectNameThe name of the AL object that executed the AL method.
alObjectTypeThe type of the AL object that executed the AL method.
alStackTraceThe stack trace in AL.
clientTypeSpecifies the type of client that opened the session, such as Background or Web. For a list of the client types, see ClientType Option Type.
companyNameThe current company name.
componentDynamics 365 Business Central Server
componentVersionSpecifies the version number of the component that emits telemetry (see the component dimension.)
deprecatedKeysA comma-separated list of all the keys that have been deprecated. The keys in this list are still supported but will eventually be removed in the next major release. We recommend that you update any queries that use these keys to use the new key name.
environmentTypeSpecifies the environment type of the Business Central solution, such as Production or Sandbox.
environmentNameSpecifies the environment name of the Business Central solution, such as Production or Sandbox.
eventIdRT0018
exclusiveTimeSpecifies the execution time of the operation without the time where AL execution was suspended due to client callback (such as when waiting for user input.) The value has the format hh:mm:ss.sssssss.

Introduced in versions 21.6 and 22.1.
executionTimeSpecifies the total time that it took to execute the AL method. The value has the format hh:mm:ss.sssssss.
extensionInfoThrough version 28, specifies execution metrics for individual extensions in the session when the trace is emitted at method exit. The following information is included for each extension:<ul><li>id: the ID of the extension.</li><li>extensionName: the name of the extension.</li><li>extensionVersion: the version of the extension.</li><li>extensionPublisher: the publisher of the extension.</li><li>subscriberExecutionCount: the number of event subscribers executed in this extension.</li><li>executionTime: the millisecond component of the accumulated execution time, not the total number of milliseconds.</li></ul>From version 29, this dimension is empty.
extensionNameSpecifies the name of the extension that contains the long-running AL method.
extensionPublisherSpecifies the publisher of the extension that contains the long-running AL method.
extensionVersionSpecifies the version of the extension that contains the long-running AL method.
extensionIdSpecifies the ID of the extension that contains the long-running AL method.
longRunningThresholdSpecifies the AL function logging threshold included in the event. The value has the format hh:mm:ss.sssssss. The separate AL Function Logging Threshold - Application Insights setting determines whether the event is emitted to Application Insights.
sqlExecutesSpecifies the number of SQL statements that was executed in the method.

This dimension was introduced in Business Central 2023 release wave 1, version 22.0.
sqlRowsReadSpecifies the number of table rows that were read by the SQL statements.

This dimension was introduced in Business Central 2023 release wave 1, version 22.0.
telemetrySchemaVersionSpecifies the version of the Business Central telemetry schema.

Sample KQL code for analyzing AL method performance

Use this KQL code if you want to analyze AL method performance.

traces
| where timestamp > ago(60d) // adjust as needed
| where customDimensions.eventId == 'RT0018'
| where toint(customDimensions.alObjectId) > 0 // filter out internal server calls
| project aadTenantId = customDimensions.aadTenantId
, environmentName = customDimensions.environmentName
, environmentType = customDimensions.environmentType
, companyName = customDimensions.companyName
, alMethod = customDimensions.alMethod
, alObjectId = customDimensions.alObjectId
, alObjectName = customDimensions.alObjectName
, alObjectType = customDimensions.alObjectType
, alStackTrace = customDimensions.alStackTrace // use the KQL snippet parseStackTrace to get top/bottom of the stack trace details
, clientType = customDimensions.clientType
// exclusiveTime is the execution time of the operation, without the time where AL execution was suspended due to client callback
, exclusiveTime = customDimensions.exclusiveTime // This dimension was introduced in Business Central 2023 release wave 1, version 22.1. Backported to version 21.6
, exclusiveTimeInMS = toreal(totimespan(customDimensions.exclusiveTime))/10000 //the datatype for exclusiveTime is timespan
// executionTime is the total time of the operation, including wait time due to client callback
, totalTime = customDimensions.executionTime
, totalTimeInMS = toreal(totimespan(customDimensions.executionTime))/10000 //the datatype for executionTime is timespan
, extensionId = customDimensions.extensionId
, extensionInfo = customDimensions.extensionInfo // parse this json structure to find out if other extensions is involved
, extensionName = customDimensions.extensionName
, extensionPublisher = customDimensions.extensionPublisher
, extensionVersion = customDimensions.extensionVersion
, longRunningThreshold = customDimensions.longRunningThreshold
, longRunningThresholdInMS = toreal(totimespan(customDimensions.longRunningThreshold))/10000 //the datatype for executionTime is timespan
, sqlExecutes = toint(customDimensions.sqlExecutes) // This dimension was introduced in Business Central 2023 release wave 1, version 22.0
, sqlRowsRead = toint(customDimensions.sqlRowsRead) // This dimension was introduced in Business Central 2023 release wave 1, version 22.0
, usertelemetryId = case(
  // user telemetry id was introduced in the platform in version 20.0
  toint( substring(customDimensions.componentVersion,0,2)) >= 20, user_Id
, 'N/A'
)

Monitoring and Analyzing Telemetry
Enable Sending Telemetry to Application Insights
Monitoring and Analyzing Long Running SQL Queries On-Premises
The Business Central Administration Center