

Monitor your Spring Boot application with OpenTelemetry and SigNoz
source link: https://dev.to/signoz/monitor-your-spring-boot-application-with-opentelemetry-and-signoz-1n4b
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

OpenTelemetry is a vendor-agnostic instrumentation library. In this article, let's explore how you can auto-instrument your Java Spring Boot application with OpenTelemetry and get the data reported through SigNoz - an open-source APM and observability tool.
Steps to get started with OpenTelemetry for Spring Boot application
- Installing SigNoz
- Installing sample Spring Boot app
- Auto instrumentation with OpenTelemetry and sending data to SigNoz
Installing SigNoz
You can get started with SigNoz using just three commands at your terminal if you have Docker installed. You can read about other deployment options from SigNoz documentation.
git clone https://github.com/SigNoz/signoz.git
cd signoz/deploy/
./install.sh
You will have an option to choose between ClickHouse or Kafka + Druid as a storage option. Trying out SigNoz with ClickHouse database takes less than 1.5GB of memory, and for this tutorial, we will use that option.
When you are done installing SigNoz, you can access the UI at: http://localhost:3000.
The application list shown in the dashboard is from a sample app called HOT R.O.D that comes bundled with the SigNoz installation package.
SigNoz dashboardInstalling sample Spring Boot app
For this tutorial, we will use a sample Spring Boot application built using Maven. You can find the code for the application at its GitHub repo.
Steps to get the app set up and running:
- Git clone the repository and go to the root folder
git clone https://github.com/spring-projects/spring-petclinic.git
cd spring-petclinic
- Update Port
This app runs on port 8080
by default. But port 8080
is used by SigNoz for its query service, so let's update the port number to something else.
Open the application.properties
file located at spring-petclinic/src/main/resources
and update the server.port attribute.
# database init, supports mysql too
database=h2
spring.datasource.schema=classpath*:db/${database}/schema.sql
spring.datasource.data=classpath*:db/${database}/data.sql
# Web
spring.thymeleaf.mode=HTML
server.port=8090
# JPA
spring.jpa.hibernate.ddl-auto=none
spring.jpa.open-in-view=false
# Internationalization
spring.messages.basename=messages/messages
# Actuator
management.endpoints.web.exposure.include=*
# Logging
logging.level.org.springframework=INFO
# logging.level.org.springframework.web=DEBUG
# logging.level.org.springframework.context.annotation=TRACE
# Maximum time static resources should be cached
spring.resources.cache.cachecontrol.max-age=12h
Also, update the port number in petclinic_test_plan.jmx located at spring-petclinic/src/test/jmeter
to port number: 8090
. It will appear under PETCLINIC_PORT
elementProp.
- Run the applicationRun the application using the following commands.
./mvnw package
java -jar target/*.jar
You can now access the application UI here: http://localhost:8090/
Sample Spring Boot application running in your local hostOnce you ensure that your application runs fine, stop it with ctrl + z
on mac, as we will be launching the application with the Java agent downloaded from OpenTelemetry.
Auto instrumentation with OpenTelemetry and sending data to SigNoz
For instrumenting Java applications, OpenTelemetry has a very handy Java JAR agent that can be attached to any Java 8+ application. The JAR agent can detect a number of popular libraries and frameworks and instrument it right out of the box. You don't need to add any code for that.
- Download the latest Java JAR agent.
- Now you need to enable the instrumentation agent as well as run your sample application. You can do so by the following command:
OTEL_METRICS_EXPORTER=none OTEL_EXPORTER_OTLP_ENDPOINT="http://<IP of SigNoz>:4317" OTEL_RESOURCE_ATTRIBUTES=service.name=javaApp java -javaagent:/path/to/opentelemetry-javaagent-all.jar -jar target/*.jar
As you are running this on your local host, you need to replace <IP of SigNoz>
with localhost
. The path should be updated to where you have kept your downloaded Java JAR agent. Your final command will look like this:
OTEL_METRICS_EXPORTER=none OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4317" OTEL_RESOURCE_ATTRIBUTES=service.name=javaApp java -javaagent:/Users/Downloads/opentelemetry-javaagent-all.jar -jar target/*.jar
Note the path is updated for my local environment.
Check out the Spring Pet Clinic app at: http://localhost:8090/ and play around with it to generate some load. It might take 1-2 minutes before it starts showing up in the SigNoz dashboard.
Below you can find your javaApp
in the list of applications being monitored.

Metrics and Traces of the Spring Boot application
SigNoz makes it easy to visualize metrics and traces captured through OpenTelemetry instrumentation.
SigNoz comes with out of box RED metrics charts and visualization. RED metrics stands for:
- Rate of requests
- Error rate of requests
- Duration taken by requests

You can then choose a particular timestamp where latency is high to drill down to traces around that timestamp.
View of traces at a particular timestampYou can use flamegraphs to exactly identify the issue causing the latency.

Conclusion
OpenTelemetry makes it very convenient to instrument your Spring Boot application. You can then use an open-source APM tool like SigNoz to analyze the performance of your app. As SigNoz offers a full-stack observability tool, you don't have to use multiple tools for your monitoring needs.
You can try out SigNoz by visiting its GitHub repo 👇
SigNoz
/
signoz
SigNoz helps developers monitor their applications & troubleshoot problems, an open-source alternative to DataDog, NewRelic, etc. 🔥 🖥. 👉 Open source Application Performance Monitoring (APM) & Observability tool
Monitor your applications and troubleshoot problems in your deployed applications, an open-source alternative to DataDog, New Relic, etc.
Documentation • ReadMe in Chinese • Slack Community • Twitter
SigNoz helps developers monitor applications and troubleshoot problems in their deployed applications. SigNoz uses distributed tracing to gain visibility into your software stack.
👉 You can see metrics like p99 latency, error rates for your services, external API calls and individual end points.
👉 You can find the root cause of the problem by going to the exact traces which are causing the problem and see detailed flamegraphs of individual request traces.
Join our Slack community
Come say Hi to us on Slack 👋
Features:
- Application overview metrics like RPS, 50th/90th/99th Percentile latencies, and Error Rate
- Slowest endpoints in your application
- See exact request trace to figure out issues in downstream services, slow DB queries, call to 3rd party services like payment…
If you want to read more about SigNoz 👇
Recommend
-
7
java-version.com: What's new in Java 16? 15? Keep up to date! Monitor your Spring Boot applications with Actuator
-
7
What is SigNoz? SigNoz is an open-source alternative to DataDog, New Relic etc. It is a full-stack application monitoring and observability platform, which can be used to track both metrics and traces. Link to our GitHub repo...
-
9
-
25
-
11
SigNozOpen source alternative to DataDog Founding Sr Backend Engineer at SigNoz0.50% - 1.00%Loca...
-
8
-
14
In a distributed system, many services can be involved in creating a response to a single request. Not only for debugging purposes it’s essential that the path of such a request can be traced through all involved services. This tutorial gives...
-
12
About the roleSigNoz is a global open source project with users in 30+ countries. We are building an open-source application monitoring which helps developers monitor their applications and troubleshoot problems, quickly. In less t...
-
5
SigNoz:开源微服务性能监控工具 解道Jdon ...
-
6
Logs Benchmark This repo contains the setup for the all the three stacks i.e SigNoz, ELK and PLG used for benchmarking. Each of the folders contains it's own set of instructions on how to run them. The results of the benchma...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK