Micrometer Tracing
Instrument services with trace and span IDs.
Micrometer Tracing is a free Spring Boot 4 Microservices & REST APIs lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Spring Boot 4 Microservices & REST APIs learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Micrometer Tracing overview
Micrometer Tracing is a vendor-neutral tracing facade. You code against its API, and a bridge (Brave or OpenTelemetry) does the real work and propagation.
Adding the dependencies
Add Micrometer Tracing plus a bridge. The Brave bridge is a common choice.
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
</dependency>Auto-configuration kicks in
With the bridge on the classpath, Spring Boot auto-configures a Tracer and instruments incoming requests and outbound HTTP clients. Many spans appear with zero code.
The Tracer bean
The Tracer is the entry point for working with spans manually. It is auto-configured and injectable.
@Service
public class OrderService {
private final Tracer tracer;
public OrderService(Tracer tracer) { this.tracer = tracer; }
}Creating a custom span
Wrap a meaningful unit of work in its own span to time it and see it in the trace.
Span span = tracer.nextSpan().name("calculate-price");
try (Tracer.SpanInScope ws = tracer.withSpan(span.start())) {
calculatePrice();
} finally {
span.end();
}@NewSpan and @SpanTag
For convenience, annotate a method with @NewSpan to wrap it in a span automatically, and tag arguments with @SpanTag.
@NewSpan("load-customer")
public Customer load(@SpanTag("customerId") Long id) {
return repo.findById(id);
}Adding tags and events
Enrich spans with tags (key/value metadata) and events (timestamped notes) to make traces more diagnostic.
span.tag("user.id", userId);
span.event("cache-miss");Reading the current trace IDs
You can read the active trace and span IDs - useful for returning a trace id to clients or correlating.
Span current = tracer.currentSpan();
if (current != null) {
String traceId = current.context().traceId();
String spanId = current.context().spanId();
}Brave vs OpenTelemetry bridge
Two bridges exist: Brave (Zipkin-native) and OpenTelemetry (OTel ecosystem). Pick one - they should not be on the classpath together.
Propagation format
The bridge controls how context is propagated. You can choose formats like W3C (traceparent) or B3, which matters when integrating with other systems.
management:
tracing:
propagation:
type: w3cBaggage
Baggage is extra key/value data propagated alongside the trace context across services - e.g. a tenant id - so every downstream span and log can access it.
Quick Check
Check your Micrometer Tracing knowledge.
Recap
You used Micrometer Tracing:
- It is a facade; a Brave or OTel bridge does the real work
- Inject the
Tracerto create custom spans, or use@NewSpan - Add tags/events; read traceId/spanId
- Baggage propagates extra context
Frequently asked questions
Is the “Micrometer Tracing” lesson free?
Yes — the full text of “Micrometer Tracing” is free to read here on the web, and the Spring Boot 4 Microservices & REST APIs course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Spring Boot 4 Microservices & REST APIs course, upgrade to CoddyKit PRO.
What will I learn in “Micrometer Tracing”?
Instrument services with trace and span IDs. You practise Spring Boot 4 Microservices & REST APIs with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Spring Boot 4 Microservices & REST APIs?
No prior experience is required. Spring Boot 4 Microservices & REST APIs on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Micrometer Tracing” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Spring Boot 4 Microservices & REST APIs lesson?
Yes. Every Spring Boot 4 Microservices & REST APIs lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.