Welcome to Day 19
of #30DaysOfServerless!
Today, we have a special set of posts from our Zero To Hero ๐ initiative, featuring blog posts authored by our Product Engineering teams for #ServerlessSeptember. Posts were originally published on the Apps on Azure blog on Microsoft Tech Community.
What We'll Coverโ
- Log Streaming - in Azure Portal
- Console Connect - in Azure Portal
- Metrics - using Azure Monitor
- Log Analytics - using Azure Monitor
- Metric Alerts and Log Alerts - using Azure Monitor
In past weeks, @kendallroden wrote about what it means to be Cloud-Native and @Anthony Chu the various ways to get your apps running on Azure Container Apps. Today, we will talk about the observability tools you can use to observe, debug, and diagnose your Azure Container Apps.
Azure Container Apps provides several observability features to help you debug and diagnose your apps. There are both Azure portal and CLI options you can use to help understand the health of your apps and help identify when issues arise.
While these features are helpful throughout your container appโs lifetime, there are two that are especially helpful. Log streaming and console connect can be a huge help in the initial stages when issues often rear their ugly head. Let's dig into both of these a little.
Log Streamingโ
Log streaming allows you to use the Azure portal to view the streaming logs from your app. Youโll see the logs written from the app to the containerโs console (stderr and stdout). If your app is running multiple revisions, you can choose from which revision to view logs. You can also select a specific replica if your app is configured to scale. Lastly, you can choose from which container to view the log output. This is useful when you are running a custom or Dapr sidecar container.
Hereโs an example CLI command to view the logs of a container app.
az containerapp logs show -n MyContainerapp -g MyResourceGroup
You can find more information about the different options in our CLI docs.
Console Connectโ
In the Azure portal, you can connect to the console of a container in your app. Like log streaming, you can select the revision, replica, and container if applicable. After connecting to the console of the container, you can execute shell commands and utilities that you have installed in your container. You can view files and their contents, monitor processes, and perform other debugging tasks.
This can be great for checking configuration files or even modifying a setting or library your container is using. Of course, updating a container in this fashion is not something you should do to a production app, but tweaking and re-testing an app in a non-production environment can speed up development.
Hereโs an example CLI command to connect to the console of a container app.
az containerapp exec -n MyContainerapp -g MyResourceGroup
You can find more information about the different options in our CLI docs.
Metricsโ
Azure Monitor collects metric data from your container app at regular intervals to help you gain insights into the performance and health of your container app. Container apps provide these metrics:
- CPU usage
- Memory working set bytes
- Network in bytes
- Network out bytes
- Requests
- Replica count
- Replica restart count
Here you can see the metrics explorer showing the replica count for an app as it scaled from one replica to fifteen, and then back down to one.
You can also retrieve metric data through the Azure CLI.
Log Analyticsโ
Azure Monitor Log Analytics is great for viewing your historical logs emitted from your container apps. There are two custom tables of interest, the ContainerAppConsoleLogs_CL which contains all the log messages written by your app (stdout and stderr), and the ContainerAppSystemLogs_CL which contain the system messages from the Azure Container Apps service.
You can also query Log Analytics through the Azure CLI.
Alertsโ
Azure Monitor alerts notify you so that you can respond quickly to critical issues. There are two types of alerts that you can define:
- Metric alerts based on Azure Monitor metric data
- Log alerts based on Azure Monitor Log Analytics data
You can create alert rules from metric charts in the metric explorer and from queries in Log Analytics. You can also define and manage alerts from the Monitor|Alerts page.
Here is what creating an alert looks like in the Azure portal. In this case we are setting an alert rule from the metric explorer to trigger an alert if the replica restart count for a specific container app is greater than two within the last fifteen minutes.
To learn more about alerts, refer to Overview of alerts in Microsoft Azure.
Conclusionโ
In this article, we looked at the several ways to observe, debug, and diagnose your Azure Container Apps. As you can see there are rich portal tools and a complete set of CLI commands to use. All the tools are helpful throughout the lifecycle of your app, be sure to take advantage of them when having an issue and/or to prevent issues.
To learn more, visit Azure Container Apps | Microsoft Azure today!
The Azure Container Apps team will answer questions live on September 29.
- Sign up to attend for live Q&A with the team
- submit your questions ahead of time, for prioritization.