Exercise - Diagnose an instrumented extension
In this exercise, you create a small extension, run successful and failed operations in a sandbox, and correlate their telemetry. You finish with an investigation record that separates observed evidence from your diagnosis.
Prepare the sandbox and AL project
You need the resources and permissions listed in the module prerequisites. Use a nonproduction Business Central online sandbox.
The 40-minute exercise estimate assumes that the prerequisite resources and permissions are ready. Provisioning, environment restarts, and variable telemetry-ingestion delays can add elapsed time.
Important
Use only an approved resource and sandbox. Before changing telemetry settings, coordinate the change and any restart with the administrator, and securely record the previous environment setting so you can restore it. Confirm Azure query access, ingestion costs, and the agreed retention policy. Record configuration confirmation, not actual connection-string values, in the investigation report.
In the Business Central admin center, open the sandbox environment and add the supplied full connection string to its Application Insights telemetry configuration. Save the change and allow the environment restart to finish if Business Central schedules one.
In Visual Studio Code with the AL Language extension, run AL: Go! and connect the new exercise project to the sandbox. Verify that the
platform,application, andruntimevalues inapp.jsonare compatible with that sandbox. Generated defaults aren't a guarantee of compatibility.In
app.json, merge the following object range and extension-publisher connection-string properties into the manifest. Preserve the project's unique app ID, name, publisher, version, other settings, and sandbox-compatible version fields. Don't replace the entire manifest with this fragment:{ "idRanges": [ { "from": 71100, "to": 71149 } ], "applicationInsightsConnectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://westus2-0.in.applicationinsights.azure.com/" }
Replace the nonworking example connection-string value with the full supplied value. Confirm that object range 71100-71149 is available in your sandbox. Remove only the generated Hello World sample from this new exercise project if its object ID is outside that range; don't remove existing application objects. The project needs no external starter files or dependencies beyond the application symbols. Run AL: Download Symbols against the target sandbox if the compatible symbols aren't already available.
Keep real connection strings in authorized local or deployment configuration rather than shared training assets or investigation reports. The published examples intentionally retain the nonworking zero-GUID value.
Build the instrumented operation
Create TelemetrySample.Codeunit.al with the following code. The public procedure creates one GUID for the execution and emits started, succeeded, or failed events. The fixed failure category avoids customer data and raw error text.
codeunit 71100 "Telemetry Sample Operation"
{
procedure Run(ShouldFail: Boolean): Guid
var
OperationId: Guid;
CustomDimensions: Dictionary of [Text, Text];
begin
OperationId := CreateGuid();
AddBaseDimensions(CustomDimensions, OperationId, 'Started');
LogEvent('MTE001', 'Telemetry sample operation started.', CustomDimensions);
if TryRun(ShouldFail) then begin
CustomDimensions.Set('Result', 'Succeeded');
LogEvent('MTE002', 'Telemetry sample operation succeeded.', CustomDimensions);
end else begin
CustomDimensions.Set('Result', 'Failed');
CustomDimensions.Add('FailureReason', 'SimulatedFailure');
LogEvent('MTE003', 'Telemetry sample operation failed.', CustomDimensions);
end;
exit(OperationId);
end;
local procedure AddBaseDimensions(var CustomDimensions: Dictionary of [Text, Text]; OperationId: Guid; Result: Text)
begin
CustomDimensions.Add('OperationId', Format(OperationId));
CustomDimensions.Add('Result', Result);
end;
local procedure LogEvent(EventId: Text; EventMessage: Text; CustomDimensions: Dictionary of [Text, Text])
begin
Session.LogMessage(
EventId,
EventMessage,
Verbosity::Normal,
DataClassification::SystemMetadata,
TelemetryScope::ExtensionPublisher,
CustomDimensions);
end;
[TryFunction]
local procedure TryRun(ShouldFail: Boolean)
begin
if ShouldFail then
Error(SimulatedFailureErr);
end;
var
SimulatedFailureErr: Label 'The simulated operation failed.';
}
Create TelemetrySample.Page.al to provide two sandbox actions. The messages display the operation GUID, which helps you locate the matching traces without exposing business data.
page 71101 "Telemetry Sample"
{
PageType = Card;
ApplicationArea = All;
UsageCategory = Administration;
Caption = 'Telemetry Sample';
layout
{
area(Content)
{
group(Instructions)
{
Caption = 'Run sample operations';
field(Guidance; GuidanceTxt)
{
ApplicationArea = All;
Caption = 'Guidance';
Editable = false;
}
}
}
}
actions
{
area(Processing)
{
action(RunSuccess)
{
ApplicationArea = All;
Caption = 'Run successful operation';
Image = Start;
trigger OnAction()
var
SampleOperation: Codeunit "Telemetry Sample Operation";
OperationId: Guid;
begin
OperationId := SampleOperation.Run(false);
Message(OperationCompletedMsg, 'succeeded', OperationId);
end;
}
action(RunFailure)
{
ApplicationArea = All;
Caption = 'Run failed operation';
Image = Error;
trigger OnAction()
var
SampleOperation: Codeunit "Telemetry Sample Operation";
OperationId: Guid;
begin
OperationId := SampleOperation.Run(true);
Message(OperationCompletedMsg, 'failed', OperationId);
end;
}
}
}
var
GuidanceTxt: Label 'Run each action, record its operation ID, and query Application Insights.';
OperationCompletedMsg: Label 'The operation %1. Operation ID: %2';
}
The code uses DataClassification::SystemMetadata, PascalCase source keys, app-prefixed event IDs, and TelemetryScope::ExtensionPublisher. The emitted fields appear as ALMTE001 through ALMTE003 and alOperationId, alResult, and alFailureReason.
These custom events use publisher-only scope. Finding them in a resource shared with environment telemetry verifies their publisher path, not environment-level routing independently. Separately confirm the environment setting in the admin center and, with the administrator, verify receipt of an applicable documented environment-level signal. If that evidence isn't available, record the environment-ingestion check as outstanding.
Publish and generate both outcomes
Download symbols if the project doesn't already contain them, then build the project with AL: Package.
Publish the extension to the sandbox with AL: Publish. Resolve compile errors before you continue.
In the Business Central web client, search for Telemetry Sample and open the page.
Select Run successful operation and record the displayed operation ID and local time.
Select Run failed operation and record its operation ID and local time.
Wait for Application Insights ingestion, then set the Logs time range to include both actions.
The try method handles the simulated failure, so the page action completes and calls Session.LogMessage for the failed outcome. This call isn't a database commit or a guarantee of telemetry delivery. Verify receipt in Application Insights rather than assuming that a completed action proves ingestion. Both paths avoid customer-sensitive values.
Correlate the events and record a diagnosis
Run this query in the Application Insights Logs experience:
traces
| extend EventId = tostring(customDimensions.eventId),
ExtensionName = tostring(customDimensions.extensionName),
EnvironmentName = tostring(customDimensions.environmentName),
EnvironmentType = tostring(customDimensions.environmentType),
OperationId = tostring(customDimensions.alOperationId),
Result = tostring(customDimensions.alResult),
FailureReason = tostring(customDimensions.alFailureReason)
| where EventId in ("ALMTE001", "ALMTE002", "ALMTE003")
| project timestamp, EventId, ExtensionName, EnvironmentName,
EnvironmentType, OperationId, Result, FailureReason, message
| order by OperationId asc, timestamp asc
Filter the results to the two exact operation GUIDs you recorded, and verify ExtensionName, EnvironmentName, and EnvironmentType against the intended app and sandbox. Preserve the final filters and UTC time range in your investigation record.
Confirm that each recorded GUID has two rows. The successful GUID has Started and Succeeded results. The failed GUID has Started and Failed results, with SimulatedFailure as the failure reason. Timestamps are UTC, so compare them with your recorded local time by applying the correct offset.
Two rows per operation is the expected result for this controlled sample, not a delivery guarantee. If rows are missing or duplicated, investigate the time range, destination, installed extension, ingestion delay, sampling, and duplicates before drawing a conclusion. Record discrepancies rather than inventing or discarding evidence to match the expectation. Started and terminal events can share a timestamp; use the event IDs and result contract to identify their roles, not display order alone.
Create an investigation record with these fields:
| Field | Evidence to record |
|---|---|
| Configuration | Sandbox name, extension version, telemetry scope, and confirmation that full connection strings are configured |
| Query | Final KQL and UTC time range |
| Correlation | Successful and failed operation GUIDs with their ordered event IDs |
| Diagnosis | The observed result and failure category, stated separately from assumptions |
| Recommendation | One justified code, configuration, or alerting action |
For this controlled case, a defensible diagnosis states that the failed operation reaches the explicit simulated failure path. A defensible recommendation keeps the correlation pattern and replaces the simulation with bounded failure categories for real operation branches. An alert isn't justified by one expected test failure, but a sustained increase in unexpected failed terminal events can justify one.