0Pricing
Spring Boot 4 Microservices & REST APIs · Lección

Micrometer Tracing

Instrumente servicios con identificadores de trazas y spans

Micrometer Tracing es una lección gratuita de Spring Boot 4 Microservices & REST APIs en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Spring Boot 4 Microservices & REST APIs, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Spring Boot 4 Microservices & REST APIs incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

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: w3c

Baggage

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 Tracer to create custom spans, or use @NewSpan
  • Add tags/events; read traceId/spanId
  • Baggage propagates extra context

Preguntas frecuentes

¿La lección «Micrometer Tracing» es gratis?

Sí — el texto completo de «Micrometer Tracing» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Spring Boot 4 Microservices & REST APIs, actualiza a CoddyKit PRO. El curso de Spring Boot 4 Microservices & REST APIs incluye 4 lecciones en total.

¿Qué aprenderé en «Micrometer Tracing»?

Instrumente servicios con identificadores de trazas y spans Practicas Spring Boot 4 Microservices & REST APIs con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Spring Boot 4 Microservices & REST APIs?

No se requiere experiencia previa. Spring Boot 4 Microservices & REST APIs en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.

¿Cuánto tiempo toma la lección «Micrometer Tracing»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Spring Boot 4 Microservices & REST APIs?

Sí. Cada lección de Spring Boot 4 Microservices & REST APIs incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Por qué es importante el distributed tracing
  2. Micrometer Tracing
  3. Exportar trazas a Zipkin
  4. Correlacionar logs y trazas
← Volver a Spring Boot 4 Microservices & REST APIs