Edit

Share via


Log storage and monitoring options in Azure Container Apps

Azure Container Apps gives you options for storing and viewing your application logs. You can configure logging options at the Container Apps environment level. If you select Azure Monitor as your logs destination, you can configure diagnostic settings at both the environment level and the container app level.

Container Apps application logs consist of two different categories:

  • Container console output (stdout/stderr) messages.
  • System logs generated by Azure Container Apps.
  • Spring App console logs.

You can choose between these logs destinations:

  • Log Analytics: Azure Monitor Log Analytics is the default storage and viewing option. Your logs are stored in a Log Analytics workspace where they can be viewed and analyzed using Log Analytics queries. To learn more about Log Analytics, see Azure Monitor Log Analytics.
  • Azure Monitor: Azure Monitor routes logs to one or more destinations:
    • Log Analytics workspace for viewing and analysis.
    • Azure storage account to archive.
    • Azure event hub for data ingestion and analytic services. For more information, see Azure Event Hubs.
    • An Azure partner monitoring solution such as Datadog, Elastic, Logz.io, and others. For more information, see Partner solutions.
  • Don't save logs: You can disable the storage of log data. When disabled, you can still view real-time container logs via the Logs stream feature in your container app. For more information, see Log streaming.

When Don't save logs or the Azure Monitor destination is selected, the Logs menu item providing the Log Analytics query editor in the Azure portal is disabled.

Configure logging options

Use these steps to configure the logging options for your environment in the Azure portal:

  1. Browse to your Container Apps environment in the portal.

  2. Select Monitoring > Logging options.

  3. You can choose from the following Logs Destination options:

    • Azure Log Analytics: With this option, you select a Log Analytics workspace to store your log data. Your logs can be viewed through Log Analytics queries. To learn more about Log Analytics, see Azure Monitor Log Analytics.
    • Azure Monitor: Azure Monitor routes your logs to a destination. When you select this option, you must select Diagnostic settings to complete the configuration after you select Save on this page.
    • Don't save logs: This option disables the storage of log data.
  4. Select Save.

Diagnostic settings

If you selected Azure Monitor as your logs destination, you must also configure the diagnostic settings. You can configure the diagnostic settings at both the environment level and the container app level.

Configure diagnostic settings at the environment level

Use these steps to configure the diagnostic settings for your environment:

  1. Browse to your environment in the portal.

  2. Select Monitoring > Diagnostic settings. If you've just set your environment's logs destination to Azure Monitor, you might need to refresh the page for this configuration item to appear.

Destination details are saved as diagnostic settings. You can create up to five diagnostic settings for your environment. You can configure different log categories for each diagnostic setting. For example, create one diagnostic setting to send the system logs category to one destination, and another to send the container console logs category to another destination.

To create a new diagnostic setting:

  1. Select Add diagnostic setting.

  2. In Diagnostic setting name, enter a name for your diagnostic setting.

  3. Select the log Category groups or Categories you want to send to this destination. You can select one or more categories.

  4. If you want to send app-level metrics, select Metrics > AllMetrics.

  5. Select one or more Destination details:

    • Send to Log Analytics workspace: Select from existing Log Analytics workspaces.
    • Archive to a storage account: This option is deprecated.
    • Stream to an event hub: Select from Azure event hubs.
    • Send to a partner solution: Select from Azure partner solutions.
  6. Select Save.

For more information about Diagnostic settings, see Diagnostic settings in Azure Monitor.

Configure diagnostic settings at the container app level

Use these steps to configure the diagnostic settings for your container app:

  1. Browse to your container app in the portal.

  2. Select Monitoring > Diagnostic settings. If you've just set your container app environment's logs destination to Azure Monitor, you might need to refresh the page for this configuration item to appear.

  3. Select Add diagnostic setting.

  4. In Diagnostic setting name, enter a name for your diagnostic setting.

  5. Under Metrics, select AllMetrics.

  6. Select one or more Destination details:

    • Send to Log Analytics workspace: Select from existing Log Analytics workspaces.
    • Archive to a storage account: This option is deprecated.
    • Stream to an event hub: Select from Azure event hubs.
    • Send to a partner solution: Select from Azure partner solutions.
  7. Select Save.

Configure logging options

Configure logs destination for your Container Apps environment using the Azure CLI az containerapp create and az containerapp update commands with the --logs-destination argument.

First, register the Microsoft.Insights namespace.

az provider register --namespace Microsoft.Insights

Send to a Log Analytics workspace

To create a Container Apps environment using an existing Log Analytics workspace as the logs destination, run the following command. Replace the <PLACEHOLDERS> with your values. You can get the Log Analytics workspace resource ID from the Log Analytics workspace page in the Azure portal, or from the az monitor log-analytics workspace show command.

az containerapp env create \
  --name <ENVIRONMENT_NAME> \
  --resource-group <RESOURCE_GROUP_NAME> \
  --logs-destination log-analytics \
  --logs-workspace-id <LOG_ANALYTICS_WORKSPACE_ID>

The --logs-destination argument accepts the values log-analytics, azure-monitor, and none.

Send to Azure Monitor

To update an existing Container Apps environment to use Azure Monitor as the logs destination, run the following command. Replace the <PLACEHOLDERS> with your values:

az containerapp env update \
  --name <ENVIRONMENT_NAME> \
  --resource-group <RESOURCE_GROUP_NAME> \
  --logs-destination azure-monitor

Configure diagnostic settings

When --logs-destination is set to azure-monitor, you must create diagnostic settings to configure the destination details for the log categories with the az monitor diagnostics-settings command. You can configure these diagnostic settings at both the environment level and the container app level.

To create diagnostic settings at the environment level, run the following command. Replace the <PLACEHOLDERS> with your values. You can get the environment ID from the Environment page in the Azure portal, or from the az containerapp env show command.

az monitor diagnostic-settings create \
  --name "AllMetricsToLogAnalytics" \
  --resource <ENVIRONMENT_ID> \
  --logs '[{"categoryGroup":"allLogs","enabled":true}]' \
  --metrics '[{"category":"AllMetrics","enabled":true}]' \
  --workspace <LOG_ANALYTICS_RESOURCE_ID>

Ensure there are no spaces in the JSON values provided to the --logs and --metrics parameters.

For the --logs parameter, you can specify category or categoryGroup, but not both at once. For categoryGroup, the available values are audit and allLogs. For category, the available values are ContainerAppConsoleLogs and ContainerAppSystemLogs.

For the --metrics parameter, the only available category is AllMetrics.

For more information see LogSettings and MetricSettings.

To create diagnostic settings at the container app level, run the following command. Replace the <PLACEHOLDERS> with your values. You can get the container app ID from the Azure portal, or from the az containerapp show command.

When creating diagnostic settings at the container app level, the --logs parameter is not supported, and for the --metrics parameter, the only available category is AllMetrics.

az monitor diagnostic-settings create \
--name "AllMetricsToLogAnalytics" \
--resource <CONTAINER_APP_ID> \
--metrics '[{"category":"AllMetrics","enabled":true}]' \
--workspace <LOG_ANALYTICS_RESOURCE_ID>

For more information about Azure Monitor diagnostic settings commands, see az monitor diagnostic-settings.

Limitations

The following limitations apply as you set up your log options.

  • Private link: Sending logs directly to a Log Analytics Workspace through Private Link isn't supported. However, you can use Azure Monitor and send your logs to the same Log Analytics Workspace. This indirection is required to prevent system log data loss.

Next steps