Get in touch

Awesome Image Awesome Image

Java Development May 6, 2024

Java Application Monitoring with OpenTelemetry

Writen by Mahipalsinh Rana


Java Application Monitoring with OpenTelemetry

We all acknowledge the fact that whenever we maintain the high standards of the Java application, solving problems and easing the tricky business, everybody benefits from it. OpenTelemetry is among the must-have instruments in the current context of the implementation of the health monitor principle for your applications. It will provide you with a complete cockpit for all the aspects of your applications written in Java.

Meanwhile, enables you to follow the trends of these applications. Not just a list of tools, but much more, OpenTelemetry is part of a project, which is overseen by the Cloud-Native Computing Foundation (CNCF). It provides APIs, libraries, and agents that help you collect and assemble telemetry data–metrics, logs, and traces. Through these metrics and analytic tools you are able to see how well your software is functioning.

This is because OpenTelemetry is compatible with any system and can easily be merged into any Java environment. Thus, you get to watch through the request chain, measure the velocity of service response, and also monitor the overall system health as it happens. It is integral, especially for those Java developers who want their applications to have more qualities of these things- reliability and responsiveness.

Important Java Metrics to Monitor

While monitoring metrics is a vital part of managing and efficiently using Java applications, it’s only one of the crucial issues. Here’s a breakdown of essential Java metrics that you should keep an eye on:

JVM Metrics

JVM (Java Virtual Machine) is Java’s running area, where the applications reside. Key JVM metrics to monitor include:

  • Heap Memory Usage: A dedicated number of the database heap memory is being used. Excessive use can cause a program to encounter `OutOfMemoryError`.
  • Garbage Collection (GC) Metrics: Tracks the efficiency of memory reclamation processes. Monitoring GC helps in optimizing application memory usage.
  • Thread Count: Shows the number of active threads. A spike in thread count could signal underlying issues in your application.

CPU Metrics

  • These metrics help assess how Java applications utilize CPU resources
  • CPU Utilization:  This shows the percentage of CPU cycles used by running processes during a certain period. A closely used one might indicate overconsumption of CPU resources if it is used to a higher extent.
  • System Load Average: This stands out for the total working time on the CPU on some particular basis. Rising degrees may indicate the fact that the CPU is being pushed too far.

Application Metrics

Specific to each Java application, these metrics provide insights into application performance and behavior:

  • Response Time: The time it consumes until the application returns a request. Greater response times should be taken with caution as they can badly impact user experience.
  • The amount of requests that an application processes per last unit of time. This is the least metric of all that defines the ability of the application, and thus to plan for scalability is important and necessary.

I/O Metrics

I/O metrics are critical for understanding how applications interact with system resources:

  • Gathering the data from the memory of which the disk has read from, or by writing the data into the disk’s memory. The I/O of a machine is clarified by high disk I/O to show heavy reliance of the application on the disk operation.
  • Network I/O: Counting the amount of data sent and received over the network using the used data traffic. You can also employ this to pick the appropriate network services and improve performance.

Concurrency Metrics

These metrics are essential for applications that handle multiple tasks simultaneously, particularly in multi-threaded environments

  • Reflects the number of threads that are permitted to run at a moment symbolized by the thread pool. Monitoring this can help in adjusting the thread pool size at its respective time for better performance of the program use.
  • Lock Contention: Tracks the duration threads spend waiting to acquire a lock. High contention rates can significantly hinder application performance.

Through these metrics being monitored regularly, the developers along with system administrators would be able to run the application efficiently, and thus even when the issues arise it would be quick to troubleshoot keeping the reliability and performance rate of the application high.

Learn | CI/CD Pipeline Integration for Liferay with Jenkins

How OpenTelemetry Works with Java Applications 

OpenTelemetry offers a streamlined and powerful way to integrate telemetry into Java applications, ensuring that developers can easily track and optimize their applications’ performance. Here’s how OpenTelemetry works with Java applications:

What is OpenTelemetry?

OpenTelemetry is an open-source observability framework that is platform-independent and facilitates the collection, composition, and export of telemetry data—such as metrics, traces, and logs—from cloud-based applications. This data is crucial for determining application performance and identifying areas that need improvement. OpenTelemetry enables developers and operators to visualize and analyze the internal workings of their systems, which is essential for maintaining efficient and smooth operations.

OpenTelemetry Java API

The Java API provided by OpenTelemetry serves as a key interface within the OpenTelemetry world, enabling the submission of telemetry data to a Java application. This enables the use of data by providing uniform semantics and definitions and strict adherence to the data formats and protocols across different applications. It contains a package of interfaces and classes that should be appropriately used so to trace traces, metrics, and logs. Java API is high-performance with low overhead, which makes it best to use it in performance-critical applications without significant performance impairments.

OpenTelemetry Java SDK

Combining the API with the OpenTelemetry Java SDK developers use is the application for it. It provides all a metrology facility must-have tools to perform a research task including data collection, processing, and exporting.  The SDK is highly flexible and configurable, offering a robust suite of features that give developers control over the collection and exportation of telemetry data. Key components of the SDK include:

  • TracerProvider: Manages trace creation and transmission.
  • MeterProvider: Handles metrics data.
  • BaggageManager: Facilitates managing context propagation.
  • Processor and Exporter: These components are involved in processing telemetry data and exporting it to the chosen backend system.

OpenTelemetry in Java Example

To better understand how to integrate OpenTelemetry with a Java application, let’s walk through a practical example. Here’s a step-by-step guide on how to set up OpenTelemetry in a Java project, focusing on creating a simple HTTP server using Spring Boot and instrumenting it to collect telemetry data.

Learn | Elasticsearch Integration with Spring Boot: A Developer’s Guide

Installation and Dependencies

Step 1: Check Java Installation

To begin, install Java on your machine using `java -version` in your terminal. In case Java is not already installed, the version matching your operating system requirements should be installed i.e. Java for Windows, Linux, etc.

Step 2: Add OpenTelemetry SDK

Then, transit to OpenTelemetry in your Java project. If you are using Maven, you can include the OpenTelemetry Java SDK as a dependency in your `pom.xml` file

Create and Launch an HTTP Server

Step 3: Set Up Spring Boot

Start a new JSP web application using the Spring Boot framework. You can use [Spring Initializr](https://start.spring.io/) and create a project with the necessary dependencies. First of all, ensure that our HTTP Server is properly connected to the Spring Web dependency.

Step 4: Create a Controller

After you install your project you will navigate within to find it in, `src/main/java/com.example.demo` of the project. Example: Create `DemoController` class that will route HTTP requests in this template.

Here’s what your `DemoController` class might look like:

Step 5: Run the Server

You can actually do direct the setup and checkout of the project with Maven, directly or do it directly through your IDE. If you are using Maven, build the project with:

The following screenshot shows how to build the project:


Source: https://lumigo.io/

You can start the project using the following command:

java -jar target/demo-0.0.1-SNAPSHOT.jar


Source: https://lumigo.io/

After launching, you can access the server by navigating to `http://localhost:8080/hello` in your web browser, and you should see “Hello, World!”.

Instrumentation with OpenTelemetry

Step 6: Use OpenTelemetry Java Agent

To instrument your application, use the OpenTelemetry Java Agent. This agent automatically instruments your application, capturing traces and metrics with minimal code changes.

Step 7: Update Your Controller for Tracing

Modify your `DemoController` to include basic tracing:

This code adds a simple trace every time the `/hello` endpoint is accessed. The span is named “hello” and you can monitor these spans via the OpenTelemetry Collector or any compatible telemetry backend.

This setup demonstrates how OpenTelemetry can be seamlessly integrated into a Java application to enhance monitoring and observability with minimal changes to the existing codebase.

The Lumio OpenTelemetry Java Distro: A No Code Observability Solution

The Lumio OpenTelemetry Java Distro presents a seamless, “no code” observability solution designed to simplify how developers monitor and understand their Java applications. Here’s an explanation of how it works and its advantages in the context of cloud-native observability:

The Lumio OpenTelemetry Java Distro is an easy, “no code” observability solution for developers who need to know how many of their Java applications are working from where “to which extent” and “what is happening”. Here’s an explanation of how it works and its advantages in the context of cloud-native observability:

OpenTelemetry: The Foundation

Despite the fact that OpenTelemetry is not an independent observability platform, it is still a very important and popular tool. It might be possible that it does not include storage, query, and visualization features of the telemetry data. However, radiated evolution, in this case, does not imply the use of telemetry data or its exportation from the apps to the different observability platforms. Its pluggable is the basic trait for integration of different technologies following protocols and formats.

lumio’s Enhancement with OpenTelemetry

To augment its observability platform used by the developers of cloud-native applications, Lumigo, the prominent OpenTelemetry platform, exploits OpenTelemetry in its information collection process. Dissemination of OpenTelemetry among various types of programming platforms is facilitated by the Lumigo team for Python, Node.js, and Java, among these environments. These distributions are particularly beneficial because they:

Require No Code Changes: Lumio established the OpenTelemetry Java Distro, which is optimized to be effortlessly waterproofed into current Java applications without any adjustments to the application code. Observability solutions running on microservice architectures have this unique feature of not forcing developers to modify the code that already exists and instead only require them to add the logic of observability runtime in development.

Come Pre-configured: Pre-set up these spreads allows them to be able to give out data regarding tracing and resources in a convenient and efficient way by sending them right to the platform. This cleverly organized configuration technique limits the time needed to set up the monitoring tools so that developers can focus on their core development work without having to bother with this configuration process.

Stable Integration: Even if you are some of the other OpenTelemetry solutions, for example, the OpenTelemetry Collector or AWS Distro for OpenTelemetry, you can send tracing data to Lumigo. Lumigo maintains this flexibility so it can optimally function as a single observability platform regardless of the implementation of the preferable OpenTelemetry version.

Benefits of Lumio OpenTelemetry Java Distro

The primary benefits of using the Lumio OpenTelemetry Java Distro include:

  • Ease of Implementation: This will be done by replacing the need for coding changes and assigning the role of a pre-configured setup which will help to decrease the technical barrier that is observed implementation of a thorough observation.
  • Comprehensive Monitoring: It locks down the deep monitoring of applications, showing technicians and system administrators inefficiencies, performance bottlenecks, and runtime errors.
  • Flexibility and Compatibility: It seamlessly integrates into the existing tech stack in a company irrespective of the team’s level of development, making it easy to use for newbies and experienced developers.

OpenTelemetry is essential for Java development companies, simplifying the collection of diverse data through a unified system. It swiftly analyzes metrics, logs, and traces, allowing developers at these companies to effectively monitor and optimize Java application performance. This integration not only enhances the reliability and strength of the underlying framework but also enables the creation of higher-quality applications more quickly. Ul is a key asset for any Java development company.

Bringing Software Development Expertise to Every
Corner of the World

United States



United Kingdom




New Zealand










South Africa