This example will introduce how to use AWS-OTel-Collector to send application traces and metrics on AWS ECS. This instruction provided the data emitter image that will generate OTLP format of metrics and traces data to AWS CloudWatch and X-Ray consoles. Please follow the steps below to try AWS OTel Collector Beta.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:PutLogEvents",
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:DescribeLogStreams",
"logs:DescribeLogGroups",
"xray:PutTraceSegments",
"xray:PutTelemetryRecords",
"xray:GetSamplingRules",
"xray:GetSamplingTargets",
"xray:GetSamplingStatisticSummaries",
"ssm:GetParameters"
],
"Resource": "*"
}
]
}
ECS-AWSOTel
for the Name and choose Create policy.ECS-AWSOTel
and select ECS-AWSOTel policy, then choose Next: Tags.ECS-AWSOTel
for the Name and choose Create role.The easiest way to deploy AWSOTelCollector on Amazon ECS is to run it as a sidecar, defining it in the same task definition as your application.
ECS Fargate Template
You can find ECS Fargate AWSOTelCollector Installing template. Instructions for setting up a service in your ECS cluster using Fargate can be found here.
ECS EC2 Template
Another example is installing AWSOTelCollector on ECS EC2 instance as sidecar to send telemetry data.
You can find ECS EC2 AWSOTelCollector Installing template. Instructions for setting up a service in your ECS cluster using EC2 can be found here.
Configure The Task Definition
The two ECS task definition templates are provided to run AWS-OTel-Collector as sidecar to send application metrics and traces on Amazon ECS. Notice that in the task definition templates we provided, you have to replace with the region your want to send the data to. Fill
and `` with the IAM role (ECS-AWSOTel
) you created above.
In the task definition, we run three applications: the customer’s application (aws-otel-emitter
), ngnix and the AWSOTelCollector aws-otel-collector
. Running the AWSOTelCollector in the same application as the main application allows the AWSOTelCollector to collect the metric/trace data for the customer’s application. We also call running the AWSOTelCollector in this way a "Sidecar".
View Your Metrics
You should now be able to view your metrics in your CloudWatch console. In the navigation bar, click on Metrics. The collected AWSOTelCollector metrics can be found in the AWSObservability/CloudWatchOTService namespace. Ensure that your region is set to the region set for your cluster.
To Install AWSOTelCollector Via CloudFormation, you have to manually create an ECS cluster on your AWS console first.
Download CloudFormation template file for installing AWSOTelCollector on ECS EC2 mode
curl -O https://raw.githubusercontent.com/aws-observability/aws-otel-collector/main/deployment-template/ecs/aws-otel-ec2-sidecar-deployment-cfn.yaml
Replace the <PATH_TO_CloudFormation_TEMPLATE> with the path where your template saved in the command, and export the following parameters, and then run CloudFormation command.
--config=/etc/ecs/container-insights/otel-task-metrics-config.yaml
--config=/etc/ecs/ecs-default-config.yaml
ClusterName=<Cluster_Name>
Region=<AWS_Region>
command=<command>
aws cloudformation create-stack --stack-name AWSOTelCollectorECS-${ClusterName}-${Region} \
--template-body file://<CFN_File_Downloaded> \
--parameters ParameterKey=ClusterName,ParameterValue=${ClusterName} \
ParameterKey=CreateIAMRoles,ParameterValue=True \
ParameterKey=command,ParameterValue=${command} \
--capabilities CAPABILITY_NAMED_IAM \
--region ${Region}
Download CloudFormation template file for installing AWSOTelCollector on ECS Fargate mode
curl -O https://raw.githubusercontent.com/aws-observability/aws-otel-collector/main/deployment-template/ecs/aws-otel-fargate-sidecar-deployment-cfn.yaml
Replace the <PATH_TO_CloudFormation_TEMPLATE> with the path where your template saved in the command, and export the following parameters, and then run CloudFormation command.
--config=/etc/ecs/ecs-default-config.yaml
--config=/etc/ecs/container-insights/otel-task-metrics-config.yaml
ClusterName=<aotTestCluster>
Region=<us-west-2>
SecurityGroups=<Security_Groups>
Subnets=<Subnets>
command=<command>
aws cloudformation create-stack --stack-name AOCECS-${ClusterName}-${Region} \
--template-body file://<PATH_TO_CloudFormation_TEMPLATE> \
--parameters ParameterKey=ClusterName,ParameterValue=${ClusterName} \
ParameterKey=CreateIAMRoles,ParameterValue=True \
ParameterKey=SecurityGroups,ParameterValue=${SecurityGroups} \
ParameterKey=Subnets,ParameterValue=${Subnets} \
ParameterKey=command,ParameterValue=${command} \
--capabilities CAPABILITY_NAMED_IAM \
--region ${Region}