Edit

Analyze SQL query trace telemetry

APPLIES TO: Business Central 2024 release wave 2 and later

SQL query trace telemetry provides verbose logging of all SQL queries executed by Business Central. This telemetry is only emitted when verbose logging is enabled from the Help & Support page or through the Business Central admin center.

Note

SQL query trace (RT0009) is different from long-running SQL query telemetry (RT0005). The long-running SQL query telemetry is always enabled and captures queries exceeding a threshold (default 750 ms). SQL query trace captures all queries when verbose logging is active, regardless of execution time.

For more information about long-running SQL queries, see Analyzing Long Running Operation (SQL Query) Telemetry.

SQL query executed

Occurs when a SQL statement is executed while verbose logging is enabled.

General dimensions

Dimension Description or value
message Executed a SQL statement
severityLevel 0 (Verbose)
user_Id The 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

Dimension Description or value
aadTenantId Specifies the Microsoft Entra tenant ID used for Microsoft Entra authentication. For on-premises, if you aren't using Microsoft Entra authentication, this value is common.
alObjectId Specifies the ID of the AL object that executed the SQL statement.
alObjectName Specifies the name of the AL object that executed the SQL statement.
alObjectType Specifies the type of the AL object that executed the SQL statement.
clientType Specifies the type of client that opened the session, such as Background or Web. For a list of the client types, see ClientType Option Type.
companyName The current company name.
component Dynamics 365 Business Central Server
componentVersion Specifies the version number of the component that emits telemetry.
environmentName Specifies the name of the tenant environment. Learn more in Managing Environments.
environmentType Specifies the environment type for the tenant, such as Production or Sandbox. Learn more in Environment Types.
eventId RT0009
executionTime Specifies the time it took to execute the SQL statement. The value has the format hh:mm:ss.sssssss.
extensionId Specifies the AppID of the extension that contains the AL object.
extensionName Specifies the name of the extension that contains the AL object.
extensionPublisher Specifies the publisher of the extension that contains the AL object.
extensionVersion Specifies the version of the extension that contains the AL object.
sqlServerSessionId Specifies the ID of the SQL Server session that executed the query.
sqlStatement Specifies the SQL statement that was executed. The value is limited to 8192 characters.

Sample KQL code

traces
| where timestamp > ago(1d) // SQL query traces generate high volume
| where customDimensions.eventId == 'RT0009'
| project timestamp
, message
, aadTenantId = customDimensions.aadTenantId
, environmentName = customDimensions.environmentName
, companyName = customDimensions.companyName
, alObjectId = customDimensions.alObjectId
, alObjectName = customDimensions.alObjectName
, alObjectType = customDimensions.alObjectType
, executionTime = customDimensions.executionTime
, sqlStatement = customDimensions.sqlStatement

Tip

Be careful when analyzing RT0009 events as they can generate large volumes of data. Always limit your query time range and consider filtering by specific objects or sessions.

To learn more about how to set up alerting on Business Central telemetry, see Alert on Telemetry.

Monitoring and Analyzing Telemetry
Analyzing Long Running Operation (SQL Query) Telemetry
Enable Sending Telemetry to Application Insights