0Pricing
Spring Boot 4 Microservices & REST APIs · Aula

Correlacionando registros e rastreamentos

Conecte registros ao contexto do rastreamento.

Correlacionando registros e rastreamentos é uma aula grátis de Spring Boot 4 Microservices & REST APIs no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Spring Boot 4 Microservices & REST APIs, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Spring Boot 4 Microservices & REST APIs inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Linking logs to traces

Traces show the request flow; logs show the details. Putting the traceId into every log line lets you jump from a trace to its exact logs - and vice versa.

What is MDC?

MDC (Mapped Diagnostic Context) is a per-thread key/value map provided by SLF4J/Logback. Values placed in it can be printed in every log line by the layout pattern.

Micrometer populates the MDC

Micrometer Tracing automatically puts the current traceId and spanId into the MDC, so they are available to the logging framework without manual code.

Adding IDs to the log pattern

Reference the MDC keys in your Logback pattern so each line carries the IDs.

# logback-spring.xml pattern
# %d{ISO8601} [%X{traceId:-},%X{spanId:-}] %-5level %logger - %msg%n

Spring Boot default pattern

Spring Boot can inject the IDs for you. Setting the application name enables the default correlation pattern that prepends [app,traceId,spanId] to logs.

spring:
  application:
    name: order-service
# logs become: [order-service,4bf9...,00f0...] INFO ...

A correlated log line

The result looks like this - the bracketed IDs tie the line to a specific trace and span.

// 2026-05-30 10:00:00 [order-service,4bf92f35...,00f067aa...] INFO  c.a.OrderService - Order placed

Searching by traceId

With IDs in logs, your log aggregator (ELK, Loki, etc.) can filter by traceId. Copy an id from Zipkin, paste it into the log search, and see every related log line.

Custom baggage in logs

You can also surface baggage (e.g. tenant id) in logs by mapping a baggage field into the MDC, enriching every line with business context.

management:
  tracing:
    baggage:
      correlation:
        fields: tenantId

Two-way navigation

The goal is bidirectional: from a slow span in Zipkin -> open its logs by traceId; from an error log -> open its trace in Zipkin. This dramatically speeds up debugging.

Keep IDs out of business logs by accident

Because IDs come from MDC, they appear only when a trace is active. Background threads without a trace context show empty IDs (%X{traceId:-} renders blank) - which is expected.

Structured logging

For best results emit logs as JSON with traceId/spanId as proper fields, so log tools can index and link them reliably instead of parsing text.

Quick Check

Test your correlation knowledge.

Recap

You correlated logs and traces:

  • Micrometer puts traceId/spanId into the MDC
  • Reference them in the Logback pattern (or use Boot's default)
  • Search logs by traceId to jump between traces and logs
  • Prefer structured JSON logs for reliable indexing

Perguntas Frequentes

A aula “Correlacionando registros e rastreamentos” é grátis?

Sim — o texto completo de “Correlacionando registros e rastreamentos” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Spring Boot 4 Microservices & REST APIs, atualize para CoddyKit PRO. O curso de Spring Boot 4 Microservices & REST APIs inclui 4 aulas no total.

O que vou aprender em “Correlacionando registros e rastreamentos”?

Conecte registros ao contexto do rastreamento. Você pratica Spring Boot 4 Microservices & REST APIs com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Spring Boot 4 Microservices & REST APIs?

Nenhuma experiência prévia é necessária. Spring Boot 4 Microservices & REST APIs no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Correlacionando registros e rastreamentos”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Spring Boot 4 Microservices & REST APIs?

Sim. Cada aula de Spring Boot 4 Microservices & REST APIs inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Por que o rastreamento distribuído é importante
  2. Rastreamento com Micrometer
  3. Exportando rastreamentos para o Zipkin
  4. Correlacionando registros e rastreamentos
← Voltar para Spring Boot 4 Microservices & REST APIs