0Pricing
Spring Boot 4 Microservices & REST APIs · Lektion

Micrometer Tracing

Instrumentieren Sie Services mit Trace- und Span-IDs.

Micrometer Tracing ist eine kostenlose Spring Boot 4 Microservices & REST APIs-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Spring Boot 4 Microservices & REST APIs-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Spring Boot 4 Microservices & REST APIs-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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

Häufig gestellte Fragen

Ist die Lektion „Micrometer Tracing“ kostenlos?

Ja — der vollständige Text von „Micrometer Tracing“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Spring Boot 4 Microservices & REST APIs-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Spring Boot 4 Microservices & REST APIs-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Micrometer Tracing“?

Instrumentieren Sie Services mit Trace- und Span-IDs. Du übst Spring Boot 4 Microservices & REST APIs mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Spring Boot 4 Microservices & REST APIs zu starten?

Keine Vorkenntnisse erforderlich. Spring Boot 4 Microservices & REST APIs auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.

Wie lange dauert die Lektion „Micrometer Tracing“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Spring Boot 4 Microservices & REST APIs-Lektion Code schreiben und ausführen?

Ja. Jede Spring Boot 4 Microservices & REST APIs-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Warum verteiltes Tracing wichtig ist
  2. Micrometer Tracing
  3. Traces nach Zipkin exportieren
  4. Logs und Traces korrelieren
← Zurück zu Spring Boot 4 Microservices & REST APIs