Register a Telemetry Logger in this app

Properties
AC0034 Hidden Design Code Fix Ignore Obsolete

Enable this rule when you want every app to carry its own Telemetry Logger, regardless of which other apps from your publisher are installed.

Codeunit Telemetry and Codeunit "Feature Telemetry" do not call Session.LogMessage for the calling app. On every call they look up the "Telemetry Logger" registered for the calling app’s publisher and hand the message to it. A logger is registered by a subscriber to the OnRegisterTelemetryLogger event of Codeunit "Telemetry Loggers". The event is raised on every telemetry call, and any installed app from the same publisher can register the logger. It does not have to be a dependency of the calling app. The first registration for a publisher wins.

Every publisher needs to have an implementation of the “Telemetry Logger” interface and a subscriber to “Telemetry Loggers”.OnRegisterTelemetryLogger event in one of their apps in order for this codeunit to work as expected

— Codeunit Telemetry on Microsoft Learn

The logger runs Session.LogMessage inside its own app, so the applicationInsightsConnectionString of the logger app receives the event. The calling app is visible only in the CallerAppName custom dimension. When no logger is registered for the publisher, "Telemetry Loggers Impl." logs warning 0000G7K and discards the message:

An app from publisher %1 is sending telemetry, but there is no registered telemetry logger for this publisher.

— NoPublisherErr label in "Telemetry Loggers Impl." in the System Application

With the rule enabled, each app that uses the telemetry codeunits implements "Telemetry Logger" and registers it in an OnRegisterTelemetryLogger subscriber, so its telemetry does not depend on a logger in another app. A logger in every app is safe: since BC 25.0 a second registration for the same publisher is ignored without a warning, and no message is dropped.

BC 25.0 removed the duplicate-logger warning 0000G7J. Older community posts that quote it describe behaviour before BC 25.0.

Example

codeunit 50101 "Sales Order Telemetry" // Register a Telemetry Logger in this app [AC0034]
{
    procedure LogOrderReleased()
    var
        FeatureTelemetry: Codeunit "Feature Telemetry";
    begin
        FeatureTelemetry.LogUsage('0000ABC', 'Sales Order Release', 'Sales order released');
    end;
}

"Sales Order Telemetry" stays as it is. Add a codeunit that implements "Telemetry Logger" and registers itself:

codeunit 50111 "App Telemetry Logger" implements "Telemetry Logger"
{
    Access = Internal;

    procedure LogMessage(EventId: Text; Message: Text; Verbosity: Verbosity; DataClassification: DataClassification; TelemetryScope: TelemetryScope; CustomDimensions: Dictionary of [Text, Text])
    begin
        Session.LogMessage(EventId, Message, Verbosity, DataClassification, TelemetryScope, CustomDimensions);
    end;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Telemetry Loggers", 'OnRegisterTelemetryLogger', '', true, true)]
    local procedure OnRegisterTelemetryLogger(var Sender: Codeunit "Telemetry Loggers")
    var
        TelemetryLogger: Codeunit "App Telemetry Logger";
    begin
        Sender.Register(TelemetryLogger);
    end;
}

AC0034 only checks that the app contains an implementation. It does not check that the implementation is registered.

When the diagnostic is reported

  • An object declares a global variable, local variable, parameter or return value of type Codeunit Telemetry or Codeunit "Feature Telemetry". Locals in triggers of fields, actions, controls, report data items and XMLport elements count.
  • No codeunit in the same app implements "Telemetry Logger".
  • The telemetry codeunits are matched on both their ID (8711 for Telemetry, 8703 for "Feature Telemetry") and their name.
  • One diagnostic is reported per object, on the object name, regardless of how many telemetry variables the object declares.

Exception

Test codeunits (Subtype = Test or TestRunner) and obsolete objects are not reported.

Why the rule is disabled by default

Microsoft documents one logger per app publisher, and that logger can live in any installed app from the publisher, such as a shared foundation app. Microsoft Learn describes this as “exactly one implementation of the “Telemetry Logger” interface registered per app publisher”. The Base Application uses the telemetry codeunits in many files and implements no logger of its own. AC0034 counts only codeunits in the app being compiled, so it does not see a logger in another app and would report every app that relies on a shared one. Leave the rule off in that topology.

Enable the rule

Add AC0034 to your project’s ruleset file. Use Info to show it as a suggestion, or Warning to make it stand out:

{
    "id": "AC0034",
    "action": "Warning",
    "justification": "Each app carries its own Telemetry Logger"
}

AC0033 applies the same check to Codeunit "Rest Client" and "Http Client Handler".

See also