You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Tutorial: Configure Application Performance Management (APM) Java agent with init-container in Azure Container Apps
15
15
16
-
Apply Java agent and init containers in Azure Container Apps to inject Application Performance Management (APM) solutions without modifying your app image. While you can package the APM plugin in the same image or Dockerfile with your app, this binds together management efforts like release and Common Vulnerabilities and Exposures (CVE) mitigation.
16
+
This article shows you how to configure Application Performance Management (APM) Java agent with init containers in Azure Container Apps, which injects APM solutions without modifying your app image. While you can package the APM plugin in the same image or Dockerfile with your app, doing that binds together management efforts like release and Common Vulnerabilities and Exposures (CVE) mitigation.
17
17
18
18
In this tutorial, you learn how to:
19
19
@@ -80,15 +80,15 @@ The following steps define environment variables and ensure your Container Apps
80
80
# [Bash](#tab/bash)
81
81
82
82
```bash
83
-
az extension add -n containerapp --upgrade
84
-
az extension add -n application-insights --upgrade
83
+
az extension add --name containerapp --upgrade
84
+
az extension add --name application-insights --upgrade
85
85
```
86
86
87
87
# [PowerShell](#tab/powershell)
88
88
89
89
```powershell
90
-
az extension add -n containerapp --upgrade
91
-
az extension add -n application-insights --upgrade
90
+
az extension add --name containerapp --upgrade
91
+
az extension add --name application-insights --upgrade
92
92
```
93
93
94
94
1. To retrieve the connection string of Application Insights, use the following commands:
@@ -111,7 +111,7 @@ The following steps define environment variables and ensure your Container Apps
111
111
112
112
## Prepare the container image
113
113
114
-
To build a setup image forApplication Insights Java agent, perform these following stepsin the same directory:
114
+
To build a setup image forApplication Insights Java agent, perform the following stepsin the same directory:
115
115
116
116
1. Save the following Dockerfile:
117
117
@@ -157,7 +157,7 @@ To build a setup image for Application Insights Java agent, perform these follow
1. Push the image to Azure Container Registry or another container image registry by using the following command:
160
+
1. Push the image to Azure Container Registry or another container image registry by using the following commands:
161
161
162
162
# [Bash](#tab/bash)
163
163
@@ -174,190 +174,194 @@ To build a setup image for Application Insights Java agent, perform these follow
174
174
```
175
175
176
176
> [!TIP]
177
-
> You can find code relevant to this step in the [Azure Contaier Apps Java Samples](https://github.com/Azure-Samples/azure-container-apps-java-samples) GitHub repo.
177
+
> You can find code relevant to this step in the [azure-container-apps-java-samples](https://github.com/Azure-Samples/azure-container-apps-java-samples) GitHub repo.
178
178
179
179
## Create a Container Apps environment and a Container App as the target Java app
180
180
181
-
1. Create a Container Apps environment.
181
+
To create a Container Apps environment and a container app as the target Java app, perform the following steps:
182
+
183
+
1. Create a Container Apps environment by using the following command:
182
184
183
185
# [Bash](#tab/bash)
184
186
185
187
```bash
186
188
az containerapp env create \
187
-
--name $ENVIRONMENT_NAME \
188
-
--resource-group $RESOURCE_GROUP \
189
-
--location "$LOCATION" \
190
-
--query "properties.provisioningState"
189
+
--name $ENVIRONMENT_NAME \
190
+
--resource-group $RESOURCE_GROUP \
191
+
--location "$LOCATION" \
192
+
--query "properties.provisioningState"
191
193
```
192
194
193
195
# [PowerShell](#tab/powershell)
194
196
195
197
```powershell
196
198
az containerapp env create `
197
-
--name $ENVIRONMENT_NAME`
198
-
--resource-group $RESOURCE_GROUP`
199
-
--location "$LOCATION"`
200
-
--query "properties.provisioningState"
199
+
--name $ENVIRONMENT_NAME`
200
+
--resource-group $RESOURCE_GROUP`
201
+
--location "$LOCATION"`
202
+
--query "properties.provisioningState"
201
203
```
202
204
203
-
Once created, the command returns a "Succeeded" message.
205
+
After successfully creating the Container Apps environment, the commandline returns a `Succeeded` message.
204
206
205
-
1. Create a Container app for further configurations.
207
+
1. Create a Container app for further configurations by using the following command:
206
208
207
209
# [Bash](#tab/bash)
208
210
209
211
```bash
210
212
az containerapp create \
211
-
--name $CONTAINER_APP_NAME \
212
-
--environment $ENVIRONMENT_NAME \
213
-
--resource-group $RESOURCE_GROUP \
214
-
--query "properties.provisioningState"
213
+
--name $CONTAINER_APP_NAME \
214
+
--environment $ENVIRONMENT_NAME \
215
+
--resource-group $RESOURCE_GROUP \
216
+
--query "properties.provisioningState"
215
217
```
216
218
217
219
# [PowerShell](#tab/powershell)
218
220
219
221
```powershell
220
222
az containerapp create `
221
-
--name $CONTAINER_APP_NAME`
222
-
--environment $ENVIRONMENT_NAME`
223
-
--resource-group $RESOURCE_GROUP`
224
-
--query "properties.provisioningState"
223
+
--name $CONTAINER_APP_NAME`
224
+
--environment $ENVIRONMENT_NAME`
225
+
--resource-group $RESOURCE_GROUP`
226
+
--query "properties.provisioningState"
225
227
```
226
228
227
-
Once created, the command returns a "Succeeded" message.
229
+
After successfully creating the Container App, the command line returns a `Succeeded` message.
230
+
231
+
## Configure init container, secrets, environment variables, and volumes to set up Application Insights integration
228
232
229
-
## Configure init-container, secrets, environment variables, and volumes to set up Application Insights integration
233
+
To configure your initcontainer with secrets, environment variables, and volumes so it can be used with Insights, perform the following steps:
230
234
231
-
1. Get current configurations of the running Container App.
235
+
1. Write the current configurations of the running Container App to **app.yml**in the current directory, by using the following command:
232
236
233
237
# [Bash](#tab/bash)
234
238
235
239
```bash
236
240
az containerapp show \
237
-
--name $CONTAINER_APP_NAME \
238
-
--resource-group $RESOURCE_GROUP \
239
-
-o yaml > app.yaml
241
+
--resource-group $RESOURCE_GROUP \
242
+
--name $CONTAINER_APP_NAME \
243
+
--output yaml \
244
+
> app.yaml
240
245
```
241
246
242
247
# [PowerShell](#tab/powershell)
243
248
244
249
```powershell
245
250
az containerapp show `
246
-
--name $CONTAINER_APP_NAME`
247
-
--resource-group $RESOURCE_GROUP`
248
-
-o yaml > app.yaml
251
+
--resource-group $RESOURCE_GROUP`
252
+
--name $CONTAINER_APP_NAME`
253
+
--output yaml `
254
+
> app.yaml
249
255
```
250
256
251
-
The YAML file `app.yaml` is created in current directory.
257
+
1. Edit the configurations in**app.yml** by using the following instructions:
252
258
253
-
1. Edit the app YAML file.
259
+
1. Add a secret for Application Insights connection string using the following code snippet:
254
260
255
-
- Add secret for Application Insights connection string
256
-
257
-
```yaml
258
-
properties:
259
-
configuration:
260
-
secrets:
261
-
- name: app-insights-connection-string
262
-
value: $CONNECTION_STRING
263
-
```
261
+
```yaml
262
+
properties:
263
+
configuration:
264
+
secrets:
265
+
- name: app-insights-connection-string
266
+
value: $CONNECTION_STRING
267
+
```
264
268
265
-
Replace $CONNECTION_STRING with your Azure Application Insights connection string.
269
+
Replace $CONNECTION_STRING with your Azure Application Insights connection string.
266
270
267
-
- Add ephemeral storage volume for Java agent files
271
+
1. Add ephemeral storage volume for Java agent files using the following code snippet:
268
272
269
-
```yaml
270
-
properties:
271
-
template:
272
-
volumes:
273
-
- name: java-agent-volume
274
-
storageType: EmptyDir
275
-
```
276
-
277
-
- Add init-container with volume mounts and environment variables
273
+
```yaml
274
+
properties:
275
+
template:
276
+
volumes:
277
+
- name: java-agent-volume
278
+
storageType: EmptyDir
279
+
```
280
+
281
+
1. Add an initcontainer with volume mounts and environment variables, using the following code snippet:
1. Update the container app with modified YAML file.
318
-
319
-
# [Bash](#tab/bash)
320
-
321
-
```bash
322
-
az containerapp update \
323
-
--name $CONTAINER_APP_NAME \
324
-
--resource-group $RESOURCE_GROUP\
325
-
--yaml app.yaml \
326
-
--query "properties.provisioningState"
327
-
```
328
-
329
-
# [PowerShell](#tab/powershell)
330
-
331
-
```powershell
332
-
az containerapp update `
333
-
--name $CONTAINER_APP_NAME`
334
-
--resource-group $RESOURCE_GROUP`
335
-
--yaml app.yaml `
336
-
--query "properties.provisioningState"
337
-
```
338
-
339
-
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.
1. Update the container app with the modified YAML file, using the following command:
322
+
323
+
# [Bash](#tab/bash)
324
+
325
+
```bash
326
+
az containerapp update \
327
+
--name $CONTAINER_APP_NAME \
328
+
--resource-group $RESOURCE_GROUP\
329
+
--yaml app.yaml \
330
+
--query "properties.provisioningState"
331
+
```
332
+
333
+
# [PowerShell](#tab/powershell)
334
+
335
+
```powershell
336
+
az containerapp update `
337
+
--name $CONTAINER_APP_NAME`
338
+
--resource-group $RESOURCE_GROUP`
339
+
--yaml app.yaml `
340
+
--query "properties.provisioningState"
341
+
```
342
+
343
+
After updating the container app, the command returns a `Succeeded` message. Then you can view your Application Insights inthe Azure portal to verify that your container app is connected.
344
+
341
345
## Clean up resources
342
346
343
-
The resources created in this tutorial contribute to your Azure bill. If you aren't going to keep them in the long term, run the following commands to clean them up.
347
+
The resource group you created in this tutorial contributes to your Azure bill. If you aren't going to need it in the long term, use the following command to remove it:
344
348
345
349
# [Bash](#tab/bash)
350
+
346
351
```bash
347
352
az group delete --resource-group $RESOURCE_GROUP
348
353
```
354
+
349
355
# [PowerShell](#tab/powershell)
350
356
```powershell
351
357
az group delete --resource-group $RESOURCE_GROUP
352
358
```
353
359
354
-
---
355
-
356
360
## Other APM solutions
357
361
358
362
Other than [Azure Application Insights](/azure/azure-monitor/app/java-standalone-config), there are other popular APM solutions in the community. If you want to integrate your Azure Container App with other APM providers, just replace the Java agent JAR and related config files.
0 commit comments