Dynamics 365 Business Central: automate the telemetry setup.

Some days ago I was reading a summary made by Kennie about the Ask Me Anything (AMA) session on data-driven implementations session at last Directions EMEA.

The session abstract was the following: Let’s get together and discuss how we can use telemetry pro-actively in our project implementation lifecycle – from prospect meetings, during implementation, and before/after go-live.

I was quite surprised to see two topics listed on the asked questions:

  1. Is there a way to automate the deployment of Azure Application Insights with Dynamics 365 Business Central?
  2. Are telemetry costs per user?

Here is a quick post answering the above questions.

Automate the deployment of Application Insights telemetry configuration with Dynamics 365 Business Central

The short answer is YES: you can fully automate the telemetry configuration deployment on every Dynamics 365 Business Central tenant. What you need to do is:

  • Select an Azure subscription
  • Create a Resource Group
  • Create Log Analytics workspace
  • Create an Azure Application Insights instance on that workspace
  • Retrieve the Application Insights connection string
  • Set the data retention on the Application Insights instance
  • Set the daily Cap on the Application Insights instance
  • Connect to Dynamics 365 Business Central by using Admin Center APIs
  • Set the connection string to the Dynamics 365 Business Central environment

All these steps can be automated via Azure Powershell. Here is a complete script that I’m personally using (you can also download it from my Github here):

#Name of the Application Insights Resource
$appInsightsName = "YOURAPPLICATIONINSIGHTSNAME"

#Name of the Resource Group to use.
$resourceGroupName = "YOURRESOURCEGROUPNAME"

#Name of the workspave
$WorkspaceName = "YOURWORKSPACENAME"

#Azure location
$Location = "westeurope"

#Data retention for Application Insights (days)
$dataretentiondays = 30

#Daily Cap (GB) for Application Insights instance
$dailycap = 15

#Parameters for connecting to Dynamics 365 Business Central tenant
#Business Central tenant id
$aadTenantId = "TENANTID"     
#Name of the D365BC Environment
$D365BCenvironmentName = "YOURD365BCENVIRONMENTNAME"
#Partner's AAD app id
$aadAppId = "CLIENTID"        
#Partner's AAD app redirect URI
$aadAppRedirectUri = "nativeBusinessCentralClient://auth" 

Connect-AzAccount

New-AzResourceGroup -Name $resourceGroupName -Location $Location

New-AzOperationalInsightsWorkspace -Location $Location -Name $WorkspaceName -ResourceGroupName $resourceGroupName
$Resource = Get-AzOperationalInsightsWorkspace -Name $WorkspaceName -ResourceGroupName $resourceGroupName
$workspaceId = $Resource.ResourceId

New-AzApplicationInsights -ResourceGroupName $resourceGroupName -Name $appInsightsName -location $Location -WorkspaceResourceId $workspaceId
$Resource = Get-AzResource -ResourceType Microsoft.Insights/components -ResourceGroupName $resourceGroupName -ResourceName $appInsightsName
$connectionString = $resource.Properties.ConnectionString
Write-Host "Connection String = " $connectionString
#Set data retention
$Resource.Properties.RetentionInDays = $dataretentiondays
$Resource | Set-AzResource -Force
#Set daily cap (GB)
Set-AzApplicationInsightsDailyCap -ResourceGroupName $resourceGroupName -Name $appInsightsName -DailyCapGB $dailycap


# Load Microsoft.IdentityModel.Clients.ActiveDirectory.dll
Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\AzureAD\2.0.2.140\Microsoft.IdentityModel.Clients.ActiveDirectory.dll" # Install-Module AzureAD to get this


# Get access token
$ctx = [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext]::new("https://login.microsoftonline.com/$aadTenantId")
$redirectUri = New-Object -TypeName System.Uri -ArgumentList $aadAppRedirectUri
$platformParameters = New-Object -TypeName Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformParameters -ArgumentList ([Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior]::Always)
$accessToken = $ctx.AcquireTokenAsync("https://api.businesscentral.dynamics.com", $aadAppId, $redirectUri, $platformParameters).GetAwaiter().GetResult().AccessToken

Write-Host $accessToken

$response = Invoke-WebRequest `
    -Method Post `
    -Uri    "https://api.businesscentral.dynamics.com/admin/v2.11/applications/businesscentral/environments/$D365BCenvironmentName/settings/appinsightskey" `
    -Body   (@{
                 key = $connectionString
              } | ConvertTo-Json) `
    -Headers @{Authorization=("Bearer $accessToken")} `
    -ContentType "application/json"
Write-Host "Responded with: $($response.StatusCode) $($response.StatusDescription)"

What about telemetry costs?

I wrote in the past about this topic (for example here). Telemetry costs are are not billed per Dynamics 365 Business Central users but you pay for the amount of ingested data and for the retention of data you have.

Costs should not be a problem for everyone seriously handling a Business Central tenant. Telemetry is a must to activate and costs are absolutely something that customers and partners can handle. At last Directions EMEA in Lyon me and my friend Duilio shared the following sticker:

What’s the meaning of this “rebus”?

On an average basis (accordingly to all the tenants we see every day) the cost of telemetry can be summarized like paying a breakfast (cappuccino and brioches) per user per month. Download this image and use it with your customers… 🙂

Can you pay a breakfast to your uses every month or your company could fail for this expense? If it can fail (I doubt!) thatn you can reduce telemetry ingestion or data retention period (the script does that). Cost is not a problem…

Leave a comment

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