0Pricing
Spring Boot 4 Microservices & REST APIs · Leçon

Traçabilité avec Micrometer

Instrumentez les services avec des identifiants de trace et de span.

Traçabilité avec Micrometer est une leçon Spring Boot 4 Microservices & REST APIs gratuite sur CoddyKit. Ceci est la leçon 2 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage Spring Boot 4 Microservices & REST APIs, et ta progression se synchronise sur le web et l'application CoddyKit. Le cours Spring Boot 4 Microservices & REST APIs comprend 4 leçons au total.

Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.

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

Questions Fréquemment Posées

La leçon « Traçabilité avec Micrometer » est-elle gratuite ?

Oui — le texte complet de « Traçabilité avec Micrometer » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours Spring Boot 4 Microservices & REST APIs, passe à CoddyKit PRO. Le cours Spring Boot 4 Microservices & REST APIs comprend 4 leçons au total.

Qu'est-ce que j'apprendrai dans « Traçabilité avec Micrometer » ?

Instrumentez les services avec des identifiants de trace et de span. Tu pratiques Spring Boot 4 Microservices & REST APIs avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.

Dois-je avoir de l'expérience pour commencer Spring Boot 4 Microservices & REST APIs ?

Aucune expérience préalable n'est requise. Spring Boot 4 Microservices & REST APIs sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 2 sur 4.

Combien de temps prend la leçon « Traçabilité avec Micrometer » ?

La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.

Peux-tu écrire et exécuter du code dans cette leçon Spring Boot 4 Microservices & REST APIs ?

Oui. Chaque leçon Spring Boot 4 Microservices & REST APIs inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.

Toutes les leçons de ce cours

  1. Pourquoi la traçabilité distribuée est importante
  2. Traçabilité avec Micrometer
  3. Exporter les traces vers Zipkin
  4. Corréler les journaux et les traces
← Retour à Spring Boot 4 Microservices & REST APIs