Quick revision
The short answer
We adopt one standard for the whole fleet: W3C trace context propagated by Micrometer Tracing or OpenTelemetry in every service, with traceId and spanId written into every log line through the MDC and structured logging. We make sure the gateway, async executors and messaging carry the context too, deliver all of it through a shared starter, prove it with an end-to-end test that follows one request across services, and teach teams to start every investigation by searching for the trace id.
What to remember
In this answer, we introduced correlation across 20 services by choosing W3C trace context with Micrometer Tracing or OpenTelemetry everywhere, writing traceId and spanId into every log line through the MDC and structured JSON with fixed field names, and closing the gaps at the gateway, in async executors and in messaging. We delivered it through a shared starter, proved it with a nightly end-to-end test that searches for one trace id across services, and made it part of runbooks and training so investigations start with the trace id.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
We adopt one standard for the whole fleet: W3C trace context propagated by Micrometer Tracing or OpenTelemetry in every service, with traceId and spanId written into every log line through the MDC and structured logging. We make sure the gateway, async executors and messaging carry the context too, deliver all of it through a shared starter, prove it with an end-to-end test that follows one request across services, and teach teams to start every investigation by searching for the trace id.
Why this question is asked
With 20 services, one customer request may touch five or six of them, and each writes its logs separately. Without a shared id, an investigation means matching timestamps by hand across dashboards, which is why it takes hours. Interviewers ask this as a scenario question because the technology is mostly ready-made; the hard parts are consistency across many teams, the gaps where context gets lost, and changing how people investigate. In this answer, we will recap how trace context works, choose the standard, put the ids into logs, close the gaps at the gateway, in async code and in messaging, roll it out through a starter with a test that proves it, and make it part of how teams work.
1A Quick Recap of Trace Context
Distributed tracing gives every incoming request a trace id, a random 128-bit value written as 32 hex characters, and gives every unit of work inside it a span id of 16 hex characters. When service A calls service B, A sends the trace id and its current span id in a header, and B continues the same trace with a new span. So all the work for one request, in every service, shares one trace id.
The W3C Trace Context standard defines that header as traceparent, for example 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01, which holds a version, the trace id, the parent span id and a sampled flag. Because it is a standard, a Java service, a Node gateway and a Python job can all continue the same trace. That is the key property for a fleet: we need one id that crosses every boundary, not one per team.
6 messages in order. Play them, or step through them one at a time.
Every log line, in every service, carries the same trace id 4bf9.
2Choosing One Standard for 20 Services
We decide once: W3C propagation everywhere, and one instrumentation approach per language. For Spring Boot services that is Micrometer Tracing with either the Brave or the OpenTelemetry bridge, which Boot auto-configures together with Actuator; services in other languages use OpenTelemetry SDKs, which speak the same header. If some services still use the older B3 headers from Zipkin, we configure them to accept both B3 and W3C during the migration and to send W3C.
Notice what we are not deciding yet: whether to store traces. Correlation only needs the ids to be propagated and logged. A tracing backend such as Tempo, Jaeger or Zipkin is very useful, but we can start with a low sampling rate, for example 10 percent of traces exported, because the trace id is created and logged for every request whether or not the trace itself is sampled for export. Check that your setup behaves this way: the id must exist even when sampling says no.
3Putting Trace Ids Into Every Log Line
Micrometer Tracing writes traceId and spanId into the MDC for the current thread. We then need every service to print them in the same field names, and the simplest way is structured JSON logging, which Spring Boot supports out of the box since 3.4.
The field names matter more than they seem. If ten services write traceId and five write trace_id, a search in the log platform misses a third of the lines. So the starter fixes the format and the names, and the log platform indexes traceId as a keyword field. With plain-text logs we can still add the ids to the pattern, but JSON is what makes the search reliable.
4Closing the Gaps: Gateway, Async Work and Messaging
Most correlation projects fail at the edges, where a request leaves the code path that tracing instruments automatically. The gateway or load balancer is the first edge: it should start the trace, or forward an incoming traceparent, and log the trace id in its access log, so that the first line of every request is searchable too.
The second edge is asynchronous work inside a service. The MDC lives in a ThreadLocal, so @Async methods, CompletableFuture stages and custom thread pools lose the context unless their executors are decorated, for example with Spring's ContextPropagatingTaskDecorator. Reactive services need automatic context propagation enabled in Reactor.
The third edge is messaging. Spring Kafka and Spring AMQP can add the trace headers to each message and continue the trace in the listener, but observation must be switched on for templates and listener containers (properties such as spring.kafka.template.observation-enabled and spring.kafka.listener.observation-enabled; check your version). Scheduled jobs and batch steps start their own traces, which is fine as long as they log them. We list these edges explicitly in the rollout plan, because each one is a place where the trace id silently disappears.
5Rolling It Out Through a Starter and Proving It
We do not ask 20 teams to configure this by hand. A platform team ships an internal Spring Boot starter, a dependency that brings the tracing bridge, the exporter, the structured logging defaults, the executor decorator and the messaging observation settings. A team adds one dependency and gets the standard; the starter's version tells us which services are on it.
Then we prove it. An end-to-end test in a shared environment sends one request with a known traceparent through the gateway, waits for the flow to finish, and queries the log platform for that trace id. It asserts that lines from every expected service are present, including the Kafka consumer. Run nightly, this test catches the service that upgraded a library and lost propagation, before an incident does.
- Agree W3C and field namesone decision for all teams
- Build the startertracing, JSON logs, executors, messaging
- Pilot on one request pathgateway, 3 to 4 services
- End-to-end trace testevery service logs the trace id?
- Roll out in wavestrack starter adoption per service
- Train and update runbooksstart with the trace id
6 steps in order. Play them, or step through them one at a time.
6Making Teams Use It
The tooling only shortens investigations if people use it. We return the trace id to clients in a response header and show it on error pages, so support tickets arrive with it. Runbooks start with "find the trace id, then search all logs for it". Dashboards link from a slow request in a metric to its trace, and from the trace to its logs. A one-hour session per team, with a real past incident replayed using the trace id, usually convinces people faster than any document.
We also measure the result: the share of services on the starter, the share of log lines that carry a traceId field, and the time spent in the investigation phase of incidents. If investigations dropped from hours to around 15 minutes for the first incidents after the rollout, that is the number that keeps the work funded.
7Follow-up questions
Do we need a tracing backend, or are trace ids in logs enough?
Trace ids in logs alone already solve the correlation problem: one search returns every line of the request. A tracing backend adds the timing picture, showing which span took 2 seconds, and is worth adding, but it can come later and can use sampling to control cost. The ids must be created and logged for every request regardless of sampling.
What if some services cannot be changed quickly, such as a legacy system?
We make the boundary visible. The service in front of it logs the trace id together with whatever id the legacy system returns, such as a transaction number, so investigators can make the jump. If the legacy system accepts a free-form header or field, we pass the trace id through it so its own logs can include it later.
Why use W3C traceparent rather than our own X-Correlation-Id header?
Because tracing libraries, gateways, cloud load balancers and services in other languages already understand it, so propagation works without custom code in each one. An internal header would need its own filters, client interceptors and message handling in every language, and it would not connect to traces. We can still log an existing correlation id next to the trace id during a transition.
8Conclusion
In this answer, we introduced correlation across 20 services by choosing W3C trace context with Micrometer Tracing or OpenTelemetry everywhere, writing traceId and spanId into every log line through the MDC and structured JSON with fixed field names, and closing the gaps at the gateway, in async executors and in messaging. We delivered it through a shared starter, proved it with a nightly end-to-end test that searches for one trace id across services, and made it part of runbooks and training so investigations start with the trace id.
Open with
I would make one fleet-wide decision first: W3C trace context propagation, using Micrometer Tracing with the Brave or OpenTelemetry bridge in the Spring services and OpenTelemetry in the others, since they all speak the traceparent header.
Then, if they want more
Then every log line must carry traceId and spanId. Tracing puts them in the MDC, and I would standardise on structured JSON logging with fixed field names, because if half the services write trace_id the search misses lines.
Next I would close the gaps, because that is where correlation usually breaks: the gateway must start or forward the trace and log it, async executors need a context-propagating TaskDecorator, Reactor needs automatic context propagation, and Kafka templates and listeners need observation enabled so the headers travel with messages.
I would package all of this into an internal starter so teams add one dependency instead of configuring twenty services by hand, and track adoption by starter version. To prove it, a nightly end-to-end test sends a request with a known traceparent and checks that every expected service, including consumers, logged that trace id.
Finally, I would return the trace id to clients, put it into runbooks, and train teams with a replayed incident, and I would measure investigation time before and after.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Incident investigations take hours because logs from 20 services cannot be correlated....": https://scrivio-interview-library.netlify.app/spring-boot/boot-logging/9157d279b6/