awslabs.cloudwatch-applicationsignals-mcp-server 0.1.21__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- awslabs/__init__.py +17 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/__init__.py +17 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/audit_presentation_utils.py +288 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/audit_utils.py +912 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/aws_clients.py +120 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/canary_utils.py +910 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ec2/ec2-dotnet-enablement.md +435 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ec2/ec2-java-enablement.md +321 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ec2/ec2-nodejs-enablement.md +420 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ec2/ec2-python-enablement.md +598 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ecs/ecs-dotnet-enablement.md +264 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ecs/ecs-java-enablement.md +193 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ecs/ecs-nodejs-enablement.md +198 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/ecs/ecs-python-enablement.md +236 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/eks/eks-dotnet-enablement.md +166 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/eks/eks-java-enablement.md +166 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/eks/eks-nodejs-enablement.md +166 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/eks/eks-python-enablement.md +169 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/lambda/lambda-dotnet-enablement.md +336 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/lambda/lambda-java-enablement.md +336 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/lambda/lambda-nodejs-enablement.md +336 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_guides/templates/lambda/lambda-python-enablement.md +336 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/enablement_tools.py +147 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/server.py +1505 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/service_audit_utils.py +231 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/service_tools.py +659 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/sli_report_client.py +333 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/slo_tools.py +386 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/trace_tools.py +784 -0
- awslabs/cloudwatch_applicationsignals_mcp_server/utils.py +172 -0
- awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/METADATA +808 -0
- awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/RECORD +36 -0
- awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/WHEEL +4 -0
- awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/entry_points.txt +2 -0
- awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/licenses/LICENSE +174 -0
- awslabs_cloudwatch_applicationsignals_mcp_server-0.1.21.dist-info/licenses/NOTICE +2 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# Task: Enable AWS Application Signals for Python on ECS
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
This guide provides complete steps to enable AWS Application Signals for ECS Fargate services, distributed tracing, performance monitoring, and service mapping.
|
|
5
|
+
|
|
6
|
+
## Prerequisites
|
|
7
|
+
- Services running on ECS both the ec2 and Fargate launch types.
|
|
8
|
+
- Applications using Python language
|
|
9
|
+
|
|
10
|
+
## Implementation Steps
|
|
11
|
+
|
|
12
|
+
**Constraints:**
|
|
13
|
+
You must strictly follow the steps in the order below, do not skip or combine steps.
|
|
14
|
+
|
|
15
|
+
### Step 1: Setup CloudWatch Agent Task
|
|
16
|
+
When running in ECS, the CloudWatch Agent is deployed as a sidecar container next to the application container.
|
|
17
|
+
Proper permissions, a CWAgentConfig configuration file, and the target log group must be set up to enable logging and metrics collection.
|
|
18
|
+
|
|
19
|
+
#### 1.1 Add CloudWatch Agent Permissions to ECS Task Role
|
|
20
|
+
|
|
21
|
+
Update ECS task role to add CloudWatchAgentServerPolicy:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
// Update existing taskRole or create new one
|
|
25
|
+
const taskRole = new iam.Role(this, 'EcsTaskRole', {
|
|
26
|
+
assumedBy: new iam.ServicePrincipal('ecs-tasks.amazonaws.com'),
|
|
27
|
+
managedPolicies: [
|
|
28
|
+
iam.ManagedPolicy.fromAwsManagedPolicyName('AWSXRayDaemonWriteAccess'),
|
|
29
|
+
iam.ManagedPolicy.fromAwsManagedPolicyName('CloudWatchAgentServerPolicy'),
|
|
30
|
+
],
|
|
31
|
+
inlinePolicies: {
|
|
32
|
+
// Your existing inline policies...
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
#### 1.2 Create CloudWatch Agent Log Group
|
|
38
|
+
```typescript
|
|
39
|
+
const cwAgentLogGroup = new logs.LogGroup(this, 'CwAgentLogGroup', {
|
|
40
|
+
logGroupName: '/ecs/ecs-cwagent',
|
|
41
|
+
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
42
|
+
retention: logs.RetentionDays.ONE_WEEK,
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
#### 1.3 Add CloudWatch Agent Container to Each Task Definition
|
|
47
|
+
```typescript
|
|
48
|
+
// Add CloudWatch Agent sidecar to each task definition
|
|
49
|
+
const cwAgentContainer = taskDefinition.addContainer('ecs-cwagent-{SERVICE_NAME}', {
|
|
50
|
+
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest'),
|
|
51
|
+
essential: false,
|
|
52
|
+
memoryReservationMiB: 128,
|
|
53
|
+
cpu: 64,
|
|
54
|
+
environment: {
|
|
55
|
+
CW_CONFIG_CONTENT: JSON.stringify({
|
|
56
|
+
"traces": {
|
|
57
|
+
"traces_collected": {
|
|
58
|
+
"application_signals": {}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"logs": {
|
|
62
|
+
"metrics_collected": {
|
|
63
|
+
"application_signals": {}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}),
|
|
67
|
+
},
|
|
68
|
+
logging: ecs.LogDrivers.awsLogs({
|
|
69
|
+
streamPrefix: 'ecs',
|
|
70
|
+
logGroup: cwAgentLogGroup,
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Step 2: Add AWS Distro of OpenTelemetry Zero-Code Instrumentation to Main Service
|
|
76
|
+
|
|
77
|
+
#### 2.1 Add Bind Mount Volumes to Task Definition
|
|
78
|
+
```typescript
|
|
79
|
+
const taskDefinition = new ecs.FargateTaskDefinition(this, '{SERVICE_NAME}TaskDefinition', {
|
|
80
|
+
// Existing configuration...
|
|
81
|
+
volumes: [
|
|
82
|
+
{
|
|
83
|
+
name: "opentelemetry-auto-instrumentation-python"
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### 2.2 Add ADOT Auto-instrumentation Init Container
|
|
90
|
+
```typescript
|
|
91
|
+
const initContainer = taskDefinition.addContainer('init', {
|
|
92
|
+
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/aws-observability/adot-autoinstrumentation-python:v0.12.0'),
|
|
93
|
+
essential: false,
|
|
94
|
+
memoryReservationMiB: 64,
|
|
95
|
+
cpu: 32,
|
|
96
|
+
command: ['cp', '-a', '/autoinstrumentation/.', '/otel-auto-instrumentation-python'],
|
|
97
|
+
logging: ecs.LogDrivers.awsLogs({
|
|
98
|
+
streamPrefix: 'init-{SERVICE_NAME}',
|
|
99
|
+
logGroup: serviceLogGroup,
|
|
100
|
+
}),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Add mount point to init container
|
|
104
|
+
initContainer.addMountPoints({
|
|
105
|
+
sourceVolume: 'opentelemetry-auto-instrumentation-python',
|
|
106
|
+
containerPath: '/otel-auto-instrumentation-python',
|
|
107
|
+
readOnly: false,
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### 2.3 Configure Main Application Container OpenTelemetry Environment Variables
|
|
112
|
+
|
|
113
|
+
##### Python Application Configuration:
|
|
114
|
+
```typescript
|
|
115
|
+
const mainContainer = taskDefinition.addContainer('{SERVICE_NAME}-container', {
|
|
116
|
+
// Existing configuration...
|
|
117
|
+
environment: {
|
|
118
|
+
// Existing environment variables...
|
|
119
|
+
|
|
120
|
+
// ADOT Configuration for Application Signals
|
|
121
|
+
OTEL_RESOURCE_ATTRIBUTES: 'service.name=${SERVICE_NAME}', // SERVICE_NAME is defined by user
|
|
122
|
+
OTEL_METRICS_EXPORTER: 'none',
|
|
123
|
+
OTEL_LOGS_EXPORTER: 'none',
|
|
124
|
+
PYTHONPATH: '/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation:$APP_PATH:/otel-auto-instrumentation-python',
|
|
125
|
+
OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED: 'true',
|
|
126
|
+
OTEL_TRACES_EXPORTER: 'otlp',
|
|
127
|
+
OTEL_EXPORTER_OTLP_PROTOCOL: 'http/protobuf',
|
|
128
|
+
OTEL_PYTHON_DISTRO: 'aws_distro',
|
|
129
|
+
OTEL_PYTHON_CONFIGURATOR: 'aws_configurator',
|
|
130
|
+
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: 'http://localhost:4316/v1/traces',
|
|
131
|
+
OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT: 'http://localhost:4316/v1/metrics',
|
|
132
|
+
OTEL_AWS_APPLICATION_SIGNALS_ENABLED: 'true',
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
If there is PYTHONPATH in container definition, APP_PATH is the existing PYTHONPATH value,
|
|
137
|
+
else no need APP_PATH, PYTHONPATH: '/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation-python'
|
|
138
|
+
|
|
139
|
+
#### 2.4 Add Mount Point to Main Container
|
|
140
|
+
```typescript
|
|
141
|
+
// Add mount point to main application container
|
|
142
|
+
mainContainer.addMountPoints({
|
|
143
|
+
sourceVolume: 'opentelemetry-auto-instrumentation-python',
|
|
144
|
+
containerPath: '/otel-auto-instrumentation-python',
|
|
145
|
+
readOnly: false,
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
#### 2.5 Configure Container Dependencies
|
|
150
|
+
```typescript
|
|
151
|
+
// Ensure containers start in correct order
|
|
152
|
+
mainContainer.addContainerDependencies({
|
|
153
|
+
container: initContainer,
|
|
154
|
+
condition: ecs.ContainerDependencyCondition.SUCCESS,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
mainContainer.addContainerDependencies({
|
|
158
|
+
container: cwAgentContainer,
|
|
159
|
+
condition: ecs.ContainerDependencyCondition.START,
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Step 3: Apply Python Framework–Specific Changes
|
|
164
|
+
Depending on the Python web framework your application uses, additional configuration may be required to ensure OpenTelemetry zero-code instrumentation initializes correctly.
|
|
165
|
+
|
|
166
|
+
#### 3.a: Django-Specific Configuration
|
|
167
|
+
Django applications may require additional settings to work seamlessly with OpenTelemetry zero-code instrumentation. These adjustments ensure that Django initializes with the correct configuration。
|
|
168
|
+
|
|
169
|
+
#### 3.a.1: set DJANGO_SETTINGS_MODULE
|
|
170
|
+
If your ECS application is built with Django, explicitly set the DJANGO_SETTINGS_MODULE environment variable in the container definition to ensure correct initialization during OpenTelemetry zero-code instrumentation.
|
|
171
|
+
```typescript
|
|
172
|
+
const mainContainer = taskDefinition.addContainer('{SERVICE_NAME}-container', {
|
|
173
|
+
// Existing configuration...
|
|
174
|
+
environment: {
|
|
175
|
+
// Existing environment variables...
|
|
176
|
+
|
|
177
|
+
// Ensure Django settings module is explicitly defined
|
|
178
|
+
DJANGO_SETTINGS_MODULE: {{your django settings}}
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
#### 3.a.2: Add --noreload When Using Django’s Development Server
|
|
184
|
+
If you are using Django’s development server, override the Docker CMD in your ECS container definition by adding the --noreload flag. This prevents startup failures caused by conflicts between Django’s auto-reloader and OpenTelemetry instrumentation.
|
|
185
|
+
Skip this step if you run Django in production with a WSGI or ASGI server (e.g., Gunicorn, Uvicorn, Daphne).
|
|
186
|
+
|
|
187
|
+
**Before (Dockerfile):**
|
|
188
|
+
```dockerfile
|
|
189
|
+
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**After (ECS IaC override):**
|
|
193
|
+
```typescript
|
|
194
|
+
Const appContainer = taskDefinition.addContainer('Application', {
|
|
195
|
+
// Override Dockerfile CMD to include "--noreload"
|
|
196
|
+
command: ["python", "manage.py", "runserver", "0.0.0.0:8000", "--noreload"],
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
## Completion
|
|
202
|
+
|
|
203
|
+
**Tell the user:**
|
|
204
|
+
|
|
205
|
+
"I've completed the Application Signals enablement for your application. Here's what I modified:
|
|
206
|
+
|
|
207
|
+
**Files Changed:**
|
|
208
|
+
- IAM role: Added CloudWatchAgentServerPolicy
|
|
209
|
+
- ECS container: Installed and configured CloudWatch Agent as sidecar
|
|
210
|
+
- ADOT SDK container: Mounted ADOT SDK dependencies into Application container
|
|
211
|
+
- Applicaiton container: Enabled zero-code instrumentation for Application
|
|
212
|
+
|
|
213
|
+
**Next Steps:**
|
|
214
|
+
1. Ensure that [Application Signals is enabled in AWS account](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable.html).
|
|
215
|
+
This is a one-time setup; if already enabled, you can skip this step.
|
|
216
|
+
2. Review the changes I made using `git diff`
|
|
217
|
+
3. Deploy your infrastructure:
|
|
218
|
+
- For CDK: `cdk deploy`
|
|
219
|
+
- For Terraform: `terraform apply`
|
|
220
|
+
- For CloudFormation: Deploy your stack
|
|
221
|
+
4. After deployment, wait 5-10 minutes for telemetry data to start flowing
|
|
222
|
+
|
|
223
|
+
**Verification:**
|
|
224
|
+
Once deployed, you can verify Application Signals is working by:
|
|
225
|
+
- Opening the AWS CloudWatch Console
|
|
226
|
+
- Navigating to Application Signals → Services
|
|
227
|
+
- Looking for your service (named: {{SERVICE_NAME}})
|
|
228
|
+
- Checking that traces and metrics are being collected
|
|
229
|
+
|
|
230
|
+
**Monitor Application Health:**
|
|
231
|
+
After enablement, you can monitor your application's operational health using Application Signals dashboards. For more information, see [Monitor the operational health of your applications with Application Signals](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Services.html).
|
|
232
|
+
|
|
233
|
+
**Troubleshooting**
|
|
234
|
+
If you encounter any other issues, refer to the [CloudWatch APM troubleshooting guide](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable-Troubleshoot.html).
|
|
235
|
+
|
|
236
|
+
Let me know if you'd like me to make any adjustments before you deploy!"
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Task: Enable AWS Application Signals for .NET Applications on Amazon EKS
|
|
2
|
+
|
|
3
|
+
This guide shows how to modify the existing CDK and Terraform infrastructure code to enable AWS Application Signals for .NET applications running on Amazon EKS.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Application Signals enabled in your AWS account (see [Enable Application Signals in your account](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable.html))
|
|
8
|
+
- Existing EKS cluster deployed using the provided CDK or Terraform code
|
|
9
|
+
- .NET application containerized and pushed to ECR
|
|
10
|
+
- AWS CLI configured with appropriate permissions
|
|
11
|
+
|
|
12
|
+
## Critical Requirements
|
|
13
|
+
|
|
14
|
+
**Error Handling:**
|
|
15
|
+
- If you cannot determine required values from the IaC, STOP and ask the user
|
|
16
|
+
- For multiple EC2 instances, ask which one(s) to modify
|
|
17
|
+
- Preserve all existing UserData commands; add new ones in sequence
|
|
18
|
+
|
|
19
|
+
**Do NOT:**
|
|
20
|
+
- Run deployment commands automatically (`cdk deploy`, `terraform apply`, etc.)
|
|
21
|
+
- Remove existing application startup logic
|
|
22
|
+
- Skip the user approval step before deployment
|
|
23
|
+
|
|
24
|
+
## CDK Implementation
|
|
25
|
+
|
|
26
|
+
### 1. Install CloudWatch Observability Add-on
|
|
27
|
+
|
|
28
|
+
Create an IAM role and install the CloudWatch Observability add-on:
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import * as eks from 'aws-cdk-lib/aws-eks';
|
|
32
|
+
import * as iam from 'aws-cdk-lib/aws-iam';
|
|
33
|
+
|
|
34
|
+
// Create IAM role for CloudWatch agent
|
|
35
|
+
const cloudwatchRole = new iam.Role(this, 'CloudWatchAgentAddOnRole', {
|
|
36
|
+
assumedBy: new iam.OpenIdConnectPrincipal(cluster.openIdConnectProvider),
|
|
37
|
+
managedPolicies: [
|
|
38
|
+
iam.ManagedPolicy.fromAwsManagedPolicyName('CloudWatchAgentServerPolicy')
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Install the CloudWatch Observability add-on
|
|
43
|
+
new eks.CfnAddon(this, 'CloudWatchAddon', {
|
|
44
|
+
addonName: 'amazon-cloudwatch-observability',
|
|
45
|
+
clusterName: cluster.clusterName,
|
|
46
|
+
serviceAccountRoleArn: cloudwatchRole.roleArn
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 2. Add .NET Instrumentation Annotation
|
|
51
|
+
|
|
52
|
+
Update your deployment template metadata to include the .NET instrumentation annotation:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
template: {
|
|
56
|
+
metadata: {
|
|
57
|
+
labels: { app: config.appName },
|
|
58
|
+
annotations: {
|
|
59
|
+
'instrumentation.opentelemetry.io/inject-dotnet': 'true'
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
// ... rest of your template configuration
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Terraform Implementation
|
|
67
|
+
|
|
68
|
+
### 1. Add CloudWatch Agent IAM Permissions
|
|
69
|
+
|
|
70
|
+
Add the CloudWatch policy to the node role:
|
|
71
|
+
|
|
72
|
+
```hcl
|
|
73
|
+
# Additional IAM policies for Application Signals
|
|
74
|
+
resource "aws_iam_role_policy_attachment" "cloudwatch_agent_policy" {
|
|
75
|
+
policy_arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
|
|
76
|
+
role = aws_iam_role.node_role.name
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Important:** Add this policy attachment to your node group's `depends_on` block:
|
|
81
|
+
|
|
82
|
+
```hcl
|
|
83
|
+
resource "aws_eks_node_group" "app_nodes" {
|
|
84
|
+
# ... existing configuration ...
|
|
85
|
+
|
|
86
|
+
depends_on = [
|
|
87
|
+
aws_iam_role_policy_attachment.node_policy,
|
|
88
|
+
aws_iam_role_policy_attachment.cloudwatch_agent_policy
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 2. Install CloudWatch Observability Add-on
|
|
94
|
+
|
|
95
|
+
Add the CloudWatch Observability EKS add-on:
|
|
96
|
+
|
|
97
|
+
```hcl
|
|
98
|
+
# CloudWatch Observability Add-on
|
|
99
|
+
resource "aws_eks_addon" "cloudwatch_observability" {
|
|
100
|
+
cluster_name = aws_eks_cluster.app_cluster.name
|
|
101
|
+
addon_name = "amazon-cloudwatch-observability"
|
|
102
|
+
|
|
103
|
+
depends_on = [
|
|
104
|
+
aws_eks_node_group.app_nodes
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 3. Add .NET Instrumentation Annotation
|
|
110
|
+
|
|
111
|
+
Update your Kubernetes deployment template to include the .NET instrumentation annotation:
|
|
112
|
+
|
|
113
|
+
```hcl
|
|
114
|
+
template {
|
|
115
|
+
metadata {
|
|
116
|
+
labels = {
|
|
117
|
+
app = var.app_name
|
|
118
|
+
}
|
|
119
|
+
annotations = {
|
|
120
|
+
"instrumentation.opentelemetry.io/inject-dotnet" = "true"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
# ... rest of your template configuration
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Important Notes
|
|
128
|
+
|
|
129
|
+
- The .NET instrumentation annotation will cause pods to restart automatically
|
|
130
|
+
- .NET applications require .NET 6.0 or later for Application Signals support
|
|
131
|
+
- It may take a few minutes for data to appear in the Application Signals console after deployment
|
|
132
|
+
|
|
133
|
+
## Completion
|
|
134
|
+
|
|
135
|
+
**Tell the user:**
|
|
136
|
+
|
|
137
|
+
"I've completed the Application Signals enablement for your .NET application. Here's what I modified:
|
|
138
|
+
|
|
139
|
+
**Files Changed:**
|
|
140
|
+
- IAM role: Added CloudWatchAgentServerPolicy
|
|
141
|
+
- CloudWatch Observability EKS add-on: Added to the EKS Cluster
|
|
142
|
+
- Kubernetes Deployment: Instrumentation annotation added with inject-dotnet set to true
|
|
143
|
+
|
|
144
|
+
**Next Steps:**
|
|
145
|
+
1. Ensure that [Application Signals is enabled in AWS account](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable.html).
|
|
146
|
+
2. Review the changes I made using `git diff`
|
|
147
|
+
3. Deploy your infrastructure:
|
|
148
|
+
- For CDK: `cdk deploy`
|
|
149
|
+
- For Terraform: `terraform apply`
|
|
150
|
+
- For CloudFormation: Deploy your stack
|
|
151
|
+
4. After deployment, wait 5-10 minutes for telemetry data to start flowing
|
|
152
|
+
|
|
153
|
+
**Verification:**
|
|
154
|
+
Once deployed, you can verify Application Signals is working by:
|
|
155
|
+
- Opening the AWS CloudWatch Console
|
|
156
|
+
- Navigating to Application Signals → Services
|
|
157
|
+
- Looking for your service (named: {{SERVICE_NAME}})
|
|
158
|
+
- Checking that traces and metrics are being collected
|
|
159
|
+
|
|
160
|
+
**Monitor Application Health:**
|
|
161
|
+
After enablement, you can monitor your application's operational health using Application Signals dashboards. For more information, see [Monitor the operational health of your applications with Application Signals](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Services.html).
|
|
162
|
+
|
|
163
|
+
**Troubleshooting**
|
|
164
|
+
If you encounter any other issues, refer to the [CloudWatch APM troubleshooting guide](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable-Troubleshoot.html).
|
|
165
|
+
|
|
166
|
+
Let me know if you'd like me to make any adjustments before you deploy!"
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Task: Enable AWS Application Signals for Java Applications on Amazon EKS
|
|
2
|
+
|
|
3
|
+
This guide shows how to modify the existing CDK and Terraform infrastructure code to enable AWS Application Signals for Java applications running on Amazon EKS.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Application Signals enabled in your AWS account (see [Enable Application Signals in your account](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable.html))
|
|
8
|
+
- Existing EKS cluster deployed using the provided CDK or Terraform code
|
|
9
|
+
- Java application containerized and pushed to ECR
|
|
10
|
+
- AWS CLI configured with appropriate permissions
|
|
11
|
+
|
|
12
|
+
## Critical Requirements
|
|
13
|
+
|
|
14
|
+
**Error Handling:**
|
|
15
|
+
- If you cannot determine required values from the IaC, STOP and ask the user
|
|
16
|
+
- For multiple EC2 instances, ask which one(s) to modify
|
|
17
|
+
- Preserve all existing UserData commands; add new ones in sequence
|
|
18
|
+
|
|
19
|
+
**Do NOT:**
|
|
20
|
+
- Run deployment commands automatically (`cdk deploy`, `terraform apply`, etc.)
|
|
21
|
+
- Remove existing application startup logic
|
|
22
|
+
- Skip the user approval step before deployment
|
|
23
|
+
|
|
24
|
+
## CDK Implementation
|
|
25
|
+
|
|
26
|
+
### 1. Install CloudWatch Observability Add-on
|
|
27
|
+
|
|
28
|
+
Create an IAM role and install the CloudWatch Observability add-on:
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import * as eks from 'aws-cdk-lib/aws-eks';
|
|
32
|
+
import * as iam from 'aws-cdk-lib/aws-iam';
|
|
33
|
+
|
|
34
|
+
// Create IAM role for CloudWatch agent
|
|
35
|
+
const cloudwatchRole = new iam.Role(this, 'CloudWatchAgentAddOnRole', {
|
|
36
|
+
assumedBy: new iam.OpenIdConnectPrincipal(cluster.openIdConnectProvider),
|
|
37
|
+
managedPolicies: [
|
|
38
|
+
iam.ManagedPolicy.fromAwsManagedPolicyName('CloudWatchAgentServerPolicy')
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Install the CloudWatch Observability add-on
|
|
43
|
+
new eks.CfnAddon(this, 'CloudWatchAddon', {
|
|
44
|
+
addonName: 'amazon-cloudwatch-observability',
|
|
45
|
+
clusterName: cluster.clusterName,
|
|
46
|
+
serviceAccountRoleArn: cloudwatchRole.roleArn
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 2. Add Java Instrumentation Annotation
|
|
51
|
+
|
|
52
|
+
Update your deployment template metadata to include the Java instrumentation annotation:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
template: {
|
|
56
|
+
metadata: {
|
|
57
|
+
labels: { app: config.appName },
|
|
58
|
+
annotations: {
|
|
59
|
+
'instrumentation.opentelemetry.io/inject-java': 'true'
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
// ... rest of your template configuration
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Terraform Implementation
|
|
67
|
+
|
|
68
|
+
### 1. Add CloudWatch Agent IAM Permissions
|
|
69
|
+
|
|
70
|
+
Add the CloudWatch policy to the node role:
|
|
71
|
+
|
|
72
|
+
```hcl
|
|
73
|
+
# Additional IAM policies for Application Signals
|
|
74
|
+
resource "aws_iam_role_policy_attachment" "cloudwatch_agent_policy" {
|
|
75
|
+
policy_arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
|
|
76
|
+
role = aws_iam_role.node_role.name
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Important:** Add this policy attachment to your node group's `depends_on` block:
|
|
81
|
+
|
|
82
|
+
```hcl
|
|
83
|
+
resource "aws_eks_node_group" "app_nodes" {
|
|
84
|
+
# ... existing configuration ...
|
|
85
|
+
|
|
86
|
+
depends_on = [
|
|
87
|
+
aws_iam_role_policy_attachment.node_policy,
|
|
88
|
+
aws_iam_role_policy_attachment.cloudwatch_agent_policy
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 2. Install CloudWatch Observability Add-on
|
|
94
|
+
|
|
95
|
+
Add the CloudWatch Observability EKS add-on:
|
|
96
|
+
|
|
97
|
+
```hcl
|
|
98
|
+
# CloudWatch Observability Add-on
|
|
99
|
+
resource "aws_eks_addon" "cloudwatch_observability" {
|
|
100
|
+
cluster_name = aws_eks_cluster.app_cluster.name
|
|
101
|
+
addon_name = "amazon-cloudwatch-observability"
|
|
102
|
+
|
|
103
|
+
depends_on = [
|
|
104
|
+
aws_eks_node_group.app_nodes
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 3. Add Java Instrumentation Annotation
|
|
110
|
+
|
|
111
|
+
Update your Kubernetes deployment template to include the Java instrumentation annotation:
|
|
112
|
+
|
|
113
|
+
```hcl
|
|
114
|
+
template {
|
|
115
|
+
metadata {
|
|
116
|
+
labels = {
|
|
117
|
+
app = var.app_name
|
|
118
|
+
}
|
|
119
|
+
annotations = {
|
|
120
|
+
"instrumentation.opentelemetry.io/inject-java" = "true"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
# ... rest of your template configuration
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Important Notes
|
|
128
|
+
|
|
129
|
+
- The Java instrumentation annotation will cause pods to restart automatically
|
|
130
|
+
- Java applications typically have faster startup times with Application Signals compared to other languages
|
|
131
|
+
- It may take a few minutes for data to appear in the Application Signals console after deployment
|
|
132
|
+
|
|
133
|
+
## Completion
|
|
134
|
+
|
|
135
|
+
**Tell the user:**
|
|
136
|
+
|
|
137
|
+
"I've completed the Application Signals enablement for your Java application. Here's what I modified:
|
|
138
|
+
|
|
139
|
+
**Files Changed:**
|
|
140
|
+
- IAM role: Added CloudWatchAgentServerPolicy
|
|
141
|
+
- CloudWatch Observability EKS add-on: Added to the EKS Cluster
|
|
142
|
+
- Kubernetes Deployment: Instrumentation annotation added with inject-java set to true
|
|
143
|
+
|
|
144
|
+
**Next Steps:**
|
|
145
|
+
1. Ensure that [Application Signals is enabled in AWS account](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable.html).
|
|
146
|
+
2. Review the changes I made using `git diff`
|
|
147
|
+
3. Deploy your infrastructure:
|
|
148
|
+
- For CDK: `cdk deploy`
|
|
149
|
+
- For Terraform: `terraform apply`
|
|
150
|
+
- For CloudFormation: Deploy your stack
|
|
151
|
+
4. After deployment, wait 5-10 minutes for telemetry data to start flowing
|
|
152
|
+
|
|
153
|
+
**Verification:**
|
|
154
|
+
Once deployed, you can verify Application Signals is working by:
|
|
155
|
+
- Opening the AWS CloudWatch Console
|
|
156
|
+
- Navigating to Application Signals → Services
|
|
157
|
+
- Looking for your service (named: {{SERVICE_NAME}})
|
|
158
|
+
- Checking that traces and metrics are being collected
|
|
159
|
+
|
|
160
|
+
**Monitor Application Health:**
|
|
161
|
+
After enablement, you can monitor your application's operational health using Application Signals dashboards. For more information, see [Monitor the operational health of your applications with Application Signals](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Services.html).
|
|
162
|
+
|
|
163
|
+
**Troubleshooting**
|
|
164
|
+
If you encounter any other issues, refer to the [CloudWatch APM troubleshooting guide](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable-Troubleshoot.html).
|
|
165
|
+
|
|
166
|
+
Let me know if you'd like me to make any adjustments before you deploy!"
|