Enable your applications on Amazon EKS clusters
CloudWatch Application Signals is supported for Java, Python, Node.js, and .NET applications. To enable Application Signals for your applications on an existing Amazon EKS cluster, you can use the Amazon Web Services Management Console, Amazon CDK, or CloudWatch Observability add-on Auto monitor advanced configuration.
Topics
Enable Application Signals on an Amazon EKS cluster using the console
To enable CloudWatch Application Signals on your applications on an existing Amazon EKS cluster, use the instructions in this section.
Important
If you are already using OpenTelemetry with an application that you intend to enable for Application Signals, see OpenTelemetry compatibility before you enable Application Signals.
To enable Application Signals for your applications on an existing Amazon EKS cluster
Note
If you haven't already enabled Application Signals, follow the instructions in Enable Application Signals in your account and then follow the procedure below.
Open the CloudWatch console at https://console.amazonaws.cn/cloudwatch/
. Choose Application Signals.
For Specify platform, choose EKS.
For Select an EKS cluster, select the cluster where you want to enable Application Signals.
If this cluster does not already have the Amazon CloudWatch Observability EKS add-on enabled, you are prompted to enable it. If this is the case, do the following:
Choose Add CloudWatch Observability EKS add-on. The Amazon EKS console appears.
Select the check box for Amazon CloudWatch Observability and choose Next.
The CloudWatch Observability EKS add-on enables both Application Signals and CloudWatch Container Insights with enhanced observability for Amazon EKS. For more information about Container Insights, see Container Insights.
Select the most recent version of the add-on to install.
Select an IAM role to use for the add-on. If you choose Inherit from node, attach the correct permissions to the IAM role used by your worker nodes. Replace
my-worker-node-role
with the IAM role used by your Kubernetes worker nodes.aws iam attach-role-policy \ --role-name
my-worker-node-role
\ --policy-arn arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy \ --policy-arn arn:aws:iam::aws:policy/AWSXRayWriteOnlyAccessIf you want to create a service role to use the add-on, see Install the CloudWatch agent with the Amazon CloudWatch Observability EKS add-on or the Helm chart.
Choose Next, confirm the information on the screen, and choose Create.
In the next screen, choose Enable CloudWatch Application Signals to return to the CloudWatch console and finish the process.
-
There are two options for enabling your applications for Application Signals. For consistency, we recommend that you choose one option per cluster.
The Console option is simpler. Using this method causes your pods to restart immediately.
The Annotate Manifest File method gives you more control of when your pods restart, and can also help you manage your monitoring in a more decentralized way if you don’t want to centralize it.
Note
If you are enabling Application Signals for a Node.js application with ESM, skip to Setting up a Node.js application with the ESM module format instead.
Choose View Services when done. This takes you to the Application Signals Services view, where you can see the data that Application Signals is collecting. It might take a few minutes for data to appear.
To enable Application Signals in another Amazon EKS cluster, choose Enable Application Signals from the Services screen.
For more information about the Services view, see Monitor the operational health of your applications with Application Signals.
Note
If you're using a WSGI server for your Python application, see No Application Signals data for Python application that uses a WSGI server for information to make Application Signals work.
We've also identified other considerations that you should keep in mind when enabling Python applications for Application Signals. For more information, see Python application doesn't start after Application Signals is enabled.
Setting up a Node.js application with the ESM module format
We provide limited support for Node.js applications with the ESM module format. For details, see Known limitations about Node.js with ESM.
For the ESM module format, enabling Application Signals through the console or by annotating the manifest file doesn’t work. Skip step 8 of the previous procedure, and do the following instead.
To enable Application Signals for a Node.js application with ESM
Install the relevant dependencies to your Node.js application for autoinstrumentation:
npm install @aws/aws-distro-opentelemetry-node-autoinstrumentation npm install @opentelemetry/instrumentation@0.54.0
Add the following environmental variables to the Dockerfile for your application and build the image.
... ENV OTEL_AWS_APPLICATION_SIGNALS_ENABLED=true ENV OTEL_TRACES_SAMPLER_ARG='endpoint=http://cloudwatch-agent.amazon-cloudwatch:2000' ENV OTEL_TRACES_SAMPLER='xray' ENV OTEL_EXPORTER_OTLP_PROTOCOL='http/protobuf' ENV OTEL_EXPORTER_OTLP_TRACES_ENDPOINT='http://cloudwatch-agent.amazon-cloudwatch:4316/v1/traces' ENV OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT='http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics' ENV OTEL_METRICS_EXPORTER='none' ENV OTEL_LOGS_EXPORTER='none' ENV NODE_OPTIONS='--import @aws/aws-distro-opentelemetry-node-autoinstrumentation/register --experimental-loader=@opentelemetry/instrumentation/hook.mjs' ENV OTEL_SERVICE_NAME='
YOUR_SERVICE_NAME
' #replace with a proper service name ENV OTEL_PROPAGATORS='tracecontext,baggage,b3,xray' ... # command to start the application # for example # CMD ["node", "index.mjs"]Add the environmental variables
OTEL_RESOURCE_ATTRIBUTES_POD_NAME
,OTEL_RESOURCE_ATTRIBUTES_NODE_NAME
,OTEL_RESOURCE_ATTRIBUTES_DEPLOYMENT_NAME
,POD_NAMESPACE
andOTEL_RESOURCE_ATTRIBUTES
to the deployment yaml file for the application. For example:apiVersion: apps/v1 kind: Deployment metadata: name: nodejs-app labels: app: nodejs-app spec: replicas: 2 selector: matchLabels: app: nodejs-app template: metadata: labels: app: nodejs-app # annotations: # make sure this annotation doesn't exit # instrumentation.opentelemetry.io/inject-nodejs: 'true' spec: containers: - name: nodejs-app image:
your-nodejs-application-image
#replace with a proper image uri imagePullPolicy: Always ports: - containerPort: 8000 env: - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME valueFrom: fieldRef: fieldPath: spec.nodeName - name: OTEL_RESOURCE_ATTRIBUTES_DEPLOYMENT_NAME valueFrom: fieldRef: fieldPath: metadata.labels['app'] # Assuming 'app' label is set to the deployment name - name: POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace - name: OTEL_RESOURCE_ATTRIBUTES value: "k8s.deployment.name=$(OTEL_RESOURCE_ATTRIBUTES_DEPLOYMENT_NAME),k8s.namespace.name=$(POD_NAMESPACE),k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)"Deploy the Node.js application to the cluster.
Once you have enabled your applications on the Amazon EKS Clusters, you can monitor your application health. For more information, see Monitor the operational health of your applications with Application Signals.
Enable Application Signals on an Amazon EKS cluster using the CloudWatch Observability add-on advanced configuration
Starting with version v4.0.0-eksbuild.1 of the CloudWatch Observability Amazon EKS add-on, you can automatically enable Application Signals for all service workloads in your EKS cluster(s) using a new centralized Auto monitor configuration flag in the add-on's advanced configuration.
To choose the Auto monitor feature, you must modify the advanced configuration when creating or updating the add-on or Helm chart. By setting monitorAllServices
to true,
the CloudWatch Observability add-on will detect all Kubernetes service workloads and attempt to inject Amazon Distro for OpenTelemetry (ADOT) SDKs during deployment automatically.
Additionally, by enabling restartPods
, all service workload pods will be restarted to immediately inject the ADOT SDKs as part of an automated redeployment process.
--configuration-values '{ "manager":{ "applicationSignals":{ "autoMonitor":{ "monitorAllServices":true, "restartPods":true } } } }'
CloudWatch Observability Add-on also provides additional fine-grained control to include or exclude specific services as needed in the new advanced configuration. For more information, see Configuring Application Signals for your Amazon EKS cluster .
Enable Application Signals on Amazon EKS using Amazon CDK
If you haven't enabled Application Signals in this account yet, you must grant Application Signals the permissions it needs to discover your services. See Enable Application Signals in your account.
Enable Application Signals for your applications.
import { aws_applicationsignals as applicationsignals } from 'aws-cdk-lib'; const cfnDiscovery = new applicationsignals.CfnDiscovery(this, 'ApplicationSignalsServiceRole', { } );
The Discovery CloudFormation resource grants Application Signals the following permissions:
-
xray:GetServiceGraph
-
logs:StartQuery
-
logs:GetQueryResults
-
cloudwatch:GetMetricData
-
cloudwatch:ListMetrics
-
tag:GetResources
For more information about this role, see Service-linked role permissions for CloudWatch Application Signals.
-
Install the
amazon-cloudwatch-observability
add-on.Create an IAM role with the
CloudWatchAgentServerPolicy
and the OIDC associated with the cluster.const cloudwatchRole = new Role(this, 'CloudWatchAgentAddOnRole', { assumedBy: new OpenIdConnectPrincipal(cluster.openIdConnectProvider), managedPolicies: [ManagedPolicy.fromAwsManagedPolicyName('CloudWatchAgentServerPolicy')], });
Install the add-on with the IAM role created above.
new CfnAddon(this, 'CloudWatchAddon', { addonName: 'amazon-cloudwatch-observability', clusterName: cluster.clusterName, serviceAccountRoleArn: cloudwatchRole.roleArn });
Add one of the following into the
PodTemplate
section of your workload manifest file.Language File Java
instrumentation.opentelemetry.io/inject-java: "true"
Python
instrumentation.opentelemetry.io/inject-python: "true"
.Net
instrumentation.opentelemetry.io/inject-dotnet: "true"
Node.js
instrumentation.opentelemetry.io/inject-nodejs: "true"
const deployment = { apiVersion: "apps/v1", kind: "Deployment", metadata: { name: "
sample-app
" }, spec: { replicas: 3, selector: { matchLabels: { "app": "sample-app
" } }, template: { metadata: { labels: { "app": "sample-app
" }, annotations: { "instrumentation.opentelemetry.io/inject-$LANG
": "true" } }, spec: {...}, }, }, }; cluster.addManifest('sample-app
', deployment)