I never really understood when I was given advice by my fellow Microsoft colleagues that I should use this code from the documentation to add Diagnostics to SQL Pools.
I finally realised that Diagnostics should not be seen as part of the resource, but as an addition to ANY resource in Azure. So this “Extension Resource” code is perfect. And the key to making it work is the “Scope” piece in this code.
You are telling the ARM template that you want to add this extension to the _specifically_s named resource in the Scope section. Once you understand this then you are golden.
I want to send my Diagnostics to a Log Analytics Workspace (LAW). The part of the code that sends it there is “WorkspaceId”. Of course you should have an existing LAW set up already.
Simply add this code to the “Resources” part of your ARM templates
{
"type": "Microsoft.Insights/diagnosticSettings",
"apiVersion": "2021-05-01-preview",
"dependsOn": [
"[variables('sqlPoolName')]"
],
"name": "mydiag",
"scope":"[concat('Microsoft.Synapse/workspaces/',variables('workspaceName'),'/sqlPools/', variables('sqlPoolName'))]",
"properties": {
"logAnalyticsDestinationType": "AzureDiagnostics",
"logs": [
{
"category": "SqlRequests",
"enabled": true
},
{
"category": "RequestSteps",
"enabled": true
},
{
"category": "ExecRequests",
"enabled": true
},
{
"category": "DmsWorkers",
"enabled": true
},
{
"category": "Waits",
"enabled": true
}
],
"metrics": [
{
"category": "AllMetrics",
"enabled": true
}
],
"workspaceId": "[resourceId(parameters('LogAnalyticsSubscriptionID'), parameters('LogAnalyticsResourceGroup'), 'Microsoft.OperationalInsights/workspaces',parameters('LogAnalyticsWorkspaceName'))]"
}
}