Java and Spring Level 2 This level · 65 of 84
Medium java spring

Request fails three services deep, independent logs, no correlation ID?

The 30 second answer

You cannot stitch one request's logs across services, so debugging becomes timestamp guessing and mean time to recover goes up. Use distributed tracing with W3C traceparent propagation. In Spring Boot, Micrometer Tracing with an OpenTelemetry or Brave bridge propagates trace and span ids through instrumented clients and puts them in the log MDC. Centralize logs and return the trace id to clients on errors.

Could you say this in an interview?

You can't stitch one request's logs across services — debugging is timestamp guessing, slow MTTR. Fix: distributed tracing with W3C traceparent propagation; in Spring Boot, Micrometer Tracing (OTel or Brave bridge) auto-propagates trace/span ids through instrumented clients and adds them to the log pattern (MDC); centralize logs; return the trace id to clients in error responses.

Alternate interview scenarios

"One request passes through multiple microservices. How would you trace it end-to-end?"

This is the design version of the question, and it has two traps. First, async hops do not carry trace context unless they are instrumented. With Spring Boot and Kafka I enable observation on the template and the listener, which is off by default, so the trace headers travel with the record. Second, Spring Boot samples only 10% of traces by default, so the one request you need may not have been recorded. I set the sampling probability for my environment, or use tail sampling in the collector, and make every service use the same propagation format.

"Your logs are not enough to debug an issue. What would you improve?"

Missing correlation is only one of the gaps. I improve three things together. First, the logs themselves. I write structured JSON instead of free text, because Spring Boot can output ECS, GELF or Logstash format with logging.structured.format.console. Every line gets the trace ID, user or tenant, and business keys such as the order id. Errors are logged once, with the cause and the inputs that matter, and never with secrets or personal data. Second, metrics for questions logs answer badly, such as rate, errors and latency percentiles per endpoint, and pool and queue saturation. Third, traces for where the time went across services. I also make log levels changeable at runtime through Actuator's loggers endpoint, so I can turn on DEBUG for one package during an incident without redeploying.

Sources (6)
  1. W3C Trace Contextw3.org
  2. Spring Boot — Tracingdocs.spring.io
  3. Spring Boot: Application properties (spring.kafka.template.observation-enabled, management.tracing.sampling.probability)docs.spring.io
  4. Spring for Apache Kafka: Micrometer observationdocs.spring.io
  5. Spring Boot: Logging (structured logging)docs.spring.io
  6. Spring Boot: Actuator endpoints (loggers)docs.spring.io
Previous
Next