Skip to content

Commit ccc61fa

Browse files
authored
Merge pull request #242058 from moarychan/moary/tutorial/monitor-and-investigate-production-ready
New ASA tutorial doc - Optimizing Applications Observability for Azure Spring Apps
2 parents 2fa9544 + be454da commit ccc61fa

29 files changed

+512
-0
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
---
2+
title: Optimize application observability for Azure Spring Apps
3+
description: Learn how to observe the application of Azure Spring Apps.
4+
author: karlerickson
5+
ms.author: v-shilichen
6+
ms.service: spring-apps
7+
ms.topic: how-to
8+
ms.date: 10/02/2023
9+
ms.custom: devx-track-java, devx-track-extended-java, devx-track-azurecli, event-tier1-build-2022
10+
---
11+
12+
# Optimize application observability for Azure Spring Apps
13+
14+
> [!NOTE]
15+
> 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.
16+
17+
**This article applies to:** ✔️ Java ❌ C#
18+
19+
**This article applies to:** <br>
20+
❌ Standard consumption and dedicated (Preview) ✔️ Basic/Standard ❌ Enterprise
21+
22+
This article shows you how to observe your production applications deployed on Azure Spring Apps and diagnose and investigate production issues. Observability is the ability to collect insights, analytics, and actionable intelligence through the logs, metrics, traces, and alerts.
23+
24+
To find out if your applications meet expectations and to discover and predict issues in all applications, focus on the following areas:
25+
26+
- **Availability**: Check that the application is available and accessible to the user.
27+
- **Reliability**: Check that the application is reliable and can be used normally.
28+
- **Failure**: Understand that the application isn't working properly and further fixes are required.
29+
- **Performance**: Understand which performance issues the application encounters that need further attention and find out the root cause of the problem.
30+
- **Alerts**: Know the current state of the application. Proactively notify others and take necessary actions when the application isn't working properly.
31+
32+
This article uses the well-known [PetClinic](https://github.com/azure-samples/spring-petclinic-microservices) sample app as the production application. For more information on how to deploy PetClinic to Azure Spring Apps and use MySQL as the persistent store, see the following articles:
33+
34+
- [Deploy microservice applications to Azure Spring Apps](./quickstart-deploy-microservice-apps.md)
35+
- [Integrate Azure Spring Apps with Azure Database for MySQL](./quickstart-integrate-azure-database-mysql.md)
36+
37+
Log Analytics and Application Insights are deeply integrated with Azure Spring Apps. You can use Log Analytics to diagnose your application with various log queries and use Application Insights to investigate production issues. For more information, see the following articles:
38+
39+
- [Overview of Log Analytics in Azure Monitor](../azure-monitor/logs/log-analytics-overview.md)
40+
- [Azure Monitor Insights overview](../azure-monitor/insights/insights-overview.md)
41+
42+
## Prerequisites
43+
44+
- An Azure subscription. [!INCLUDE [quickstarts-free-trial-note](../../includes/quickstarts-free-trial-note.md)]
45+
46+
[!INCLUDE [application-observability-with-basic-standard-plan](includes/application-observability/application-observability-with-basic-standard-plan.md)]
47+
48+
## Query logs to diagnose an application problem
49+
50+
If you encounter production issues, you need to do a root cause analysis. Finding logs is an important part of this analysis, especially for distributed applications with logs spread across multiple applications. The trace data collected by Application Insights can help you find the log information for all related links, including the exception stack information.
51+
52+
This section explains how to use Log Analytics to query the application logs and use Application Insights to investigate request failures. For more information, see the following articles:
53+
54+
- [Log Analytics tutorial](../azure-monitor/logs/log-analytics-tutorial.md)
55+
- [Application Map: Triage distributed applications](../azure-monitor/app/app-map.md)
56+
57+
### Log queries
58+
59+
This section explains how to query application logs from the `AppPlatformLogsforSpring` table hosted by Azure Spring Apps. You can use the [Kusto Query Language](/azure/data-explorer/kusto/query/) to customize your queries for application logs.
60+
61+
To see the built-in example query statements or to write your own queries, open the Azure Spring Apps instance and go to the **Logs** menu.
62+
63+
#### Show the application logs that contain the "error" or "exception" terms
64+
65+
To see the application logs containing the terms "error" or "exception", select **Alerts** on the **Queries** page, and then select **Run** in the **Show the application logs which contain the "error" or "exception" terms** section.
66+
67+
The following query shows the application logs from the last hour that contains the terms "error" or "exception". You can customize the query with any keyword you want to search for.
68+
69+
```sql
70+
AppPlatformLogsforSpring
71+
| where TimeGenerated > ago(1h)
72+
| where Log contains "error" or Log contains "exception"
73+
| project TimeGenerated , ServiceName , AppName , InstanceName , Log , _ResourceId
74+
```
75+
76+
:::image type="content" source="media/application-observability/show-application-logs-abnormal.png" alt-text="Screenshot of the Azure portal that shows the Logs page with the example query and query results." lightbox="media/application-observability/show-application-logs-abnormal.png":::
77+
78+
#### Show the error and exception number of each application
79+
80+
To see the error and exception number of an application, select **Alerts** on the **Queries** page, and then select **Run** in the **Show the error and exception number of each application** section.
81+
82+
The following query shows a pie chart of the number of the logs in the last 24 hours that contain the terms "error" or "exception". To view the results in a table format, select **Result**.
83+
84+
```sql
85+
AppPlatformLogsforSpring
86+
| where TimeGenerated > ago(24h)
87+
| where Log contains "error" or Log contains "exception"
88+
| extend FullAppName = strcat(ServiceName, "/", AppName)
89+
| summarize count_per_app = count() by FullAppName, ServiceName, AppName, _ResourceId
90+
| sort by count_per_app desc
91+
| render piechart
92+
```
93+
94+
:::image type="content" source="media/application-observability/show-application-logs-abnormal-number.png" alt-text="Screenshot of the Azure portal that shows abnormal logs number for the Azure Spring Apps instance." lightbox="media/application-observability/show-application-logs-abnormal-number.png":::
95+
96+
#### Query the customers service log with a key word
97+
98+
Use the following query to see a list of logs in the `customers-service` app that contain the term "root cause". Update the query to use the keyword that you're looking for.
99+
100+
```sql
101+
AppPlatformLogsforSpring
102+
| where AppName == "customers-service"
103+
| where Log contains "root cause"
104+
| project-keep InstanceName, Log
105+
```
106+
107+
:::image type="content" source="media/application-observability/show-error-logs.png" alt-text="Screenshot of the Azure portal that shows the Logs page with the example query and root cause logs." lightbox="media/application-observability/show-error-logs.png":::
108+
109+
### Investigate request failures
110+
111+
Use the following steps to investigate request failures in the application cluster and to view the failed request list and specific examples of the failed requests:
112+
113+
1. Go to the Azure Spring Apps instance overview page.
114+
115+
1. On the navigation menu, select **Application Insights** to go to the Application Insights overview page. Then, select **Failures**.
116+
117+
:::image type="content" source="media/application-observability/application-insights-failures.png" alt-text="Screenshot of the Azure portal that shows the Application Insights Failures page." lightbox="media/application-observability/application-insights-failures.png":::
118+
119+
1. On the **Failure** page, select the `PUT` operation that has the most failed requests count, select **1 Samples** to go into the details, and then select the suggested sample.
120+
121+
:::image type="content" source="media/application-observability/application-insights-failure-suggested-sample.png" alt-text="Screenshot of the Azure portal that shows the Select a sample operation pane with the suggested failure sample." lightbox="media/application-observability/application-insights-failure-suggested-sample.png":::
122+
123+
1. Go to the **End-to-end transaction details** page to view the full call stack in the right panel.
124+
125+
:::image type="content" source="media/application-observability/application-insights-e2e-exception.png" alt-text="Screenshot of the Azure portal that shows the End-to-end transaction details page with Application Insights failures." lightbox="media/application-observability/application-insights-e2e-exception.png":::
126+
127+
## Improve the application performance using Application Insights
128+
129+
If there's a performance issue, the trace data collected by Application Insights can help find the log information of all relevant links, including the execution time of each link, to help find the location of the performance bottleneck.
130+
131+
To use Application Insights to investigate the performance issues, use the following steps:
132+
133+
1. Go to the Azure Spring Apps instance overview page.
134+
135+
1. On the navigation menu, select **Application Insights** to go to the Application Insights overview page. Then, select **Performance**.
136+
137+
:::image type="content" source="media/application-observability/application-insights-performance.png" alt-text="Screenshot of the Azure portal that shows the Application Insights Performance page." lightbox="media/application-observability/application-insights-performance.png":::
138+
139+
1. On the **Performance** page, select the slowest `GET /api/gateway/owners/{ownerId}` operation, select **3 Samples** to go into the details, and then select the suggested sample.
140+
141+
:::image type="content" source="media/application-observability/application-insights-performance-suggested-sample.png" alt-text="Screenshot of the Azure portal that shows the Select a sample operation pane with the suggested performance sample." lightbox="media/application-observability/application-insights-performance-suggested-sample.png":::
142+
143+
1. Go to the **End-to-end transaction details** page to view the full call stack in the right panel.
144+
145+
:::image type="content" source="media/application-observability/application-insights-e2e-performance.png" alt-text="Screenshot of the Azure portal that shows the End-to-end transaction details page with the Application Insights performance issue." lightbox="media/application-observability/application-insights-e2e-performance.png":::
146+
147+
[!INCLUDE [clean-up-resources-portal](includes/application-observability/clean-up-resources.md)]
148+
149+
## Next steps
150+
151+
> [!div class="nextstepaction"]
152+
> [Set up a staging environment](../spring-apps/how-to-staging-environment.md)
153+
154+
> [!div class="nextstepaction"]
155+
> [Map an existing custom domain to Azure Spring Apps](./tutorial-custom-domain.md)
156+
157+
> [!div class="nextstepaction"]
158+
> [Use TLS/SSL certificates](./how-to-use-tls-certificate.md)

0 commit comments

Comments
 (0)