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

With the built-in monitoring capability in Azure Spring Cloud, you can debug and monitor complex issues. Azure Spring Cloud 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 Cloud: 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-cloud app logs -n solar-system-weather -f

You will see 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-cloud 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 Cloud.

    Logs Analytics entry

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

  3. Then select Run, and you will see logs. See Azure Log Analytics docs for more guidance on writing queries.

    Logs Analytics query - Steeltoe

  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.

    Metrics entry - Steeltoe

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

    Use filter in metrics - Steeltoe

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

    Apply splitting in metrics - Steeltoe

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.

    Distributed Tracing entry - Steeltoe

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

    Distributed tracing overview - Steeltoe

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

    Distributed tracing - Steeltoe

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

    Distributed tracing performance - Steeltoe

With the built-in monitoring capability in Azure Spring Cloud, you can debug and monitor complex issues. Azure Spring Cloud 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

Complete previous steps:

Logs

There are two ways to see logs on Azure Spring Cloud: 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-cloud app logs -s <service instance name> -g <resource group name> -n gateway -f

You will see logs like this:

Log Streaming from Azure CLI

Tip

Use az spring-cloud 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 Cloud.

    Logs Analytics portal entry

  2. Then you will see filtered logs. See Azure Log Analytics docs for more guidance on writing queries.

    Logs Analytics query

Metrics

Navigate to the Application insights blade. Then, navigate to the Metrics blade - you can see metrics contributed by Spring Boot apps, Spring Cloud modules, and dependencies.

The chart below shows gateway-requests (Spring Cloud Gateway), hikaricp_connections (JDBC Connections) and http_client_requests.

Metrics blade

Spring Boot registers a lot number of core metrics: JVM, CPU, Tomcat, Logback... The Spring Boot auto-configuration enables the instrumentation of requests handled by Spring MVC. All those three REST controllers OwnerResource, PetResource and VisitResource have been instrumented by the @Timed Micrometer annotation at class level.

  • customers-service application has the following custom metrics enabled:
    • @Timed: petclinic.owner
    • @Timed: petclinic.pet
  • visits-service application has the following custom metrics enabled:
    • @Timed: petclinic.visit

You can see these custom metrics in the Metrics blade: Custom metrics

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

Availability test

Navigate to the Live Metrics blade - you can see live metrics on screen with low latencies < 1 second: Live metrics

Tracing

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

Navigate to the Application Map blade: Application map

Navigate to the Performance blade: Performance blade

Navigate to the Performance/Dependenices blade - you can see the performance number for dependencies, particularly SQL calls: Performance/Dependencies blade

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

Navigate to the Failures/Exceptions blade - you can see a collection of exceptions: Failures/Exceptions

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

Clean up resources

In these quickstarts, you created Azure resources that will continue to accrue charges if they remain in your subscription. If you don't expect to need these resources in the future, delete the resource group by using the portal or by running the following command in the Cloud Shell:

az group delete --name <your resource group name; for example: helloworld-1558400876966-rg> --yes

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 Cloud, see: