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.
- Visit https://start.spring.io
- Pick your favorite build tool. (I’ll be using Maven).
- Pick the latest version of Spring Boot 3. (I’ll be using 3.0.0-SNAPSHOT).
- Just leave the project metadata as is.
- From the dependencies panel on the right, pick Spring Web and Actuator
- 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: