Quickstart: Monitoring Azure Spring Apps apps with logs, metrics, and tracing

Note

Azure Spring Apps is the new name for the Azure Spring Cloud service. Although the service has a new name, you'll see the old name in some places for a while as we work to update assets such as screenshots, videos, and diagrams.

This article applies to: ✔️ Basic/Standard ❌ Enterprise

With the built-in monitoring capability in Azure Spring Apps, you can debug and monitor complex issues. Azure Spring Apps integrates Steeltoe distributed tracing with Azure's Application Insights. This integration provides powerful logs, metrics, and distributed tracing capability from the Azure portal.

The following procedures explain how to use Log Streaming, Log Analytics, Metrics, and Distributed Tracing with the sample app that you deployed in the preceding quickstarts.

Prerequisites

Logs

There are two ways to see logs on Azure Spring Apps: Log Streaming of real-time logs per app instance or Log Analytics for aggregated logs with advanced query capability.

Log streaming

You can use log streaming in the Azure CLI with the following command.

az spring app logs --name solar-system-weather --follow

You're shown output similar to the following example:

=> ConnectionId:0HM2HOMHT82UK => RequestPath:/weatherforecast RequestId:0HM2HOMHT82UK:00000003, SpanId:|e8c1682e-46518cc0202c5fd9., TraceId:e8c1682e-46518cc0202c5fd9, ParentId: => Microsoft.Azure.SpringCloud.Sample.SolarSystemWeather.Controllers.WeatherForecastController.Get (Microsoft.Azure.SpringCloud.Sample.SolarSystemWeather)
Executing action method Microsoft.Azure.SpringCloud.Sample.SolarSystemWeather.Controllers.WeatherForecastController.Get (Microsoft.Azure.SpringCloud.Sample.SolarSystemWeather) - Validation state: Valid
←[40m←[32minfo←[39m←[22m←[49m: Microsoft.Azure.SpringCloud.Sample.SolarSystemWeather.Controllers.WeatherForecastController[0]

=> ConnectionId:0HM2HOMHT82UK => RequestPath:/weatherforecast RequestId:0HM2HOMHT82UK:00000003, SpanId:|e8c1682e-46518cc0202c5fd9., TraceId:e8c1682e-46518cc0202c5fd9, ParentId: => Microsoft.Azure.SpringCloud.Sample.SolarSystemWeather.Controllers.WeatherForecastController.Get (Microsoft.Azure.SpringCloud.Sample.SolarSystemWeather)
Retrieved weather data from 4 planets
←[40m←[32minfo←[39m←[22m←[49m: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[2]

=> ConnectionId:0HM2HOMHT82UK => RequestPath:/weatherforecast RequestId:0HM2HOMHT82UK:00000003, SpanId:|e8c1682e-46518cc0202c5fd9., TraceId:e8c1682e-46518cc0202c5fd9, ParentId: => Microsoft.Azure.SpringCloud.Sample.SolarSystemWeather.Controllers.WeatherForecastController.Get (Microsoft.Azure.SpringCloud.Sample.SolarSystemWeather)
Executing ObjectResult, writing value of type 'System.Collections.Generic.KeyValuePair`2[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]][]'.
←[40m←[32minfo←[39m←[22m←[49m: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[2]

Tip

Use az spring app logs -h to explore more parameters and log stream functionality.

Log Analytics

  1. In the Azure portal, go to the service | Overview page and select Logs in the Monitoring section. Select Run on one of the sample queries for Azure Spring Apps.

    Screenshot of the Azure portal that shows the Logs pane with Queries page open and Run highlighted.

  2. Edit the query to remove the Where clauses that limit the display to warning and error logs.

  3. Select Run. You're shown logs. For more information, see Get started with log queries in Azure Monitor.

    Screenshot of the Azure portal that shows the Logs Analytics query result.

  4. To learn more about the query language that's used in Log Analytics, see Azure Monitor log queries. To query all your Log Analytics logs from a centralized client, check out Azure Data Explorer.

Metrics

  1. In the Azure portal, go to the service | Overview page and select Metrics in the Monitoring section. Add your first metric by selecting one of the .NET metrics under Performance (.NET) or Request (.NET) in the Metric drop-down, and Avg for Aggregation to see the timeline for that metric.

    Screenshot of the Azure portal that shows the Metrics page with available filters.

  2. Select Add filter in the toolbar, select App=solar-system-weather to see CPU usage only for the solar-system-weather app.

    Screenshot of the Azure portal that shows the Metrics page with the filter Property, Operator, and Values options highlighted.

  3. Dismiss the filter created in the preceding step, select Apply Splitting, and select App for Values to see the CPU usage by different apps.

    Screenshot of the Azure portal that shows the Metrics page with the splitting Values, Limit, and Sort options highlighted.

Distributed tracing

  1. In the Azure portal, go to the service | Overview page and select Distributed tracing in the Monitoring section. Then select the View application map tab on the right.

    Screenshot of the Azure portal that shows the Distributed tracing page.

  2. You can now see the status of calls between apps.

    Screenshot of the Azure portal that shows the Application map page.

  3. Select the link between solar-system-weather and planet-weather-provider to see more details such as the slowest calls by HTTP methods.

    Screenshot of the Azure portal that shows the Application map details.

  4. Finally, select Investigate Performance to explore more powerful built-in performance analysis.

    Screenshot of the Azure portal that shows the Performance page.

With the built-in monitoring capability in Azure Spring Apps, you can debug and monitor complex issues. Azure Spring Apps integrates Spring Cloud Sleuth with Azure's Application Insights. This integration provides powerful logs, metrics, and distributed tracing capability from the Azure portal. The following procedures explain how to use Log Streaming, Log Analytics, Metrics, and Distributed tracing with deployed PetClinic apps.

Prerequisites

Logs

There are two ways to see logs on Azure Spring Apps: Log Streaming of real-time logs per app instance or Log Analytics for aggregated logs with advanced query capability.

Log streaming

You can use log streaming in the Azure CLI with the following command.

az spring app logs \
    --resource-group <resource-group-name> \
    --service <service-instance-name> \
    --name api-gateway \
    --follow

You're shown logs like this:

Screenshot of the Azure CLI log streaming output.

Tip

Use az spring app logs -h to explore more parameters and log stream functionalities.

To learn more about the query language that's used in Log Analytics, see Azure Monitor log queries. To query all your Log Analytics logs from a centralized client, check out Azure Data Explorer.

Log Analytics

  1. Go to the service | Overview page and select Logs in the Monitoring section. Select Run on one of the sample queries for Azure Spring Apps.

    Screenshot of the Azure portal that shows the Queries page with Run highlighted.

  2. Then you're shown filtered logs. For more information, see Get started with log queries in Azure Monitor.

    Screenshot of the Azure portal that shows the query result of filtered logs.

Metrics

Navigate to the Application insights page, and then navigate to the Metrics page. You can see metrics contributed by Spring Boot apps, Spring modules, and dependencies.

The following chart shows gateway_requests (Spring Cloud Gateway), hikaricp_connections (JDBC Connections), and http_client_requests.

Screenshot of the Azure portal that shows the Application Insights Metrics page with a graph of the selected values.

Spring Boot registers several core metrics, including JVM, CPU, Tomcat, and Logback. The Spring Boot autoconfiguration enables the instrumentation of requests handled by Spring MVC. All three REST controllers (OwnerResource, PetResource, and VisitResource) are instrumented by the @Timed Micrometer annotation at the class level.

The customers-service application has the following custom metrics enabled:

  • @Timed: petclinic.owner
  • @Timed: petclinic.pet

The visits-service application has the following custom metrics enabled:

  • @Timed: petclinic.visit

You can see these custom metrics in the Metrics page:

Screenshot of the Azure portal that shows the Application Insights Metrics page with custom metrics.

You can use the Availability Test feature in Application Insights and monitor the availability of applications:

Screenshot of the Azure portal that shows the Application Insights Availability page with the Availability Test section highlighted.

Navigate to the Live Metrics page to see live metrics with low latencies (less than one second):

Screenshot of the Azure portal that shows the Application Insights Live Metrics page low latencies graphs.

Tracing

Open the Application Insights created by Azure Spring Apps and start monitoring Spring applications.

Navigate to the Application Map page:

Screenshot of the Azure portal that shows the Application Insights Application Map page with map components.

Navigate to the Performance page:

Screenshot of the Azure portal that shows the Application Insights Performance page with Operation details.

Navigate to the Dependencies tab, where you can see the performance number for dependencies, particularly SQL calls:

Screenshot of the Azure portal that shows the Application Insights Performance page with the Depencies table highlighted.

Select a SQL call to see the end-to-end transaction in context:

Screenshot of the Azure portal that shows the End-to-end transaction details page.

Navigate to the Failures page and the Exceptions tab, where you can see a collection of exceptions:

Screenshot of the Azure portal that shows the Application Insights Failures page.

Select an exception to see the end-to-end transaction and stacktrace in context:

Screenshot of the Azure portal that shows the End-to-end transaction details page with the exception details and call stack.

Clean up resources

If you plan to continue working with subsequent quickstarts and tutorials, you might want to leave these resources in place. When no longer needed, delete the resource group, which deletes the resources in the resource group. To delete the resource group by using Azure CLI, use the following commands:

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
az group delete --name $resourceGroupName &&
echo "Press [ENTER] to continue ..."

In an earlier quickstart, you also set the default resource group name. If you don't intend to continue to the next quickstart, clear out that default by running the following CLI command:

az config set defaults.group=

Next steps

To explore more monitoring capabilities of Azure Spring Apps, see: