From bc45439b53436dfe63afddf3ef9636edf44dca97 Mon Sep 17 00:00:00 2001 From: Arend-Jan Kauffmann Date: Fri, 25 Feb 2022 23:13:54 +0100 Subject: [PATCH 1/2] Add guideline CustomTelemetry --- .../BestPractices/CustomTelemetry/index.md | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 content/docs/BestPractices/CustomTelemetry/index.md diff --git a/content/docs/BestPractices/CustomTelemetry/index.md b/content/docs/BestPractices/CustomTelemetry/index.md new file mode 100644 index 00000000..18ade1f0 --- /dev/null +++ b/content/docs/BestPractices/CustomTelemetry/index.md @@ -0,0 +1,89 @@ +--- +title: "Custom Telemetry" +tags: ["AL","Telemetry"] +categories: ["Best Practice"] +--- + +_Created by Microsoft, Described by Arend-Jan Kauffmann_ + +## Description +With AL it is possible to emit custom telemetry signals to Azure Application Insights. There are a number of considerations that you should keep in mind when designing custom telemetry signals. + +- Think about it as an API +- Naming conventions and telemetry schema +- Candidate data for telemetry +- How customers use telemetry +- Privacy + +## Think about it as an API + +Customers will build analytics and monitoring solutions on top of their telemetry data. + +Therefore, signal must be treated as any other API + +- documented +- versioned +- discoverable +- non-breaking + +## Naming conventions and telemetry schema + +To make it easy for the consumer of telemetry to work with the data, please + +- use CamelCasing. This makes all fields in Application Insights look the same (signal logged through the AL LogMessage method will have "al" prefixed to dimension names. +- never use fields/custom dimension keys with spaces or special characters. This makes the KQL queries so much easier to write +- for custom dimensions, consider using prefixes that helps the telemetry consumer understand where the dimension is coming from (e.g. HttpStatusCode, SqlStatement, ...) + +Consider always having a "message" field that expresses in human readable form what the telemetry event is about. +If you do, let message names follow the Object ActionInPastTense pattern +Some examples + +- Web Service Called: +- Email attempt failed +- Authorization to environment succeeded + +```al +local procedure ProcessHttpResponse(var Request: HttpRequestMessage; var Response: HttpResponseMessage) +var + CustomTelemetryDimensions: Dictionary of [Text,Text]; +begin + if Response.HttpStatusCode <> 200 then begin + CustomTelemetryDimensions.Add('Url', Request.GetRequestUri); + CustomTelemetryDimensions.Add('HttpStatusCode', Format(Response.HttpStatusCode)); + CustomTelemetryDimensions.Add('ReasonPhrase', Response.ReasonPhrase); + Session.LogMessage( + 'MyExt0001', + 'Web service call failed', + Verbosity::Error, + DataClassification::SystemMetadata, + TelemetryScope::ExtensionPublisher, + CustomTelemetryDimensions); + end; +end; +``` + +## Candidate data for telemetry + +Telemetry must be actionable for the customer. Do not emit signals that they cannot act on (knowing about CPU performance counters on the database is useless if the partner cannot scale the database) + +Also, note that customers pay for data ingestion. So be mindful to not flood their telemetry resources. Consider to use TelemetryScope::ExtensionPublisher by default and only use TelemetryScope::All in case the customer can also act on the data. + +If you do not know where to start, consider using telemetry for deflection. In Dynamics 365 Business Central, they started with signal about authorization (successful/failed) to deflect support cases that was due to disabled users/wrong licenses. + +## How customers use telemetry + +The following are known scenarios for customer telemetry + +- The tenant admin (typically an IT-pro) wants to troubleshoot a performance problem and they need more details than what is provided in the analytics reports in the admin center. +- The customer wants to analyze (and correct) errors happening in the environment (typically an IT-pro) +- The customer wants to analyze usage of features (typically an analytics user, maybe with BI experience) + +Customers typically start in the Application Insights portal and then move on to use more advanced tools for analytics (KQL, Power BI, Excel, ...). Once they have seen the light, they will likely start alerting on telemetry using Azure Monitor Alerts or setting up Power Automate flows. + +Business Central have developed a telemetry maturity model (based on the Gartner BI maturity model) for how organizations can evolve to use telemetry proactively in their business processes. + +## Privacy + +Telemetry must be privacy compliant. + +For privacy reasons, events that have a DataClassification other than SystemMetadata aren't sent to Application Insight resources set up on the tenant. During development of your extension, it's good practice to have a privacy review of the use of LOGMESSAGE calls to ensure that customer data isn't mistakenly leaked into Application Insights resources. \ No newline at end of file From fb6a07a1ee81365774b58ceb71c259f04ae37a1b Mon Sep 17 00:00:00 2001 From: Arend-Jan Kauffmann Date: Sat, 26 Feb 2022 17:05:49 +0100 Subject: [PATCH 2/2] Resolve comments + extra chapter --- content/docs/BestPractices/CustomTelemetry/index.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/content/docs/BestPractices/CustomTelemetry/index.md b/content/docs/BestPractices/CustomTelemetry/index.md index 18ade1f0..d3a04574 100644 --- a/content/docs/BestPractices/CustomTelemetry/index.md +++ b/content/docs/BestPractices/CustomTelemetry/index.md @@ -11,6 +11,7 @@ With AL it is possible to emit custom telemetry signals to Azure Application Ins - Think about it as an API - Naming conventions and telemetry schema +- Objects emitting telemetry signals - Candidate data for telemetry - How customers use telemetry - Privacy @@ -30,7 +31,7 @@ Therefore, signal must be treated as any other API To make it easy for the consumer of telemetry to work with the data, please -- use CamelCasing. This makes all fields in Application Insights look the same (signal logged through the AL LogMessage method will have "al" prefixed to dimension names. +- use PascalCasing. This makes all fields in Application Insights look the same (signal logged through the AL LogMessage method will have "al" prefixed to dimension names. - never use fields/custom dimension keys with spaces or special characters. This makes the KQL queries so much easier to write - for custom dimensions, consider using prefixes that helps the telemetry consumer understand where the dimension is coming from (e.g. HttpStatusCode, SqlStatement, ...) @@ -62,6 +63,12 @@ begin end; ``` +## Objects emitting telemetry signals + +Telemetry data includes information about the object that emitted the telemetry signal. It's recommended to call Session.LogMessage() from within the object that causes a situation that you want to have telemetry for. That will make it easier to analyze where exactly in the code an issue occurred. + +Of course it is possible to have a single object as a central place to emit telemetry signals. The telemetry data includes a callstack, so eventually it would be possible to trace back to the exact place where an issue occurred. But that requires a more complicated query, so it would be better to emit telemetry signals right from place in the code where an issue occurred. + ## Candidate data for telemetry Telemetry must be actionable for the customer. Do not emit signals that they cannot act on (knowing about CPU performance counters on the database is useless if the partner cannot scale the database)