Video in progress

How does tracing work in Spring Boot 3, and what happened to Spring Cloud Sleuth?

Sleuth doesn't work with Spring Boot 3. Micrometer Tracing took its place: it instruments through the Observation API, creates traces with an OpenTelemetry or Brave bridge, and adds the traceId to logs automatically.

📖 Answer

In Spring Boot 2, adding spring-cloud-starter-sleuth was enough. In Boot 3 the dependencies you need are:

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>
<dependency>
    <groupId>io.opentelemetry</groupId>
    <artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>

Plus Actuator. The settings:

management:
  tracing:
    sampling:
      probability: 0.1   # default 0.1; 1.0 in a local environment
  otlp:
    tracing:
      endpoint: http://otel-collector:4318/v1/traces

The core idea is the Observation API: a single Observation gives you both a metric (a Timer) and a span. Spring MVC, WebClient, RestClient, Spring Kafka and @Scheduled are instrumented through it. Spring Boot doesn't wrap JDBC itself: for that you need the separate datasource-micrometer library or the OTel agent.

In your own code:

Observation.createNotStarted("invoice.generate", observationRegistry)
        .lowCardinalityKeyValue("type", "monthly")
        .observe(() -> generate());

A lowCardinalityKeyValue goes to both the metric and the span. A highCardinalityKeyValue goes only to the span, which protects against the cardinality problem.

Something common in a migration: sampling. Since the default is 10%, you get the complaint "I can't see the traces". Another thing is the traceId in the log pattern. Boot 3.2+ adds it itself through logging.pattern.correlation, and hand-written patterns in the old Sleuth style need updating.