Skip to content

Commit dfc5d57

Browse files
Merge pull request #273923 from craigshoemaker/aca/java-component-logs
[Container Apps] New: Read Java component logs
2 parents 3f27a1c + 8685703 commit dfc5d57

File tree

3 files changed

+173
-0
lines changed

3 files changed

+173
-0
lines changed

articles/container-apps/TOC.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@
338338
- name: Connect to Config Server for Spring
339339
href: java-config-server.md
340340
displayName: java
341+
- name: Query managed component logs
342+
href: java-component-logs.md
343+
displayName: java
341344
- name: Billing & quotas
342345
items:
343346
- name: Billing
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
---
2+
title: Observability of managed Java components in Azure Container Apps
3+
description: Learn how to retrieve logs of managed Java components in Azure Container Apps.
4+
services: container-apps
5+
author: craigshoemaker
6+
ms.service: container-apps
7+
ms.custom: devx-track-extended-java
8+
ms.topic: how-to
9+
ms.date: 05/01/2024
10+
ms.author: cshoe
11+
zone_pivot_groups: container-apps-portal-or-cli
12+
---
13+
14+
# Tutorial: Observability of managed Java components in Azure Container Apps
15+
16+
Java components include built-in observability features that can give you a holistic view of Java component health throughout its lifecycle. In this tutorial, you learn how to query logs messages generated by a Java component.
17+
18+
## Prerequisites
19+
20+
The following prerequisites are required for this tutorial.
21+
22+
| Resource | Description |
23+
|---|---|
24+
| Azure Log Analytics | To use the built-in observability features of managed Java components, ensure you set up Azure Log Analytics to use Log Analytics or *Azure Monitor*. For more information, see [Log storage and monitoring options in Azure Container Apps](log-options.md). |
25+
| Java component | Make sure to create at least one Java component in your environment, such as [Eureka Server](java-eureka-server.md) or [Config Server](java-config-server.md). |
26+
27+
## Query log data
28+
29+
Log Analytics is a tool that helps you view and analyze log data. Using Log Analytics, you can write Kusto queries to retrieve, sort, filter, and visualize log data. These visualizations help you spot trends and identify issues with your application. You can work interactively with the query results or use them with other features such as alerts, dashboards, and workbooks.
30+
31+
::: zone pivot="azure-portal"
32+
33+
1. Open the Azure portal and go to your Azure Log Analytics workspace.
34+
35+
1. Select **Logs** from the sidebar.
36+
37+
1. In the query tab, under the *Tables* section, under *Custom Logs*, select the **ContainerAppSystemlogs_CL** table.
38+
39+
1. Enter the following Kusto query to display Eureka Server logs for the Spring component.
40+
41+
```kusto
42+
ContainerAppSystemLogs_CL
43+
| where ComponentType_s == 'SpringCloudEureka'
44+
| project Time=TimeGenerated, Type=ComponentType_s, Component=ComponentName_s, Message=Log_s
45+
| take 100
46+
```
47+
48+
:::image type="content" source="media/java-components-logs/java-component-logs.png" alt-text="Screenshot of the Log Analytics Java component logs." lightbox="media/java-components-logs/java-component-logs.png":::
49+
50+
1. Select the **Run** button to run the query.
51+
52+
::: zone-end
53+
54+
::: zone pivot="azure-cli"
55+
56+
You query the component logs via the Azure CLI [log analytics](/cli/azure/monitor/log-analytics) extension.
57+
58+
1. Run the following command to create a variable for your Log Analytics workspace ID.
59+
60+
Make sure to replace `<WORKSPACE_ID>` with your Log Analytics workspace ID before running the query.
61+
62+
# [Bash](#tab/bash)
63+
64+
```azurecli
65+
SET $WORKSPACE_ID=<WORKSPACE_ID>
66+
```
67+
68+
# [PowerShell](#tab/powershell)
69+
70+
```powershell
71+
$WORKSPACE_ID = "<WORKSPACE_ID>"
72+
```
73+
74+
---
75+
76+
1. Run the following command to query the logs table.
77+
78+
# [Bash](#tab/bash)
79+
80+
```azurecli
81+
az monitor log-analytics query \
82+
--workspace $WORKSPACE_ID \
83+
--analytics-query "ContainerAppSystemLogs_CL | where ComponentType_s == 'SpringCloudEureka' | project Time=TimeGenerated, Type=ComponentType_s, Component=ComponentName_s, Message=Log_s | take 5" --out table
84+
```
85+
86+
# [PowerShell](#tab/powershell)
87+
88+
```powershell
89+
$queryResults = Invoke-AzOperationalInsightsQuery -WorkspaceId $WORKSPACE_ID -Query "ContainerAppSystemLogs_CL | where ComponentType_s == 'SpringCloudEureka' | project Time=TimeGenerated, Type=ComponentType_s, Component=ComponentName_s, Message=Log_s | take 5"
90+
$queryResults.Results
91+
```
92+
93+
---
94+
95+
The `project` operator's parameters specify the table columns.
96+
97+
::: zone-end
98+
99+
## Query Java Component Log with Azure monitor
100+
101+
You can query Azure Monitor for monitoring data for your Java component logs.
102+
103+
::: zone pivot="azure-portal"
104+
105+
1. Open the Azure portal and go to your Container Apps environment.
106+
107+
1. From the sidebar, under the *Monitoring* section, select **Logs**.
108+
109+
1. In the query tab, in the *Tables* section, under the *Container Apps* heading, select the **ContainerAppSystemLogs** table.
110+
111+
1. Enter the following Kusto query to display the log entries of Eureka Server for Spring component logs.
112+
113+
```kusto
114+
ContainerAppSystemLogs
115+
| where ComponentType == "SpringCloudEureka"
116+
| project Time=TimeGenerated, Type=ComponentType, Component=ComponentName, Message=Log
117+
| take 100
118+
```
119+
120+
1. Select the **Run** button to run the query.
121+
122+
::: zone-end
123+
124+
::: zone pivot="azure-cli"
125+
126+
You query the component logs via the Azure CLI [log analytics](/cli/azure/monitor/log-analytics) extension.
127+
128+
1. Run the following command to create a variable for your Log Analytics workspace ID.
129+
130+
Make sure to replace `<WORKSPACE_ID>` with your Log Analytics workspace ID before running the query.
131+
132+
# [Bash](#tab/bash)
133+
134+
```azurecli
135+
SET $WORKSPACE_ID=<WORKSPACE_ID>
136+
```
137+
138+
# [PowerShell](#tab/powershell)
139+
140+
```powershell
141+
$WORKSPACE_ID = "<WORKSPACE_ID>"
142+
```
143+
144+
---
145+
146+
1. Run the following command to query the logs table.
147+
148+
# [Bash](#tab/bash)
149+
150+
```azurecli
151+
az monitor log-analytics query --workspace $WORKSPACE_CUSTOMER_ID --analytics-query "ContainerAppSystemLogs | where ComponentType == 'SpringCloudEureka' | project Time=TimeGenerated, Type=ComponentType, Component=ComponentName, Message=Log | take 5" --out table
152+
```
153+
154+
# [PowerShell](#tab/powershell)
155+
156+
```powershell
157+
$queryResults = Invoke-AzOperationalInsightsQuery -WorkspaceId $WORKSPACE_ID -Query "ContainerAppSystemLogs | where ComponentType == 'SpringCloudEureka' | project Time=TimeGenerated, Type=ComponentType, Component=ComponentName, Message=Log | take 5"
158+
$queryResults.Results
159+
```
160+
161+
---
162+
163+
The `project` operator's parameters specify the table columns.
164+
165+
::: zone-end
166+
167+
## Next steps
168+
169+
> [!div class="nextstepaction"]
170+
> [Log storage and monitoring options in Azure Container Apps](log-options.md)
94.3 KB
Loading

0 commit comments

Comments
 (0)