MSBA-353 · Lesson 7 of 12 · 19 min
Performance and telemetry
▶ Video coming soon A video version of this lesson is on the way.
Three complaints reached Noor in the first week of November, all from CONFIG. Callum said the Get Rate action "sometimes takes forever". Ysmay Thorvaldsen said the café transfer draft took several seconds to open even before Copilot was called. And the nightly web shop order import had failed twice with a message about a lock. None of them happened when Noor tried them herself. "That is what telemetry is for," she said. "We stop guessing and look at what the service recorded." This lesson covers how Business Central records what happens, how developers add their own signals, and the coding patterns that keep extensions fast.
The MB-820 outline puts telemetry in the testing and monitoring domain, weighted at 10 to 15 percent, with three skills: monitor and analyze telemetry, configure telemetry, and create custom telemetry events. Performance appears across the outline, most explicitly in the API skill "improve API performance by using Read Scale-Out".
Two destinations for telemetry
Business Central sends telemetry to Azure Application Insights, a monitoring service in Azure. There are two independent destinations, and the difference matters.
| Destination | Configured where | Receives | Typical owner |
|---|---|---|---|
| Environment telemetry | Business Central admin center, environment details, Application Insights connection string | Signals from everything in that environment: base application, Microsoft apps, all extensions | The customer, or the partner on the customer's behalf |
| App telemetry | The extension's app.json, applicationInsightsConnectionString | Signals related to that app only, in every environment where it is installed | The app publisher |
For Corbel & Finch, Noor created an Application Insights resource in the company's Azure subscription and entered its connection string on each environment in the admin center: PROD, CONFIG, TRAINING and UPDATE-TEST, each recorded with an environment name in the signals so queries can separate them. Separately, the CF Roastery extension's app.json carries the connection string of Quarrystone's own resource, so Quarrystone sees how its code behaves for this customer, and would see the same for any other customer running its apps. A Marketplace app does exactly the same at larger scale: one publisher resource, signals from every tenant.
What Business Central records
Telemetry signals arrive in Application Insights mostly in the traces table, each with a message and a set of custom dimensions such as the event ID, environment, company, extension, object and duration. Every signal type has an event ID, and learning the common ones saves a lot of searching.
| Event ID | Signal | Useful for |
|---|---|---|
| RT0005 | Operation exceeded time threshold (SQL query) | Slow database calls and the AL stack that made them |
| RT0018 | Operation exceeded time threshold (AL method) | Slow AL code, with a call stack |
| RT0012 | Database lock timed out | Lock conflicts between sessions |
| RT0008 | Incoming web service call | API and OData traffic, status codes, durations |
| RT0019 | Outgoing web service call | Calls from AL to external services |
| RT0030 | Error dialog displayed | Errors users see, with the message |
| LC0010 to LC0023 | Extension lifecycle: installed, failed to install, compiled, updated, failed to update | Deployment and upgrade problems |
| AL0000E24 to AL0000E26, AL0000HE7 | Job queue entry enqueued, started, finished, errored | Background jobs |
| CL0001 | Page opened | Usage of pages |
Signals are queried with Kusto Query Language (KQL) in Application Insights, or through Microsoft's Power BI apps and troubleshooting notebooks built on the same data. A query filters by event ID and time, projects the dimensions of interest and summarizes.
traces
| where timestamp > ago(7d)
| where customDimensions.eventId == "RT0019"
| where customDimensions.environmentName == "CONFIG"
| extend endpoint = tostring(customDimensions.endpoint),
status = tostring(customDimensions.httpStatusCode),
ms = totimespan(customDimensions.serverExecutionTime) / 1ms
| summarize calls = count(), avgMs = avg(ms), p95Ms = percentile(ms, 95) by endpoint, status
| order by p95Ms descCase 1: the slow rate quote
The RT0019 query showed the Tidewell rates endpoint with an average of 900 milliseconds but a 95th percentile of 14 seconds. Noor added a custom dimension to the extension's own telemetry with the first character of the destination postal code, and the pattern was clear: rates for remote northern areas were slow, because Tidewell priced them through a partner carrier. The fix was not in Business Central at all. Noor set the client timeout to 20 seconds, added a message telling users that remote rates can take longer, and cached each quote on the sales order for an hour, so reopening the order did not ask again.
Custom telemetry
Platform signals show what the platform sees. An extension adds its own events with Session.LogMessage, which takes an event ID, a message, a verbosity, a data classification, a TelemetryScope and a dictionary of custom dimensions. TelemetryScope::ExtensionPublisher sends the event only to the app's own resource; TelemetryScope::All sends it to the environment's resource as well, so the customer can see it. Only signals classified as SystemMetadata are emitted, which is a safety rail: customer data in a message is not sent. Event IDs are the developer's choice; a short app prefix keeps them unique, such as CFR0001.
local procedure LogRateQuote(PostalPrefix: Text[1]; DurationMs: Integer; Success: Boolean)
var
Dimensions: Dictionary of [Text, Text];
begin
Dimensions.Add('postalPrefix', PostalPrefix);
Dimensions.Add('durationMs', Format(DurationMs));
Dimensions.Add('success', Format(Success));
Session.LogMessage('CFR0001', 'Tidewell rate quote completed', Verbosity::Normal,
DataClassification::SystemMetadata, TelemetryScope::All, Dimensions);
end;The System Application also provides a Feature Telemetry codeunit with methods for logging that a feature was used, that it failed, or that a customer set it up, which gives consistent feature-usage reporting without writing raw LogMessage calls for each. Noor logged each café transfer draft as a feature use, and each accepted proposal separately, so that after go-live Bettina could see how often managers kept the Copilot proposal unchanged.
Case 2: the slow page
For the transfer draft page, the RT0018 signal showed the page's OnOpenPage trigger taking about four seconds, and RT0005 signals below it pointed at a loop over the café's 27 stockkeeping units, each reading the full Item record and calculating inventory one item at a time. Noor used the in-client performance profiler in CONFIG, which records a session and shows time spent per method and object, to confirm the hot spot. Three changes brought the page to under half a second.
| Problem | Change | Why it helps |
|---|---|---|
| Each Item read loaded every field, including table extension fields | SetLoadFields with only No., Description and Base Unit of Measure | Partial records read fewer columns and skip extension tables not needed |
| Inventory calculated item by item with CalcFields in a loop | A query object that sums item ledger entry quantity by item for the location in one statement | One database call instead of 27 |
| Maximum quantities read from SKUs in a second loop | Joined into the same query | Fewer round trips |
Performance patterns for AL
Most slow extensions share a handful of causes, and the remedies are routine. Partial records: call SetLoadFields before reading, so only the fields the code uses are loaded; this matters more with table extensions, whose fields live in companion tables that otherwise need joining. Set-based operations: use ModifyAll, DeleteAll, CalcSums and query objects instead of loops where possible. FlowFields: calculate them only when needed, and use SetAutoCalcFields before a loop rather than CalcFields inside it. Keys: filter and sort on fields that are covered by a key, and add keys in table extensions for frequent filters, remembering that every extra index slows inserts. Counting: use IsEmpty to test existence rather than Count.
Two features move work off the user's path. Page background tasks calculate values for a page part, such as cues on a role center, in a separate read-only session, so the page opens at once and the numbers appear a moment later. Job queue entries run heavy processing, such as the Tidewell booking queue from lesson 3, in the background on a schedule.
Read Scale-Out
Business Central online keeps a read-only replica of each production database. Read Scale-Out sends work that only reads to the replica, leaving the primary database for users who are posting. Objects opt in with DataAccessIntent = ReadOnly, available on reports, API pages, API queries and queries; for reports and queries it is often the default for new objects. A read-only object cannot write, and the replica can lag the primary by a short time, so it suits reporting and integrations that read, not screens where a user expects to see what they just posted. Noor set ReadOnly on the coffee availability API and the sales-by-line API query from lesson 1, so the web shop's polling and Bettina's Power BI refresh no longer compete with posting.
Case 3: the lock timeouts
The web shop import failures were RT0012 signals at about 2:00 a.m., which matched the nightly Adjust Cost - Item Entries job set up in MSBA-351. Both processes touched item ledger and value entries, and the import waited for locks held by cost adjustment until it timed out. Noor checked the job queue signals, confirmed the overlap, and moved the import to 1:15 a.m., finishing well before cost adjustment starts. She also shortened the import's transactions by committing after each order, so one long batch never holds locks for minutes, and set the job queue entry to retry on failure. In AL, the ReadIsolation property on a record lets reads choose an isolation level explicitly, and avoiding unnecessary LockTable calls keeps transactions short; both reduce contention in busy companies.
Load testing
Tests in lesson 5 prove correctness; the Business Central Performance Toolkit measures speed under load. It runs scenarios written in AL, such as "create and post a sales order", as many simulated users in parallel, and reports durations and SQL statement counts. Noor wrote a scenario that drafts and accepts a café transfer, and ran it with twenty users in a sandbox, far more than Corbel & Finch will ever have at once, to confirm the page and the validation code scale. In AL-Go, performance toolkit tests can be part of the pipeline and compared between builds, so a change that doubles the SQL calls per scenario is noticed before release.
Worked problem
Writing the first query of the morning
After go-live, Callum wants one query to check each morning that nothing broke overnight. What should it cover?
Show solution
- Job queue entries that errored in the last 24 hours (AL0000HE7), with the object and error message.
- Error dialogs users saw (RT0030) grouped by message, to spot new or frequent errors.
- Incoming API calls (RT0008) with status codes of 400 and above, by endpoint, to catch web shop failures.
- Outgoing calls (RT0019) to Tidewell with failures, by status code.
- Extension update failures (LC0023), which matter during update windows.
Answer: A morning query over job queue errors, user errors, failed incoming and outgoing calls and extension update failures covers most overnight problems in one place.
Alerts instead of dashboards
Nobody watches a dashboard at 3 a.m. Application Insights supports alert rules that run a query on a schedule and notify people when the result crosses a threshold. Noor set up three for PROD, to take effect at go-live: more than five errored job queue entries in an hour; any failed extension update during an update window; and more than ten failed web shop API calls in fifteen minutes. Each alert sends an email to the shared roastery-systems mailbox and to Quarrystone's support desk, and each has a short note explaining what to check first. Alerts that fire too often get tuned rather than ignored, because an ignored alert is worse than none.
Telemetry costs and retention
Application Insights charges by the volume of data ingested and keeps it for a set retention period. A busy environment can send a lot of signals, especially page views and verbose custom events. Noor reviewed the first two weeks of CONFIG data, kept the default retention, and set a daily ingestion cap with a warning, so that a runaway loop of custom events could not produce a surprise bill. Custom events use Verbosity::Normal for business milestones and Verbosity::Verbose only for detail that is switched on while investigating. Bettina asked who could see the data; the answer was the people given access to the Azure resource, which Noor limited to herself, Callum and Quarrystone's support desk.
| Question | Signal | Owner |
|---|---|---|
| Did overnight jobs run? | Job queue lifecycle events | Callum, each morning |
| Is the web shop integration healthy? | Incoming calls by status code | Callum and Quarrystone |
| Is Tidewell slow or failing? | Outgoing calls and the custom rate event | Quarrystone |
| Did the update succeed? | Extension lifecycle events | Quarrystone during update windows |
| Is the Copilot feature used? | Feature telemetry | Bettina, monthly |
Common mistakes
MistakeAssuming app telemetry shows everything in the customer's environment.
InsteadApp telemetry covers only the app; environment telemetry is set in the admin center.
MistakeLogging customer data in custom telemetry.
InsteadUse SystemMetadata classification and leave names, addresses and amounts out.
MistakeCalling CalcFields inside a loop over many records.
InsteadUse SetAutoCalcFields, CalcSums or a query.
MistakeReading full records when two fields are needed.
InsteadCall SetLoadFields first.
MistakeUsing Read Scale-Out on a page where users expect to see what they just posted.
InsteadUse ReadOnly intent for reporting and integration reads that tolerate a short lag.
Summary and key terms
- Environment telemetry is configured in the admin center; app telemetry is configured in app.json.
- Signals land in Application Insights with event IDs such as RT0005, RT0018, RT0012, RT0008, RT0019 and RT0030, queried with KQL.
- Session.LogMessage emits custom events; TelemetryScope decides whether the environment resource also receives them.
- The performance profiler finds hot spots; SetLoadFields, set-based operations and queries fix most of them.
- Read Scale-Out sends read-only work to a replica through DataAccessIntent = ReadOnly.
- The Performance Toolkit measures scenarios under load.
- Application Insights
- The Azure monitoring service that receives Business Central telemetry.
- Event ID
- The code that identifies a telemetry signal type, such as RT0005.
- KQL
- Kusto Query Language, used to query telemetry.
- TelemetryScope
- The parameter that sends a custom event to the publisher only or to all resources.
- Partial record
- A record loaded with only selected fields through SetLoadFields.
- Read Scale-Out
- Routing read-only work to a read-only database replica.
- Page background task
- Work for a page done in a separate read-only session so the page opens quickly.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Where would Corbel & Finch see signals from a Microsoft app in PROD?
Show answer
In the environment telemetry resource configured in the admin center, not in Quarrystone's app resource.
Which event ID pointed to the import failures, and what caused them?
Show answer
RT0012, lock timeouts caused by overlap with the nightly cost adjustment job.
Why is customer data safe from custom telemetry calls?
Show answer
Only events classified as SystemMetadata are emitted.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.