Dynamics 365 Business Central telemetries for Azure Functions

In my Azure Functions session at latest BC TechDays in Belgium I spent some minutes showing the Azure Functions module in the System Application and how you can use it for calling Azure Functions from AL code in an easy way.

Here is one of the example I used in the demo, where from an action in the Customer Card page I’m calling an Azure Functions from AL code for generating a QR Code containing some details of the customer record. With the Azure Functions module of the System Application you can do like in the following code:

I talked also about the importance of using telemetry in Azure Functions for traceability and diagnostics. I recommend to connect the Azure Functions to an Azure Application Insights instance (see this post for more) and also I recommend to inject custom telemetry signals from your Azure Function code in order to have telemetry details saves in the CustomEvents table of your Azure Application Insights instance:

A question I received after the session was: is there the possibility to have telemetry signals in Application Insights from the Azure Function module of the System Application directly?

The answer is: YES!

The Azure Function module sends telemetry data to the Application Insights instance connected to your tenant about the success or failure of calls from Business Central to your Azure Functions. You can find more details about that here.

For monitoring Azure Functions you have the following signals (eventId):

  • AL0000I74: Request sent to Azure function succeeded
  • AL0000I7P: Request sent to Azure function failed
  • AL0000I75: Authorization failed to Azure function

As an example, here is a KQL query giving the Azure Functions requests succeeded in the last day (with the details of the endpoint called):

traces
| where timestamp > ago(1d)
| where customDimensions.eventId == 'AL0000I74' //Request succeeded
| project timestamp
, message
, aadTenantId = customDimensions.aadTenantId
, environmentName = customDimensions.environmentName
, environmentType = customDimensions.environmentType
, companyName = customDimensions.companyName
, requestStatusCode = customDimensions.alStatusCode
, functionHost = customDimensions.alFunctionHost
, eventName = customDimensions.alEventName
, statusCode = customDimensions.alStatusCode

I personally also love to see the time chart of the Azure Functions call (just to quickly discover spikes on calls or anomalies):

traces
| where timestamp > ago(1d)
| where customDimensions.eventId == 'AL0000I74'
| render timechart 

For troubleshooting possible authentication problems when calling Azure Functions from AL (like secret expired, wrong function key or similar), remember that the signal AL0000I75 (Authorization failed) contains the alErrorText parameter that gives you the reason of the failure:

traces
| where timestamp > ago(1d)
| where customDimensions.eventId == 'AL0000I75'  //Authorization failed
| project timestamp
, aadTenantId = customDimensions.aadTenantId
, environmentName = customDimensions.environmentName
, environmentType = customDimensions.environmentType
, companyName = customDimensions.companyName
, errorText = customDimensions.alErrorText
, functionHost = customDimensions.alFunctionHost

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.