Skip to content

Commit 18d54d9

Browse files
committed
Update apm config with aca secrets
1 parent ceeaad3 commit 18d54d9

File tree

2 files changed

+55
-45
lines changed

2 files changed

+55
-45
lines changed

articles/container-apps/TOC.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@
381381
- name: Query managed component logs
382382
href: java-component-logs.md
383383
displayName: java
384-
- name: Configure APM integration by Java agent
384+
- name: Configure APM solutions by Java agent and init-container
385385
href: java-apm-agent-config.md
386386
- name: Create a highly available Eureka server component cluster
387387
href: java-eureka-server-highly-available.md

articles/container-apps/java-apm-agent-config.md

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: "Tutorial: Configure APM integration for Java applications in Azure Container Apps"
3-
description: Learn to configure APM integration for Java applications in Azure Container Apps
2+
title: "Tutorial: Configure APM integration for Java applications with Java agent and init-container"
3+
description: Learn to configure APM integration for Java applications with Java agent and init-container
44
services: container-apps
55
author: croffz
66
ms.service: azure-container-apps
@@ -10,9 +10,11 @@ ms.date: 09/26/2024
1010
ms.author: kuzhong
1111
---
1212

13-
# Tutorial: Configure APM integration for Java applications in Azure Container Apps
13+
# Tutorial: Configure APM integration for Java applications with Java agent and init-container
1414

15-
APM (Application Performance Management) is useful when you need observability on your applications running online. You can configure APM integration for Java applications in Azure Container Apps easily by Java agent and init containers without modifying your app image. In this tutorial, you learn how to:
15+
APM (Application Performance Management) is useful when it comes to observability for your applications running online. You can package the APM plugin in the same image or Dockerfile with your app, but this will bind the management efforts together, like release and CVE (Common Vulnerabilities and Exposures) mitigation. Alternatively, you can leverage Java agent and init containers in Azure Container Apps to inject APM solutions without modifying your app image.
16+
17+
In this tutorial, you learn how to:
1618

1719
> [!div class="checklist"]
1820
> * Prepare an image to set up Java agent and push to Azure Container Registry
@@ -44,8 +46,6 @@ The following commands help you define variables and ensure your Container Apps
4446
az login
4547
```
4648
47-
---
48-
4949
1. Ensure you have the latest version of Azure CLI extensions for Container Apps and Application Insights.
5050
5151
# [Bash](#tab/bash)
@@ -62,8 +62,6 @@ The following commands help you define variables and ensure your Container Apps
6262
az extension add -n application-insights --upgrade
6363
```
6464
65-
---
66-
6765
1. Set up environment variables used in various commands to follow.
6866
6967
# [Bash](#tab/bash)
@@ -88,10 +86,6 @@ The following commands help you define variables and ensure your Container Apps
8886
$LOCATION="eastus"
8987
```
9088
91-
---
92-
93-
## Prepare an image to set up Java agent and push to Azure Container Registry
94-
9589
1. Retrieve the connection string of Application Insights.
9690
9791
# [Bash](#tab/bash)
@@ -110,44 +104,57 @@ The following commands help you define variables and ensure your Container Apps
110104
--query connectionString)
111105
```
112106
113-
---
107+
## Prepare an image to set up Java agent and push to Azure Container Registry
108+
109+
> [!TIP]
110+
> You can skip this step and use `` as the init-container image.
114111
115112
1. Build setup image for Application Insights Java agent.
116113
117-
Save the Dockerfile and run `docker build` in the same directory.
114+
Save the Dockerfile along with the setup script, and run `docker build` in the same directory.
118115
119116
```Dockerfile
120117
FROM mcr.microsoft.com/cbl-mariner/base/core:2.0
121118
122-
ARG connectionString
119+
ARG version="3.5.4"
123120
124121
RUN tdnf update -y && tdnf install -y curl ca-certificates
125122
126-
RUN curl -L https://github.com/microsoft/ApplicationInsights-Java/releases/download/3.5.4/applicationinsights-agent-3.5.4.jar > agent.jar
123+
RUN curl -L "https://github.com/microsoft/ApplicationInsights-Java/releases/download/${version}/applicationinsights-agent-${version}.jar" > agent.jar
127124
128-
RUN echo "{\"connectionString\": \"${connectionString}\"}" > applicationinsights.json
125+
ADD setup.sh /setup.sh
129126
130-
ENTRYPOINT ["/bin/sh", "-c", "cp agent.jar /java-agent/agent.jar && cp applicationinsights.json /java-agent/applicationinsights.json"]
127+
ENTRYPOINT ["/bin/sh", "setup.sh"]
131128
```
132-
129+
130+
---
131+
132+
```shell
133+
#!/bin/sh
134+
135+
if [[ -z "$CONNECTION_STRING" ]]; then
136+
echo "Environment variable CONNECTION_STRING is not found. Exiting..."
137+
exit 1
138+
else
139+
echo "{\"connectionString\": \"$CONNECTION_STRING\"}" > /java-agent/applicationinsights.json
140+
cp agent.jar /java-agent/agent.jar
141+
fi
142+
```
143+
144+
---
145+
133146
# [Bash](#tab/bash)
134147
135148
```azurecli
136-
docker build . \
137-
-t "$CONTAINER_REGISTRY_NAME.azurecr.io/samples/java-agent-setup:1.0.0" \
138-
--build-arg connectionString=$CONNECTION_STRING
149+
docker build . -t "$CONTAINER_REGISTRY_NAME.azurecr.io/samples/java-agent-setup:1.0.0"
139150
```
140151
141152
# [PowerShell](#tab/powershell)
142153
143154
```powershell
144-
docker build . `
145-
-t "$CONTAINER_REGISTRY_NAME.azurecr.io/samples/java-agent-setup:1.0.0" `
146-
--build-arg connectionString=$CONNECTION_STRING
155+
docker build . -t "$CONTAINER_REGISTRY_NAME.azurecr.io/samples/java-agent-setup:1.0.0"
147156
```
148157
149-
---
150-
151158
1. Push the image to Azure Container Registry or other container image registries.
152159
153160
# [Bash](#tab/bash)
@@ -164,8 +171,6 @@ The following commands help you define variables and ensure your Container Apps
164171
docker push "$CONTAINER_REGISTRY_NAME.azurecr.io/samples/java-agent-setup:1.0.0"
165172
```
166173
167-
---
168-
169174
## Create a Container Apps environment and a Container App as the target Java app
170175
171176
1. Create a Container Apps environment.
@@ -190,8 +195,6 @@ The following commands help you define variables and ensure your Container Apps
190195
--query "properties.provisioningState"
191196
```
192197
193-
---
194-
195198
Once created, the command returns a "Succeeded" message.
196199
197200
1. Create a Container app for further configurations.
@@ -216,13 +219,11 @@ The following commands help you define variables and ensure your Container Apps
216219
--query "properties.provisioningState"
217220
```
218221
219-
---
220-
221222
Once created, the command returns a "Succeeded" message.
222223
223-
## Configure init containers and volume mounts to set up Application Insights integration
224+
## Configure init-container, environment variables and volumes to set up Application Insights integration
224225
225-
1. Get current configurations of running Container App.
226+
1. Get current configurations of the running Container App.
226227
227228
# [Bash](#tab/bash)
228229
@@ -242,13 +243,23 @@ The following commands help you define variables and ensure your Container Apps
242243
-o yaml > app.yaml
243244
```
244245
245-
---
246-
247246
YAML File `app.yaml` is created in current directory.
248247
249248
2. Edit the app YAML file.
250249
251-
- Ephemeral storage volume for Java agent files
250+
- Add a secret for Application Insights connection string
251+
252+
```yaml
253+
properties:
254+
configuration:
255+
secrets:
256+
- name: app-insights-connection-string
257+
value: $CONNECTION_STRING
258+
```
259+
260+
Replace $CONNECTION_STRING with your Azure Application Insights connection string.
261+
262+
- Add ephemeral storage volume for Java agent files
252263
253264
```yaml
254265
properties:
@@ -258,7 +269,7 @@ The following commands help you define variables and ensure your Container Apps
258269
storageType: EmptyDir
259270
```
260271
261-
- Init container with volume mount to set up Java agent
272+
- Add init-container with volume mounts and environment variables to set up Java agent
262273
263274
```yaml
264275
properties:
@@ -268,16 +279,18 @@ The following commands help you define variables and ensure your Container Apps
268279
name: java-agent-setup
269280
resources:
270281
cpu: 0.25
271-
ephemeralStorage: 1Gi
272282
memory: 0.5Gi
283+
env:
284+
- name: CONNECTION_STRING
285+
secretRef: app-insights-connection-string
273286
volumeMounts:
274287
- mountPath: /java-agent
275288
volumeName: java-agent-volume
276289
```
277290
278291
Replace $CONTAINER_REGISTRY_NAME with your Azure Container Registry name or replace the image from other container image registries.
279292
280-
- App container with volume mount and environment variable to inject Java agent
293+
- App container with volume mounts and environment variables to inject Java agent
281294
282295
```yaml
283296
properties:
@@ -287,7 +300,6 @@ The following commands help you define variables and ensure your Container Apps
287300
image: mcr.microsoft.com/azurespringapps/samples/hello-world:0.0.1
288301
resources:
289302
cpu: 0.5
290-
ephemeralStorage: 2Gi
291303
memory: 1Gi
292304
env:
293305
- name: JAVA_TOOL_OPTIONS
@@ -319,8 +331,6 @@ The following commands help you define variables and ensure your Container Apps
319331
--query "properties.provisioningState"
320332
```
321333
322-
---
323-
324334
Once updated, the command returns a "Succeeded" message. Then you can check out your Application Insights in Azure portal to see your Container App is connected.
325335
326336
## Other APM solutions

0 commit comments

Comments
 (0)