{"id":15137728,"url":"https://github.com/aws-samples/aws-ecs-springboot-opentelemetry-sample","last_synced_at":"2025-10-23T13:30:55.212Z","repository":{"id":137021765,"uuid":"425149982","full_name":"aws-samples/aws-ecs-springboot-opentelemetry-sample","owner":"aws-samples","description":"SpringBoot integration with AWS Distro for OpenTelemetry on Amazon ECS","archived":false,"fork":false,"pushed_at":"2021-12-18T21:17:17.000Z","size":279,"stargazers_count":19,"open_issues_count":0,"forks_count":7,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-01-30T18:48:17.008Z","etag":null,"topics":["aws","cloudwatch","ecs","fargate","java","metrics","microservices","open-telemetry","springboot","tracing","xray"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit-0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aws-samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-06T03:52:00.000Z","updated_at":"2024-12-20T14:24:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"ae3529e9-cc56-4a95-89f3-3f446162edc5","html_url":"https://github.com/aws-samples/aws-ecs-springboot-opentelemetry-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aws-samples%2Faws-ecs-springboot-opentelemetry-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aws-samples%2Faws-ecs-springboot-opentelemetry-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aws-samples%2Faws-ecs-springboot-opentelemetry-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aws-samples%2Faws-ecs-springboot-opentelemetry-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aws-samples","download_url":"https://codeload.github.com/aws-samples/aws-ecs-springboot-opentelemetry-sample/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237834599,"owners_count":19373757,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","cloudwatch","ecs","fargate","java","metrics","microservices","open-telemetry","springboot","tracing","xray"],"created_at":"2024-09-26T07:01:48.291Z","updated_at":"2025-10-23T13:30:49.796Z","avatar_url":"https://github.com/aws-samples.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SpringBoot integration with AWS Distro for OpenTelemetry on Amazon ECS\n\nThis project contains source code that demos the following:\n\n- How to integrate [AWS OpenTelemetry](https://aws-otel.github.io/) with Java [SpringBoot](https://spring.io/projects/spring-boot) based microservices.\n- Using [AWS OpenTelemetry](https://aws-otel.github.io/) using [Amazon ECS service pattern](https://aws.amazon.com/blogs/opensource/deployment-patterns-for-the-aws-distro-for-opentelemetry-collector-with-amazon-elastic-container-service/). \n- How to send [AWS OpenTelemetry](https://aws-otel.github.io/) metrics from ECS service to [CloudWatch Metrics](https://aws.amazon.com/cloudwatch/), [AWS X-Ray](https://aws.amazon.com/xray/) and [Amazon Managed Service for Prometheus](https://aws.amazon.com/prometheus/).\n- Create nested stacks using [AWS SAM Nested applications](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-nested-applications.html). \n\nThe [AWS Distro for OpenTelemetry (ADOT)](https://aws.amazon.com/otel/?otel-blogs.sort-by=item.additionalFields.createdDate\u0026otel-blogs.sort-order=desc) is a secure, production-ready, AWS-supported distribution of the OpenTelemetry project.\n\n#### Integrating OpenTelemetry with springboot services.\n\nThis project shows how to add [java OpenTelemetry agent](https://github.com/aws-observability/aws-otel-java-instrumentation)  with popular spring boot based microservices.\nRefer the `Dockerfile` in the project to see how to add the java OpenTelemetry agent without making code changes to the application.\n\n#### Using Amazon ECS service pattern\nSeveral patterns can be used for deploying ADOT for observability. The common ones include\n\n- **The sidecar pattern** : A common practice in the observability world is to use sidecars to provide container instrumentation.\nThe [ADOT website](https://aws-otel.github.io/docs/getting-started/prometheus-remote-write-exporter/ecs) shows how to configure the AWS OTel Collector to scrape metrics using the sidecar pattern.\nA main advantage of the sidecar pattern is that it is simple to configure and troubleshoot. However, when customers have thousands of microservices and multiple environments,compute cost \nof running sidecar per task can start to add up and this pattern may become expensive.\n\n- **Amazon ECS service pattern**: The Amazon ECS service deployment pattern is similar to the [DaemonSet](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/) pattern in Kubernetes. \nAn Amazon ECS service allows you to run and maintain a specified number of instances of a OTel task in ECS. \nIf any of the tasks fail, the Amazon ECS service scheduler launches another task instance to replace the failed task.\nIf Autoscaling is added to the OpenTelemetry service, it dynamically scales as more application services are added, and they push metrics to the OpenTelemetry service.\nAWS Service discovery is used with the OpenTelemetry service to provide a private namespace to the service, which can be used by application services to discover and push their metrics to OpenTelemetry service.\nThe main advantage of this pattern is cost saving. Compute costs are reduced because the number of instrumentation containers no longer has a 1:1 relationship with the application containers.\nThis project is demoing the pattern.\n\nFor more information on sidecar vs ecs service pattern please refer to this AWS [Blog](https://aws.amazon.com/blogs/opensource/deployment-patterns-for-the-aws-distro-for-opentelemetry-collector-with-amazon-elastic-container-service/).\n\n#### Sending metrics from OpenTelemetry to CloudWatch, X-Ray \u0026 Amazon Managed Service for Prometheus\n\nThe [OpenTelemetry configuration](https://opentelemetry.io/docs/collector/configuration/) allows you to manage sources and destinations of metrics collected by the OTel.\nRefer to ssm parameter in `otel-service.yaml` that contains the OpenTelemetry configuration used by the service to export metrics data to CloudWatch and Prometheus \u0026 traces data to X-Ray.\n\nOnce the project is deployed, you will be able to see 2 new namespaces in the CloudWatch metrics console.\n\n![Cloudwatch Metrics](docs/cw-metrics.png)\n\nYou can also view AWS X-Ray service map\n\n![X-Ray Service Map](docs/xray.png)\n\n\nYou can query Prometheus metrics using the [these techniques](https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-onboard-query.html).\n\n#### Using AWS SAM CLI Nested Applications to create and maintain nested stack\nFinally, instead of using [Cloudformation nested stack](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-nested-stacks.html) to create infrastructure we are using [AWS SAM Nested applications](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-nested-applications.html). Cloudformation nested stack can be hard to change locally and redeploy because it\nrequires you to upload the updated templates to s3 bucket everytime you want to make a change. Instead, [AWS SAM cli](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) can manage that process for you.\nThough primarily used to create serverless infrastructure, AWS SAM nested application (AWS::Serverless::Application) can  allow you to create nested stacks with a minor change to the parent Cloudformation template. AWS SAM will convert them to Cloudformation nested stacks internally before deploying.\n\n\n### Solution Overview\n![Architecture](docs/otel.png)\n\n## Deploy the sample application\n\n\u003e **WARNING**:\n\u003e This project creates VPC, ALB, ECS Cluster \u0026 Services, CloudMap, S3 buckets that can incur cost. Cleanup resources once done working.\n\nThe AWS SAM CLI is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. \nTo use the AWS SAM CLI, you need the following tools:\n\n* AWS SAM CLI - [Install the AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html).\n* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition\u0026offering=community).\n\nTo build and deploy your application for the first time, run the following in your shell:\n\n```bash\nsam build\nsam deploy --guided --capabilities CAPABILITY_NAMED_IAM\n```\n\n### Cleanup\n\nTo delete the sample pipeline that you created, use the AWS CLI. Assuming you used your project name for the stack\nname, you can run the following:\n\n```bash\nsam delete\n```\n\n### Resources\n\nSee\nthe [AWS SAM developer guide](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html)\nfor an introduction to SAM specification, the SAM CLI, and serverless application concepts.\n\n### Contribution\n\nSee [CONTRIBUTING](CONTRIBUTING.md) for more information.\n\n### License\n\nSee the [LICENSE](LICENSE) file.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faws-samples%2Faws-ecs-springboot-opentelemetry-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faws-samples%2Faws-ecs-springboot-opentelemetry-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faws-samples%2Faws-ecs-springboot-opentelemetry-sample/lists"}