Reputation: 287
The Azure WebPub bicep documentation mentions nothing about how to enable diagnostic settings to stream logs to a log analytics workspace, but the Azure Portal has an interface for it.
I am guessing that I have to create a Microsoft.Insights/diagnosticSettings resource, buy the same thing applies here. No apparent documentation.
How do I enable diagnostics with bicep for Azure Web PubSub?
Upvotes: 2
Views: 741
Reputation: 287
Thanks for getting me in the right direction @Thomas. Your category names were a bit off and I also needed a workspaceId in the properties. After many attempts I got the category names by simply exporting my manual configuration to ARM and saw that the names should be as below.
resource webPubSubDiagnosticSettings 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = {
name: '${webPubSubName}-DiagnosticSettings'
scope: webpubsub
properties: {
workspaceId: logAnalyticsWorkspace.id
logs: [
{
category: 'ConnectivityLogs'
enabled: true
}
{
category: 'MessagingLogs'
enabled: true
}
{
category: 'HttpRequestLogs'
enabled: true
}
]
metrics: [
{
enabled: true
category: 'AllMetrics'
}
]
}
}
Upvotes: 1
Reputation: 29512
Something like that should work:
param webPubSubName string
// Get a reference to the existing signalR service
resource signalR 'Microsoft.SignalRService/webPubSub@2021-10-01' existing = {
name:webPubSubName
}
// Get the log category to send
// See https://learn.microsoft.com/en-us/azure/azure-monitor/reference/tables/tables-resourcetype?source=recommendations#signalr-service-webpubsub
var logTypes = [
'AzureActivity'
'WebPubSubConnectivity'
'WebPubSubHttpRequest'
'WebPubSubMessaging'
]
// Send logs to azure monitor
resource webPubSubLogs 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = {
scope: signalR
name: signalR.name
properties: {
...
logs: [for logType in logTypes: {
category: logType
enabled: true
retentionPolicy: {
enabled: true
days: 0
}
}]
metrics: [
{
category: 'AllMetrics'
enabled: true
retentionPolicy: {
enabled: true
days: 0
}
}
]
}
}
Upvotes: 0