How to configure an Azure Container Apps Environment to send logs to a Azure Monitor

Giovanni Fleres 20 Reputation points
2023-08-08T07:51:25.9533333+00:00

Please could somebody provide an example about how configure an Azure Container Apps Environment to send logs to Azure Monitor using ARM, Bicep or Terraform ?

Below page is not updated and it is not clear how to achieve this

https://learn.microsoft.com/en-us/azure/templates/microsoft.app/2022-01-01-preview/managedenvironments?pivots=deployment-language-arm-template

Also there is an open ticket:

https://github.com/microsoft/azure-container-apps/issues/741

Thanks,

Giovanni

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,645 questions
Azure Container Apps
Azure Container Apps
An Azure service that provides a general-purpose, serverless container platform.
686 questions
{count} votes

Accepted answer
  1. SwathiDhanwada-MSFT 18,996 Reputation points Moderator
    2023-08-09T07:05:45.81+00:00

    @Giovanni Fleres Here are the ARM and Bicep templates which worked for me in deploying the diagnostic settings of Container Apps Environment. Kindly try it from your end and revert if you have any questions.

    Bicep Template:

    param managedEnvironments_container_app_env_name string = 'container-app-e'
    
    @description('description')
    param workspaceId string = ''
    
    @description('description')
    param settingName string = 'diagtest'
    
    resource managedEnvironments_container_app_env_name_resource 'Microsoft.App/managedEnvironments@2023-04-01-preview' = {
      name: managedEnvironments_container_app_env_name
      location: 'West US'
      properties: {
        appLogsConfiguration: {
          destination: 'azure-monitor'
        }
        zoneRedundant: false
        kedaConfiguration: {
        }
        daprConfiguration: {
        }
        customDomainConfiguration: {
        }
        peerAuthentication: {
          mtls: {
            enabled: false
          }
        }
      }
    }
    
    resource setting 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = {
      scope: managedEnvironments_container_app_env_name_resource
      name: settingName
      properties: {
        workspaceId: workspaceId
        logs: [
          {
            categoryGroup: 'AllLogs'
            enabled: true
          }
        ]
        metrics: [
          {
            category: 'AllMetrics'
            enabled: true
          }
        ]
      }
    }
    
    

    ARM Template:

    {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "managedEnvironments_container_app_env_name": {
          "defaultValue": "container-app-env",
          "type": "String"
        },
        "workspaceId": {
          "type": "string",
          "defaultValue": "/subscriptions/xxxxxxxx-xxx-xxxx-xxxx-xxxx/resourcegroups/rg/providers/microsoft.operationalinsights/workspaces/xx",
          "metadata": {
            "description": "description"
          }
        },
        "settingName": {
          "type": "string",
          "defaultValue":"diagtest",
          "metadata": {
            "description": "description"
          }
        }
      },
      "variables": {},
      "resources": [
        {
          "type": "Microsoft.App/managedEnvironments",
          "apiVersion": "2023-04-01-preview",
          "name": "[parameters('managedEnvironments_container_app_env_name')]",
          "location": "West US",
          "properties": {
            "appLogsConfiguration": {
              "destination": "azure-monitor"
            },
            "zoneRedundant": false,
            "kedaConfiguration": {},
            "daprConfiguration": {},
            "customDomainConfiguration": {},
            "peerAuthentication": {
              "mtls": {
                "enabled": false
              }
            }
          }
        },
        {
          "type": "Microsoft.Insights/diagnosticSettings",
          "apiVersion": "2021-05-01-preview",
          "name": "[parameters('settingName')]",
          "scope": "[resourceId('Microsoft.App/managedEnvironments', parameters('managedEnvironments_container_app_env_name'))]",
          "properties": {
            "workspaceId": "[parameters('workspaceId')]",
            "logs": [
              {
                "categorygroup":"allLogs",
                "enabled": true
              }
            ],
            "metrics": [
              {
                "category": "AllMetrics",
                "enabled": true
              }
            ]
          },
          "dependsOn": [
            "[resourceId('Microsoft.App/managedEnvironments', parameters('managedEnvironments_container_app_env_name'))]"
          ]
        }
      ]
    }
    
    
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Rubens Guimarães 175 Reputation points Microsoft Regional Director
    2023-08-08T11:08:09.0133333+00:00

    There are different levels of logs that you can manage or send to Monitor. Diagnostic Logs are the most suitable because they provide transaction details.

    The following link demonstrates how to implement: https://learn.microsoft.com/en-us/azure/container-apps/log-options

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.