Using Micrometer to trace your Spring Boot app

Greg L. Turnquist
7 min readNov 10, 2022

If there’s one thing that eventually sneaks up on you after building and releasing an application, it’s that something breaks. Yup, applications break and not long after, our manager is asking, “What happened?”

That’s not the only thing we encounter in the Land of Production. We also sometimes see performance degrade. Certain parts of our system seem bogged down. And once again, the question arises, “What’s going on?”

This is what tracing affords us. A means to trace an operation through our application combined with metrics showing us what’s eating up all the time. And for this we turn to Micrometer.

Micrometer, launched in 2017 by the Spring team, it a metrics facade. It supports a whole host of tools, but for today we’ll use the open source distributed tracing system Zipkin.

Setting up a Spring Boot 3 application

Do you already have a Spring Boot 3 app you’d like to instrument? Great! You can skip on to the next section. In case you don’t, you’ll want to file some very simple steps.

  1. Visit https://start.spring.io
  2. Pick your favorite build tool. (I’ll be using Maven).
  3. Pick the latest version of Spring Boot 3. (I’ll be using 3.0.0-SNAPSHOT).
  4. Just leave the project metadata as is.
  5. From the dependencies panel on the right, pick Spring Web and Actuator
  6. Click on the GENERATE button, download the ZIP file, unpack it, and import it into your favorite IDE!

With that in place, you’re all set to get going!

Adding Micrometer to your Spring Boot 3 application

The first step to instrumenting your application is to add Micrometer. Now it’s important to understand that Micrometer actually has two key aspects: tracing and metrics.

  • Tracing — seeing WHAT happened
  • Metrics — seeing HOW LONG it took to happen

Sometimes people want one of the other. But for this article, we’ll do both. And to do that, you need to add the following to your build file:

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-observation</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>…

--

--

Greg L. Turnquist

Sr. Staff Technical Content Engineer at CockroachDB • YouTube Content Creator at https://youtube.com/@ProCoderIO • Best-Selling Author • Coffee Lover