|
15 | 15 |
|
16 | 16 | <!--END STABILITY BANNER-->
|
17 | 17 |
|
18 |
| -<!--BEGIN STABILITY BANNER--> |
19 |
| - |
20 |
| ---- |
21 |
| - |
22 |
| - |
23 |
| - |
24 |
| -> The APIs of higher level constructs in this module are experimental and under active development. |
25 |
| -> They are subject to non-backward compatible changes or removal in any future version. These are |
26 |
| -> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be |
27 |
| -> announced in the release notes. This means that while you may use them, you may need to update |
28 |
| -> your source code when upgrading to a newer version of this package. |
29 |
| -
|
30 |
| ---- |
31 |
| - |
32 |
| -## Application Signals |
33 |
| - |
34 | 18 | CloudWatch Application Signals is an auto-instrumentation solution built on OpenTelemetry that enables zero-code collection of monitoring data, such
|
35 |
| -as traces and metrics, from applications running across multiple platforms. It also supports topology auto-discovery based on collected monitoring |
36 |
| -data and includes a new feature for managing service-level objectives (SLOs). |
| 19 | +as traces and metrics, from applications running across multiple platforms. It also supports topology auto-discovery based on collected monitoring data |
| 20 | +and includes a new feature for managing service-level objectives (SLOs). |
37 | 21 |
|
38 | 22 | It supports Java, Python, .NET, and Node.js on platforms including EKS (and native Kubernetes), Lambda, ECS, and EC2. For more details, visit
|
39 | 23 | [Application Signals](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Monitoring-Sections.html) on the AWS
|
40 | 24 | public website.
|
41 | 25 |
|
42 |
| -## Application Signals L2 CDK for enablement |
| 26 | +## Application Signals Enablement L2 Constructs |
43 | 27 |
|
44 |
| -This module is a collection of L2 constructs which leverages native L1 CFN resources, simplifying the enablement steps and the creation of Application |
| 28 | +A collection of L2 constructs which leverages native L1 CFN resources, simplifying the enablement steps and the creation of Application |
45 | 29 | Signals resources.
|
46 | 30 |
|
47 |
| -This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) project. |
48 |
| - |
49 |
| -```ts nofixture |
50 |
| -import * as appsignals from '@aws-cdk/aws-applicationsignals-alpha'; |
51 |
| -``` |
52 |
| - |
53 | 31 | ### ApplicationSignalsIntegration
|
54 | 32 |
|
55 | 33 | `ApplicationSignalsIntegration` aims to address key challenges in the current CDK enablement process, which requires complex manual configurations for
|
56 | 34 | ECS customers. Application Signals is designed to be flexible and is supported for other platforms as well. However, the initial focus is on supporting
|
57 | 35 | ECS, with plans to potentially extend support to other platforms in the future.
|
58 | 36 |
|
59 |
| -#### 1. Enable Application Signals on ECS with sidecar mode |
60 |
| - |
61 |
| -##### 1.1. Create a TaskDefinition for application |
62 |
| - |
63 |
| -```ts |
64 |
| -import * as ecs from 'aws-cdk-lib/aws-ecs'; |
65 |
| - |
66 |
| -const fargateTaskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDefinition', { |
67 |
| - taskRole: taskRole, |
68 |
| - cpu: 2048, |
69 |
| - memoryLimitMiB: 4096 |
70 |
| -}); |
71 |
| - |
72 |
| -fargateTaskDefinition.addContainer('app', { |
73 |
| - image: ..., |
74 |
| - ... |
75 |
| -}); |
76 |
| -``` |
77 |
| - |
78 |
| -##### 1.2. Configure ApplicationSignalsIntegration |
79 |
| - |
80 |
| -Key steps: |
| 37 | +#### Enable Application Signals on ECS with sidecar mode |
81 | 38 |
|
82 | 39 | 1. Configure `instrumentation` to instrument the application with the ADOT Java Agent.
|
83 | 40 | 2. Setting `enableSidecar` to true to add the CloudWatch Agent as a sidecar container.
|
84 | 41 |
|
85 | 42 | ```ts
|
86 |
| -new appsignals.ApplicationSignalsIntegration(this, 'ApplicationSignalsIntegration', { |
87 |
| - taskDefinition, |
88 |
| - instrumentation: { |
89 |
| - language: appsignals.InstrumentationLanguage.JAVA, |
90 |
| - sdkVersion: appsignals.JavaInstrumentationVersion.V1_32_6 |
91 |
| - }, |
92 |
| - serviceName: 'sample-app', |
93 |
| - cloudWatchAgent: { |
94 |
| - enableSidecar: true, |
95 |
| - } |
96 |
| -}); |
| 43 | +import { Construct } from 'constructs'; |
| 44 | +import * as appsignals from '@aws-cdk/aws-applicationsignals-alpha'; |
| 45 | +import * as cdk from 'aws-cdk-lib'; |
| 46 | +import * as ecs from 'aws-cdk-lib/aws-ecs'; |
| 47 | + |
| 48 | +class MyStack extends cdk.Stack { |
| 49 | + public constructor(scope?: Construct, id?: string, props: cdk.StackProps = {}) { |
| 50 | + super(); |
| 51 | + const fargateTaskDefinition = new ecs.FargateTaskDefinition(this, 'FargateTaskDefinition', { |
| 52 | + cpu: 2048, |
| 53 | + memoryLimitMiB: 4096 |
| 54 | + }); |
| 55 | + |
| 56 | + fargateTaskDefinition.addContainer('app', { |
| 57 | + image: ecs.ContainerImage.fromRegistry('test/sample-app'), |
| 58 | + }); |
| 59 | + |
| 60 | + new appsignals.ApplicationSignalsIntegration(this, 'ApplicationSignalsIntegration', { |
| 61 | + taskDefinition: fargateTaskDefinition, |
| 62 | + instrumentation: { |
| 63 | + sdkVersion: appsignals.JavaInstrumentationVersion.V1_32_6 |
| 64 | + }, |
| 65 | + serviceName: 'sample-app', |
| 66 | + cloudWatchAgent: { |
| 67 | + enableSidecar: true, |
| 68 | + } |
| 69 | + }); |
| 70 | + } |
| 71 | +} |
97 | 72 | ```
|
98 | 73 |
|
99 |
| -#### 2. Enable Application Signals on ECS with daemon mode |
| 74 | +#### Enable Application Signals on ECS with daemon mode |
100 | 75 |
|
101 | 76 | Note: Since the daemon deployment strategy is not supported on ECS Fargate, this mode is only supported on ECS on EC2.
|
102 | 77 |
|
103 |
| -##### 2.1. Run CloudWatch Agent as a daemon service |
| 78 | +1. Run CloudWatch Agent as a daemon service with service connect. |
| 79 | +1. Configure `instrumentation` to instrument the application with the ADOT Python Agent. |
| 80 | +1. Set `enableSidecar` to false to disable running CloudWatch agent as a sidecar. |
| 81 | +1. Override environment variables by configuring `overrideEnvironments` to use service connect endpoints to communicate to the CloudWatch agent server |
104 | 82 |
|
105 | 83 | ```ts
|
| 84 | +import { Construct } from 'constructs'; |
| 85 | +import * as appsignals from '@aws-cdk/aws-applicationsignals-alpha'; |
| 86 | +import * as cdk from 'aws-cdk-lib'; |
| 87 | +import * as ec2 from 'aws-cdk-lib/aws-ec2'; |
106 | 88 | import * as ecs from 'aws-cdk-lib/aws-ecs';
|
107 | 89 | import * as logs from 'aws-cdk-lib/aws-logs';
|
108 | 90 |
|
109 |
| -// Create a task definition for CloudWatch agent |
110 |
| -const cwAgentTaskDefinition = new ecs.Ec2TaskDefinition(this, 'CloudWatchAgentTaskDefinition'); |
111 |
| - |
112 |
| -// Add CloudWatch agent container |
113 |
| -const cwAgentContainer = cwAgentTaskDefinition.addContainer('ecs-cwagent', { |
114 |
| - image: ecs.ContainerImage.fromRegistry("public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest"), |
115 |
| - cpu: 128, |
116 |
| - memoryLimitMiB: 64, |
117 |
| - portMappings: [ |
118 |
| - { |
119 |
| - name: 'cwagent-4316', |
120 |
| - containerPort: 4316, |
121 |
| - hostPort: 4316, |
122 |
| - }, |
123 |
| - { |
124 |
| - name: 'cwagent-2000', |
125 |
| - containerPort: 2000, |
126 |
| - hostPort: 2000, |
127 |
| - }, |
128 |
| - ], |
129 |
| - logging: new ecs.AwsLogDriver({ |
| 91 | +class MyStack extends cdk.Stack { |
| 92 | + public constructor(scope?: Construct, id?: string, props: cdk.StackProps = {}) { |
| 93 | + super(scope, id, props); |
| 94 | + |
| 95 | + const vpc = new ec2.Vpc(this, 'TestVpc', {}); |
| 96 | + const cluster = new ecs.Cluster(this, 'TestCluster', { vpc }); |
| 97 | + // Create a task definition for CloudWatch agent |
| 98 | + const cwAgentTaskDefinition = new ecs.Ec2TaskDefinition(this, 'CloudWatchAgentTaskDefinition'); |
| 99 | + |
| 100 | + // Add CloudWatch agent container |
| 101 | + const cwAgentContainer = cwAgentTaskDefinition.addContainer('ecs-cwagent', { |
| 102 | + image: ecs.ContainerImage.fromRegistry("public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest"), |
| 103 | + cpu: 128, |
| 104 | + memoryLimitMiB: 64, |
| 105 | + portMappings: [ |
| 106 | + { |
| 107 | + name: 'cwagent-4316', |
| 108 | + containerPort: 4316, |
| 109 | + hostPort: 4316, |
| 110 | + }, |
| 111 | + { |
| 112 | + name: 'cwagent-2000', |
| 113 | + containerPort: 2000, |
| 114 | + hostPort: 2000, |
| 115 | + }, |
| 116 | + ], |
| 117 | + logging: new ecs.AwsLogDriver({ |
130 | 118 | streamPrefix: 'ecs',
|
131 | 119 | logGroup: new logs.LogGroup(this, 'CwAgentLogGroup', {
|
132 |
| - logGroupName: '/ecs/ecs-cwagent-cdk-daemon', |
133 |
| - removalPolicy: cdk.RemovalPolicy.DESTROY, |
| 120 | + logGroupName: '/ecs/ecs-cwagent-cdk-daemon', |
| 121 | + removalPolicy: cdk.RemovalPolicy.DESTROY, |
134 | 122 | }),
|
135 |
| - }), |
136 |
| - environment: { |
137 |
| - CW_CONFIG_CONTENT: '{"traces": {"traces_collected": {"application_signals": {}}}, "logs": {"metrics_collected":{"application_signals": {}}}}' |
138 |
| - } |
139 |
| -}); |
140 |
| - |
141 |
| -// Create the CloudWatch agent daemon service |
142 |
| -new ecs.Ec2Service(this, 'CloudWatchAgentDaemon', { |
143 |
| - cluster, |
144 |
| - taskDefinition: cwAgentTaskDefinition, |
145 |
| - daemon: true, // Runs one container per EC2 instance |
146 |
| - serviceConnectConfiguration: { // Create service connect |
147 |
| - namespace: namespace.namespaceArn, |
148 |
| - services: [{ |
149 |
| - portMappingName: 'cwagent-4316', |
150 |
| - dnsName: 'cwagent-4316-http', |
151 |
| - port: 4316 |
152 |
| - }, { |
153 |
| - portMappingName: 'cwagent-2000', |
154 |
| - dnsName: 'cwagent-2000-http', |
155 |
| - port: 2000 |
156 |
| - }] |
157 |
| - } |
158 |
| -}); |
159 |
| -``` |
160 |
| - |
161 |
| -##### 2.2. Create a TaskDefinition for application |
162 |
| - |
163 |
| -```ts |
164 |
| -import * as ecs from 'aws-cdk-lib/aws-ecs'; |
165 |
| - |
166 |
| -const ec2TaskDefinition = new ecs.Ec2TaskDefinition(this, 'EC2TaskDefinition', { |
167 |
| - taskRole: taskRole, |
168 |
| - ... |
169 |
| -}); |
170 |
| - |
171 |
| -ec2TaskDefinition.addContainer('app', { |
172 |
| - image: ..., |
173 |
| - ... |
174 |
| -}); |
175 |
| -``` |
176 |
| - |
177 |
| -##### 2.3. Configure ApplicationSignalsIntegration |
178 |
| - |
179 |
| -Key steps: |
180 |
| - |
181 |
| -1. Configure `instrumentation` to instrument the application with the ADOT Python Agent. |
182 |
| -2. Set `enableSidecar` to false to disable running CloudWatch agent as a sidecar. |
183 |
| -3. Override environment variables by configuring `overrideEnvironments` to use Service Connect to communicate to the CloudWatch agent server |
184 |
| - |
185 |
| -```ts |
186 |
| -new appsignals.ApplicationSignalsIntegration(this, 'ApplicationSignalsIntegration', ec2TaskDefinition, { |
187 |
| - instrumentation: { |
188 |
| - language: appsignals.InstrumentationLanguage.PYTHON, |
189 |
| - sdkVersion: appsignals.PythonInstrumentationVersion.V0_8_0 |
190 |
| - }, |
191 |
| - overrideEnvironments: [{ |
192 |
| - name: appsignals.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT, |
193 |
| - // overwrite the endpoint to point to the created Service Connect |
194 |
| - value: "http://cwagent-4316-http:4316/v1/metrics" |
195 |
| - }, { |
196 |
| - name: appsignals.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, |
197 |
| - // overwrite the endpoint to point to the created Service Connect |
198 |
| - value: "http://cwagent-4316-http:4316/v1/traces" |
199 |
| - }, { |
200 |
| - name: appsignals.TraceExporting.OTEL_TRACES_SAMPLER_ARG, |
201 |
| - // overwrite the endpoint to point to the created Service Connect |
202 |
| - value: "endpoint=http://cwagent-2000-http:2000" |
203 |
| - }], |
204 |
| - serviceName: 'sample-app', |
205 |
| - cloudWatchAgent: { |
206 |
| - // disable sidecar mode |
207 |
| - enableSidecar: false, |
| 123 | + }), |
| 124 | + environment: { |
| 125 | + CW_CONFIG_CONTENT: '{"traces":{"traces_collected":{"application_signals":{}}},"logs":{"metrics_collected":{"application_signals":{}}}}' |
| 126 | + } |
| 127 | + }); |
| 128 | + |
| 129 | + // Create the CloudWatch agent daemon service |
| 130 | + new ecs.Ec2Service(this, 'CloudWatchAgentDaemon', { |
| 131 | + cluster, |
| 132 | + taskDefinition: cwAgentTaskDefinition, |
| 133 | + daemon: true, // Runs one container per EC2 instance |
| 134 | + serviceConnectConfiguration: { |
| 135 | + namespace: 'namespace-arn', |
| 136 | + services: [ |
| 137 | + { |
| 138 | + portMappingName: 'cwagent-4316', |
| 139 | + dnsName: 'cwagent-4316-http', |
| 140 | + port: 4316 |
| 141 | + }, |
| 142 | + { |
| 143 | + portMappingName: 'cwagent-2000', |
| 144 | + dnsName: 'cwagent-2000-http', |
| 145 | + port: 2000 |
| 146 | + } |
| 147 | + ] |
| 148 | + } |
| 149 | + }); |
| 150 | + |
| 151 | + const ec2TaskDefinition = new ecs.Ec2TaskDefinition(this, 'Ec2TaskDefinition', { |
| 152 | + networkMode: ecs.NetworkMode.HOST, |
| 153 | + }); |
| 154 | + |
| 155 | + ec2TaskDefinition.addContainer('app', { |
| 156 | + image: ecs.ContainerImage.fromRegistry('test/sample-app'), |
| 157 | + cpu: 0, |
| 158 | + memoryLimitMiB: 512, |
| 159 | + }); |
| 160 | + |
| 161 | + new appsignals.ApplicationSignalsIntegration(this, 'ApplicationSignalsIntegration', { |
| 162 | + taskDefinition: ec2TaskDefinition, |
| 163 | + instrumentation: { |
| 164 | + sdkVersion: appsignals.PythonInstrumentationVersion.V0_8_0 |
| 165 | + }, |
| 166 | + overrideEnvironments: [{ |
| 167 | + name: appsignals.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT, |
| 168 | + // overwrite the endpoint to point to the created Service Connect |
| 169 | + value: "http://cwagent-4316-http:4316/v1/metrics" |
| 170 | + }, { |
| 171 | + name: appsignals.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, |
| 172 | + // overwrite the endpoint to point to the created Service Connect |
| 173 | + value: "http://cwagent-4316-http:4316/v1/traces" |
| 174 | + }, { |
| 175 | + name: appsignals.TraceExporting.OTEL_TRACES_SAMPLER_ARG, |
| 176 | + // overwrite the endpoint to point to the created Service Connect |
| 177 | + value: "endpoint=http://cwagent-2000-http:2000" |
| 178 | + }], |
| 179 | + serviceName: 'sample-app', |
| 180 | + cloudWatchAgent: { |
| 181 | + // disable sidecar mode |
| 182 | + enableSidecar: false, |
| 183 | + } |
| 184 | + }); |
208 | 185 | }
|
209 |
| -}); |
| 186 | +} |
210 | 187 | ```
|
0 commit comments