Skip to content

Microservice written in Java that shows how to instrument applications using OpenTelemetry, to produce telemetry data for traces and metrics. Also how to switch the observability backend without code changes.

License

Notifications You must be signed in to change notification settings

build-on-aws/instrumenting-java-apps-using-opentelemetry

Instrumenting Java Applications using OpenTelemetry

This project provides an example of microservice written in Java that produces telemetry data for traces and metrics using OpenTelemetry. It also shows how to de-couple the application from the observability backend using the OpenTelemetry Collector and the OTLP protocol, so you can be easily switch the observability backend for another without code changes.

💡 If you want to learn how to build this code with a hands-on tutorial, you can watch the YouTube series below.

Instrumenting Java Applications using OpenTelemetry

Alternatively, you can also read the blog post: https://www.buildon.aws/posts/instrumenting-java-apps-using-opentelemetry

Requirements

🏢 Running the microservice with Grafana, Grafana Tempo, and Prometheus as observability backend.

You can have the microservice sending telemetry data to a local observability backend. Traces will be sent to Grafana Tempo and the metrics to Prometheus. Then you can use Grafana to visualize the the generated telemetry data.

  1. Start the containers using Docker Compose.
docker compose -f docker-compose.yaml up -d
  1. Access the Grafana UI: http://localhost:3000

🌩 Running the microservice with AWS X-Ray and Amazon CloudWatch as observability backend.

You can have the microservice sending telemetry data to AWS as observability backend. Traces will be sent to AWS X-Ray and the metrics to Amazon CloudWatch. This is possible thanks to the AWS Distro for OpenTelemetry that provides out-of-the-box integration with AWS services. Before running the code; make sure to configure your AWS credentials in your machine, as the code will use them to connect with the target services.

  1. Start the containers using Docker Compose.
docker compose -f docker-compose-aws.yaml up -d
  1. Access the AWS Console: https://console.aws.amazon.com

⚡️ Invoke the Microservice API manually

The microservice expose an API over the port 8888 using HTTP.

  1. Invoke this API for testing purposes.
curl -X GET http://localhost:8888/hello

Security

See CONTRIBUTING for more information.

Disclaimers

This package requires and may incorporate or retrieve a number of third-party
software packages (such as open source packages) at install-time or build-time
or run-time ("External Dependencies"). The External Dependencies are subject to
license terms that you must accept in order to use this package. If you do not
accept all of the applicable license terms, you should not use this package. We
recommend that you consult your company's open source approval policy before
proceeding.

Provided below is a list of External Dependencies and the applicable license
identification as indicated by the documentation associated with the External
Dependencies as of Amazon's most recent review.

THIS INFORMATION IS PROVIDED FOR CONVENIENCE ONLY. AMAZON DOES NOT PROMISE THAT
THE LIST OR THE APPLICABLE TERMS AND CONDITIONS ARE COMPLETE, ACCURATE, OR
UP-TO-DATE, AND AMAZON WILL HAVE NO LIABILITY FOR ANY INACCURACIES. YOU SHOULD
CONSULT THE DOWNLOAD SITES FOR THE EXTERNAL DEPENDENCIES FOR THE MOST COMPLETE
AND UP-TO-DATE LICENSING INFORMATION.

YOUR USE OF THE EXTERNAL DEPENDENCIES IS AT YOUR SOLE RISK. IN NO EVENT WILL
AMAZON BE LIABLE FOR ANY DAMAGES, INCLUDING WITHOUT LIMITATION ANY DIRECT,
INDIRECT, CONSEQUENTIAL, SPECIAL, INCIDENTAL, OR PUNITIVE DAMAGES (INCLUDING
FOR ANY LOSS OF GOODWILL, BUSINESS INTERRUPTION, LOST PROFITS OR DATA, OR
COMPUTER FAILURE OR MALFUNCTION) ARISING FROM OR RELATING TO THE EXTERNAL
DEPENDENCIES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, EVEN
IF AMAZON HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
AND DISCLAIMERS APPLY EXCEPT TO THE EXTENT PROHIBITED BY APPLICABLE LAW.

Grafana (https://grafana.com) – Affero General Public License 3.0

License

This library is licensed under the MIT-0 License. See the LICENSE file.

About

Microservice written in Java that shows how to instrument applications using OpenTelemetry, to produce telemetry data for traces and metrics. Also how to switch the observability backend without code changes.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published