MSBA-343 · Lesson 11 of 12 · 19 min

Monitoring and telemetry

▶ Video coming soon A video version of this lesson is on the way.

The last checklist line before the capstone was monitoring in production. Everything so far had been about finding problems before go-live. Desmond pointed out that some problems would only appear afterwards, with a hundred and twenty real users, real volumes and real month-ends. The question for this clinic was how Cobalt Ridge would know about them before the users rang Kiri, and how a developer would get from a symptom to a cause without access to the production database.

Three sources of evidence

Desmond grouped production evidence into three sources. Platform monitoring comes from Microsoft's tools for the environment: environment monitoring and SQL insights in Lifecycle Services, or the monitoring in the Power Platform admin center after migration. It shows what the environment and its database are doing. Application telemetry is a stream of signals from the application itself, sent to Azure Application Insights, which shows what users and processes are doing over time. Business signals are the application's own records, such as batch job history, the alert queue and workflow history, which show whether business processes completed.

Prudence had already met platform monitoring in lesson 3, and business signals were familiar from MSBA-341's alert job. Application telemetry was new, and it took most of the session.

The finance and operations environment sends signals to an Azure Application Insights resource owned by Cobalt Ridge: page views for forms, batch job events, exceptions from Infolog errors, traces and custom events and metrics from CobaltRidgeCustom. Application Insights feeds queries, workbooks and alert rules, which notify the support team.
Telemetry flows from the environment to Cobalt Ridge's Application Insights resource, where queries and alerts use it.

Monitoring and telemetry with Application Insights

Finance and operations apps can send telemetry to an Azure Application Insights resource that the customer owns. Microsoft calls the capability monitoring and telemetry. It is turned on through Feature management, and an administrator then configures which Application Insights resource each environment sends to and which kinds of signal are sent. Once it is active, the system sends telemetry such as form page views, batch job activity, Infolog errors as exceptions and other signals Microsoft documents in its list of available telemetry. Because the data goes to the customer's own Azure subscription, Cobalt Ridge would control who could read it, how long it was kept and what it cost.

Kiri asked about cost directly. Application Insights is billed largely on the volume of data ingested and retained. Microsoft's documentation on understanding and controlling cost recommends enabling only the signals the team will use, setting retention deliberately, and watching the ingestion volume after each change. Desmond's plan was to start with errors, batch and a small set of custom signals in production, review the volume weekly in hypercare, and add form telemetry for specific investigations rather than leaving everything on.

Thandeka asked about privacy. Telemetry can carry user identifiers and, if developers are careless, business data. The plan was to keep Application Insights access to the support team, to set a retention period agreed with her, and to ban personal data and sensitive business values from custom telemetry properties. A serial number was acceptable; a customer's name was not.

Adding custom signals in X++

Standard telemetry shows what the platform knows. It does not know that a pump warranty was voided, or how many alerts the inspection job processed. For that, developers add custom signals. Microsoft's documentation describes the pattern. The class SysApplicationInsightsTelemetryLogger wraps the Application Insights client; it uses a static instance per session and caches the client per server instance. Each kind of signal has a data contract class: SysApplicationInsightsEventTelemetry for events, SysApplicationInsightsPageViewTelemetry for page views, SysApplicationInsightsExceptionTelemetry for exceptions and SysApplicationInsightsTraceTelemetry for traces. Code creates the contract, adds properties, and calls the logger's matching method: trackEvent, trackPageView, trackException or trackTrace. Metrics have no contract; code calls trackMetric, or trackMetricWithDimensions to add properties that let values be sliced.

Microsoft's samples guard each call with a check that telemetry is in use, SysApplicationInsightsTelemetryHelper::useSysApplicationInsightsTelemetryLogger, so that the code does nothing when the feature is not active. Prudence followed the same pattern.

A custom event when a warranty is voided. The legal entity property class and the custom serial number property class are illustrative; check the property classes available in your version and create custom ones by following Microsoft's pattern.
internal final class CRWarrantyTelemetry
{
    public static void warrantyVoided(CRPumpWarrantyTable _warranty)
    {
        if (!SysApplicationInsightsTelemetryHelper::useSysApplicationInsightsTelemetryLogger())
        {
            return;
        }

        SysApplicationInsightsEventTelemetry eventTelemetry =
            SysApplicationInsightsEventTelemetry::newFromEventIdName('CR001', 'PumpWarrantyVoided');
        eventTelemetry.addProperty(SysApplicationInsightsLegalEntityProperty::newFromValue(curExt()));
        eventTelemetry.addProperty(CRWarrantySerialProperty::newFromValue(_warranty.SerialNumber));

        SysApplicationInsightsTelemetryLogger::instance().trackEvent(eventTelemetry);
    }
}

Choosing what to send

Desmond asked Prudence to design the custom signals before writing any code, by asking what question each signal would answer. They agreed on a short list.

Custom signals in CobaltRidgeCustom.
SignalTypeQuestion it answers
PumpWarrantyVoidedEvent with legal entity and serial numberHow often are warranties voided, and by which company?
CRInspAlertsProcessedMetric with legal entity as a dimensionIs the alert job keeping up, or is the queue growing?
CRReceiptInspectionCheckMetric of duration in millisecondsIs the receipt check staying fast after the fixes?
CRInspectionWaiverRejectedEvent with legal entityAre waiver rejections rising for a supplier problem?
Unexpected errors in CobaltRidgeCustom servicesException with class and methodWhere do custom integrations fail?

Metrics suited the alert job and the receipt check. Microsoft's documentation explains that metrics are aggregated locally and sent at most about once a minute, which makes them cheap even when they are recorded thousands of times, and suitable for batch processing. Events suited things that happen rarely and matter individually, such as a void. Exceptions were already sent for Infolog errors by the standard SysApplicationInsightsGlobalTelemetry class, so custom exception telemetry was only needed for failures caught and handled in code, which would otherwise leave no trace.

Prudence put the telemetry calls in a small helper class, CRWarrantyTelemetry, and called it from the service classes, not from wrappers or forms. Keeping telemetry out of the business logic's way meant a failure to send telemetry could never block a business process, and keeping it in one class meant the event names and properties were defined in one place.

Querying telemetry

Telemetry in Application Insights is queried with the Kusto Query Language, KQL. Each signal type is stored in a table: page views, custom events, custom metrics, exceptions, traces. A query filters, summarizes and charts them. Desmond wrote three queries with Prudence and saved them in a workbook for the support team: voids per company per week, alerts processed per run against the queue size, and the ninety-fifth percentile duration of the receipt check per day.

A KQL query for the daily ninety-fifth percentile duration of the receipt inspection check. Column names follow Application Insights conventions; check the schema in your resource.
customMetrics
| where name == 'CRReceiptInspectionCheck'
| summarize p95 = percentile(value, 95), runs = count() by bin(timestamp, 1d)
| order by timestamp asc

The ninety-fifth percentile mattered more than the average. An average can look healthy while one receipt in twenty takes a minute, and that one receipt is the one a clerk complains about. Kiri liked the chart because it would show, after each release and each service update, whether the receipt check stayed fast without anyone needing to trace it.

Alerts

Telemetry nobody looks at is an expense, not a control. Application Insights supports alert rules that run a query on a schedule and notify someone when a condition is met. Desmond set up three: the alert queue had more than two thousand pending items for over an hour, which meant the job was not keeping up; the receipt check's ninety-fifth percentile exceeded two seconds on a day; and exceptions from CobaltRidgeCustom services exceeded ten in an hour. Each alert went to the support team's channel and named a runbook entry that said what to check first.

Prudence asked why the queue alert used an hour rather than firing immediately. Desmond explained that alerts that fire on every brief spike train people to ignore them. The job ran every fifteen minutes and processed at most five hundred alerts per run, as set in MSBA-341; a queue above two thousand for an hour meant four runs in a row had not caught up, which was worth a person's attention.

Batch jobs and business signals

Not every check needs Application Insights. The batch job history in the client shows when each job ran, how long it took and whether it ended in error. Workflow history shows stuck approvals. The alert queue table itself shows whether alerts are being processed. Desmond added a simple saved view on batch jobs filtered to Cobalt Ridge's jobs, and asked Annelise to add a daily look at it to the hypercare routine. He also set up the standard batch job alerts so that a failure of the alert job or the nightly cleanup notified the support team.

Platform monitoring in production

For problems at the level of the environment, such as database blocking or a sudden change in query performance, the support team would use the platform tools. In Lifecycle Services, environment monitoring shows activity and health, and SQL insights lists expensive queries and blocking. After migration to the Power Platform admin center, the equivalent monitoring would be found there. Desmond's runbook told the support team to start with telemetry, which showed what users experienced, and to move to platform monitoring when telemetry pointed at the database rather than at code.

From symptom to cause

Desmond finished with a rehearsal. He described a symptom from the second migration rehearsal as if it had happened in production: receiving clerks at the Calgary warehouse said receipts were slow on Monday mornings. Prudence worked through it with the tools. The receipt check metric showed a spike every Monday between eight and ten. The batch history showed the weekly casting certificate report running at the same time. SQL insights in UAT showed the report's query blocking inserts into the certificate table. The fix was not in the receipt code at all; the report was moved to Sunday night, and the next Monday's chart was flat. Prudence noted that the report's run time had been agreed in MSBA-341 for the Monday supplier quality meeting, which only needed it to be ready by nine.

Following one operation across signals

A single user action can produce several signals: a page view when the form opens, custom events from the service class, and perhaps an exception. Application Insights groups related telemetry with operation identifiers, so a query can show everything that happened during one operation. Desmond showed Prudence how to start from an exception in the support workbook and follow its operation identifier to the page view and the custom events around it. For batch jobs, which have no user page view, Prudence added a custom event at the start and end of each run of the alert job, with the batch job identifier as a property. A failed run could then be found in telemetry by the same identifier the support team saw in the batch job history.

A hypercare view

Kiri asked for one page the support team would open every morning during hypercare. Desmond built an Application Insights workbook with five tiles: Infolog errors per hour by legal entity, the slowest forms of the previous day by ninety-fifth percentile load time, batch jobs that ended in error, the alert queue processed and pending charts, and the receipt check duration. Each tile linked to the query behind it. The workbook was deliberately small. A dashboard with forty charts is one that nobody reads by the second week.

Separating environments

Telemetry from UAT and production must not mix, or a test run in UAT can trigger a production alert. Cobalt Ridge used separate Application Insights resources for sandboxes and production, and the refresh checklist from lesson 9 reset the connection after each sandbox refresh, because a refreshed sandbox inherits the configuration of the environment it was copied from.

Thandeka reviewed the telemetry design before it went live, as she had reviewed the security objects. She checked the list of custom properties against her rule on personal data, confirmed the retention period for the production resource and asked who could read it. Access was granted through an Azure group managed by Cobalt Ridge's administrator, with the partner's developers given read access only for the length of hypercare. She also asked that the support workbook not be shared outside that group, because even aggregated telemetry showed which customers' warranties had been voided and when.

Worked problem

Instrumenting the alert job

Kiri wants to know during hypercare whether the inspection alert job keeps up, without anyone opening the batch history every hour. What should Prudence add?

Show solution
  1. Add a metric, CRInspAlertsProcessed, recorded at the end of each run with the legal entity as a dimension.
  2. Add a second metric with the number of pending alerts left in the queue after the run.
  3. Guard both calls with the telemetry helper check and put them in the CRWarrantyTelemetry helper class.
  4. Write a KQL query that charts processed and pending alerts per run, and add it to the support workbook.
  5. Create an alert rule for pending alerts above two thousand for an hour, linked to a runbook entry.

Answer: Two cheap metrics, a saved query and one alert rule tell the support team whether the job keeps up, and wake someone only when it has not for an hour.

Common mistakes

  • MistakeTurning on every telemetry signal in production from day one.

    InsteadEnable what you will use, watch ingestion and add signals for specific needs.

  • MistakePutting customer names or other personal data in custom telemetry properties.

    InsteadUse identifiers such as serial numbers and keep personal data out.

  • MistakeUsing averages to judge user experience.

    InsteadUse percentiles such as the ninety-fifth to see slow cases.

  • MistakeCreating alerts that fire on every brief spike.

    InsteadUse thresholds and durations that mean a person should act, with a runbook step.

Summary and key terms

  • Production evidence comes from platform monitoring, application telemetry and business records such as batch history.
  • Monitoring and telemetry sends signals to the customer's Application Insights resource once the feature is active and configured.
  • SysApplicationInsightsTelemetryLogger sends custom events, page views, exceptions, traces and metrics through data contract classes.
  • Metrics are aggregated and sent about once a minute, which suits high-volume measurements such as batch processing.
  • KQL queries, workbooks and alert rules turn telemetry into action, with cost and privacy controlled by design.
Application Insights
An Azure service that collects and analyzes telemetry from applications.
Telemetry
Signals an application sends about its behaviour, such as events, metrics and errors.
SysApplicationInsightsTelemetryLogger
The X++ class that sends custom telemetry to Application Insights.
Kusto Query Language (KQL)
The query language used to analyze data in Application Insights.
Alert rule
A scheduled query that notifies people when a condition is met.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Which logger method sends a custom event?

    Show answer

    trackEvent.

  2. Why are metrics suitable for batch processing?

    Show answer

    They are aggregated locally and sent at most about once a minute.

  3. Which standard class already sends Infolog errors as exceptions?

    Show answer

    SysApplicationInsightsGlobalTelemetry.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz