This article is contributed. See the original author and article here.

This post is part of the Zero To Hero series for #ServerlessSeptember, a month-long initiative to learn, use, and celebrate, all things Serverless On Azure.


 


Check out the main site at https://aka.ms/serverless-september to read other posts, participate in a Cloud Skills Challenge, explore a Serverless Hack, and participate in live Q&A with product teams on #AskTheExpert.


 


In past weeks, @kendallroden wrote about what it means to be cloud native and @Anthony Chu showed 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.


MikeMorton_0-1663305564504.png


 


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.


MikeMorton_0-1663386798888.png


 


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.


MikeMorton_1-1663386941330.png


 


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.


MikeMorton_2-1663386984809.png


 


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:



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.


MikeMorton_4-1663387168965.png


 


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 be answering your questions live on September 29thSign up to attend.


 

Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.