diff --git a/infra/core/host/app-diagnostics.bicep b/infra/core/host/app-diagnostics.bicep new file mode 100644 index 0000000..66e0b8e --- /dev/null +++ b/infra/core/host/app-diagnostics.bicep @@ -0,0 +1,56 @@ +param appName string = '' + +@description('The kind of the app.') +@allowed([ + 'functionapp' + 'webapp' +]) +param kind string + +@description('Resource ID of log analytics workspace.') +param diagnosticWorkspaceId string + +param diagnosticLogCategoriesToEnable array = kind == 'functionapp' ? [ + 'FunctionAppLogs' +] : [ + 'AppServiceHTTPLogs' + 'AppServiceConsoleLogs' + 'AppServiceAppLogs' + 'AppServiceAuditLogs' + 'AppServiceIPSecAuditLogs' + 'AppServicePlatformLogs' +] + +@description('Optional. The name of metrics that will be streamed.') +@allowed([ + 'AllMetrics' +]) +param diagnosticMetricsToEnable array = [ + 'AllMetrics' +] + + +var diagnosticsLogs = [for category in diagnosticLogCategoriesToEnable: { + category: category + enabled: true +}] + +var diagnosticsMetrics = [for metric in diagnosticMetricsToEnable: { + category: metric + timeGrain: null + enabled: true +}] + +resource app 'Microsoft.Web/sites@2022-03-01' existing = { + name: appName +} + +resource app_diagnosticSettings 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = { + name: '${appName}-diagnostics' + scope: app + properties: { + workspaceId: diagnosticWorkspaceId + metrics: diagnosticsMetrics + logs: diagnosticsLogs + } +} diff --git a/infra/main.bicep b/infra/main.bicep index 5f8c5a3..fd40cbc 100644 --- a/infra/main.bicep +++ b/infra/main.bicep @@ -80,6 +80,17 @@ module functionApp 'core/host/functions.bicep' = { } } + +module diagnostics 'core/host/app-diagnostics.bicep' = { + name: '${prefix}-appdiagnostics' + scope: resourceGroup + params: { + appName: functionApp.outputs.name + kind: 'functionapp' + diagnosticWorkspaceId: monitoring.outputs.logAnalyticsWorkspaceId + } +} + // CDN in front module cdnProfile 'cdn-profile.bicep' = { name: 'cdn-profile'