Quick revision
The short answer
I would make correlation the first rule: every log event carries the trace id and span id, put into the MDC by Micrometer Tracing or the OpenTelemetry Java agent, so any log line leads to its trace and back. Code keeps logging through SLF4J, and the bridge to OpenTelemetry is an appender or the agent, not a code change. Each signal does its own job, metrics for rates, traces for where time goes and logs for detail and errors, and logs flow either through an OpenTelemetry Collector over OTLP for one consistent pipeline or through the classic shipper during the transition, rolled out through the shared starter with measured overhead and sampling rules that keep traces and logs consistent.
What to remember
In this answer, we designed the link between logging and tracing for 150 services. Correlation comes first, with trace and span ids placed in the MDC by Micrometer Tracing or the OpenTelemetry agent and fixed field names in a structured format. Code keeps the SLF4J API, logs move to an OpenTelemetry Collector with consistent resource attributes while the classic shipper stays during the transition, and each signal does its own job. We rolled it out through the shared starter in measured waves, with an explicit sampling rule, and covered context propagation for virtual threads and reactive code.
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.
I would make correlation the first rule: every log event carries the trace id and span id, put into the MDC by Micrometer Tracing or the OpenTelemetry Java agent, so any log line leads to its trace and back. Code keeps logging through SLF4J, and the bridge to OpenTelemetry is an appender or the agent, not a code change. Each signal does its own job, metrics for rates, traces for where time goes and logs for detail and errors, and logs flow either through an OpenTelemetry Collector over OTLP for one consistent pipeline or through the classic shipper during the transition, rolled out through the shared starter with measured overhead and sampling rules that keep traces and logs consistent.
Why this question is asked
In many companies, logs, metrics and traces grew up separately: one team runs the log platform, another the metrics system, a third adopted tracing for a few services. During an incident, engineers jump between three tools and try to match timestamps by eye. OpenTelemetry offers a way to connect them, but across 150 services the question is not which library to add; it is what contract to set so the signals fit together without rewriting applications. Interviewers ask this to see whether we can design that contract and roll it out safely. In this answer, we will recap the three signals and OpenTelemetry's role, design correlation through the MDC, choose the shipping path, divide work between the signals, plan the rollout through a shared starter, and handle virtual threads and reactive code.
1A Quick Recap of the Three Signals
Metrics are numbers aggregated over time, such as requests per second or the 99th percentile latency, cheap to store and ideal for dashboards and alerts. Traces record the path of one request through many services as a tree of spans, where a span is one timed operation, such as an HTTP call or a database query, identified by a span id and sharing a trace id with the rest of the request. Logs are individual events with free text and fields, the most detailed and the most expensive signal.
OpenTelemetry is an open standard and set of tools for all three. It defines a data model, a wire protocol called OTLP, SDKs and a Java agent that instruments common libraries automatically, and the Collector, a separate process that receives, processes and exports telemetry to back ends. It does not replace SLF4J in our code; it gives logs a standard way to travel and to carry trace context.
2Correlate First: Trace Ids in Every Log Event
The single most valuable step is putting the trace id and span id on every log line. Then an error log links straight to the trace that shows which downstream call was slow, and a slow trace links to the detailed logs of exactly that request.
Both common stacks already do this through the MDC, the per-thread map that a logging framework copies into each event. In Spring Boot 3 and later, Micrometer Tracing with an OpenTelemetry bridge creates spans for incoming and outgoing calls and puts traceId and spanId into the MDC, and Boot's default log pattern adds them when tracing is present. The OpenTelemetry Java agent can do the same for Logback and Log4j2 without any code, using MDC keys such as trace_id and span_id. The decision for the platform is to pick one of the two per service type and fix the field names, so that the log store has one trace id field across all 150 services.
Notice that the application code did not change. The ids come from the tracing layer through the MDC, and the structured format names the fields. Whatever format we choose, the shared starter should fix it, because a log store with traceId in some services and trace_id in others breaks every cross-service query.
3Choosing How Logs Travel
There are two ways to move logs from 150 services to the back end. The classic path writes JSON to stdout, and a node agent such as Fluent Bit or Vector ships it to the log store. It is proven, it keeps the application out of the delivery path, and our log platform team already runs it.
The OpenTelemetry path sends logs as OTLP to a Collector, either from an OpenTelemetry appender attached to Logback or Log4j2 in the application, from the Java agent, or by having the Collector itself read container stdout with its file log receiver. The advantage is one pipeline for all three signals, with the same resource attributes, such as service.name, service.version and deployment.environment, attached to logs, metrics and traces alike, and a single place for processing such as removing personal data.
I would choose the Collector as the target, but with the Collector reading stdout or receiving OTLP from a local agent, so that applications never block on a remote endpoint. The classic shipper remains during the transition, and the move is a change in the platform, not in 150 code bases.
- Application codeSLF4J API only; no OpenTelemetry imports needed
- Logback or Log4j2 with MDCtrace and span ids injected by Micrometer Tracing or the agent
- OutputJSON to stdout, or OTLP to a local Collector
- OpenTelemetry Collectoradds resource attributes, redacts, samples, batches
- Back endslog store, trace store, metrics store, linked by trace id
5 layers, from the top down. Step through them one at a time.
Only the two lowest layers know which vendor stores the data.
4Avoiding Duplicate Information
Once the signals are connected, we can stop asking each to do the others' job. Rates and counts belong in metrics: a log line per request just to count requests costs far more than a counter and is slower to query. Latency breakdown belongs in traces: a log line saying 'calling inventory took 340 ms' duplicates a span that already holds that timing with more context. Logs keep what only they can hold, such as the reason a payment was declined, a validation failure with its input or a stack trace.
Writing this down as guidance in the shared starter's documentation, with examples, typically cuts log volume noticeably, because many INFO lines exist only to measure or count.
5Rolling Out Through the Shared Starter
Across 150 services, the only practical delivery vehicle is the company's shared Spring Boot starter, plus agent configuration in the base container image for services that are not on Spring Boot. A new starter version brings the tracing dependencies, the JSON log format with fixed field names, the sampling defaults and the exporter settings. Teams adopt it with a version bump.
We roll it out in waves, starting with a few services on a critical request path so we can show the end-to-end benefit, then the rest. In each wave we measure overhead, mainly CPU and allocation from span creation and the latency added at high percentiles, and compare with the previous version; a budget such as 'under 2 percent CPU at p99 load' makes the review objective.
Sampling needs one explicit rule. If traces are sampled at 10 percent, then 90 percent of log lines carry a trace id whose trace was never stored, and clicking from log to trace finds nothing. Common answers are to always keep traces with errors through tail sampling in the Collector, to log the sampled flag so the user interface can show whether a trace exists, and to keep logs themselves unsampled at WARN and above, so that sampling is consistent and understood rather than accidental.
- Bump the shared starter in pilot servicestracing, JSON format, exporter
- Overhead within budget?YesContinue to the next waveNoTune sampling or instrumentation first
- Logs link to traces in the UI?YesMark wave doneNoFix field names or propagation
3 steps in order. Play them, or step through them one at a time.
6Follow-up questions
What happens to log correlation with virtual threads and reactive code?
The MDC is a thread-local map. With virtual threads it works naturally for code that runs on one virtual thread per request, but values are not copied automatically to other threads we start, so executors must propagate context, for example with Micrometer's context-propagation wrappers. In reactive code, a request hops between threads, so thread-locals are wrong at almost any moment; Reactor stores context in its own Context, and with automatic context propagation enabled (Hooks.enableAutomaticContextPropagation() and the context-propagation library) Micrometer restores the MDC around each operator so log lines get the right ids.
Should applications use the OpenTelemetry Logs API directly?
Generally no. The OpenTelemetry logs bridge API is meant for appenders and agents, not for application code. Keeping SLF4J in the code means teams change nothing, and the bridge can be replaced without touching business logic.
Agent or Micrometer Tracing for Spring Boot services?
Both work. Micrometer Tracing is native to Spring Boot, configured with properties and visible in code reviews, while the agent instruments more libraries automatically without code changes but adds startup cost and a separate upgrade path. I would standardise on one per service type and make sure both produce the same field names and resource attributes.
7Conclusion
In this answer, we designed the link between logging and tracing for 150 services. Correlation comes first, with trace and span ids placed in the MDC by Micrometer Tracing or the OpenTelemetry agent and fixed field names in a structured format. Code keeps the SLF4J API, logs move to an OpenTelemetry Collector with consistent resource attributes while the classic shipper stays during the transition, and each signal does its own job. We rolled it out through the shared starter in measured waves, with an explicit sampling rule, and covered context propagation for virtual threads and reactive code.
Open with
I would start with correlation, because that gives the biggest benefit for the least change. Every log event should carry the trace id and span id. In Spring Boot that comes from Micrometer Tracing with the OpenTelemetry bridge, which puts the ids in the MDC, and for other services the OpenTelemetry Java agent can inject them into Logback or Log4j2.
Then, if they want more
The shared starter fixes the JSON format and field names, so the log store has one trace id field across all 150 services and you can jump from an error log to its trace and back. Application code keeps using SLF4J; the bridge to OpenTelemetry is an appender, the agent or the Collector, never a code change.
For transport I would move towards an OpenTelemetry Collector, either reading container stdout or receiving OTLP locally, because one pipeline gives the same resource attributes on logs, metrics and traces and one place for redaction and sampling, while keeping the existing shipper during the transition so the app never blocks on a remote endpoint.
I would also set guidance on what each signal is for: metrics for rates and counts, traces for latency breakdown, logs for details and errors, which usually cuts log volume. Rollout goes through the starter in waves, measuring CPU and tail latency against a budget.
And I would define sampling explicitly, for example tail sampling that keeps error traces and unsampled WARN logs, so log-to-trace links do not silently lead nowhere.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 3
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
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 "Logs, metrics and traces are handled by different libraries and teams in your company....": https://scrivio-interview-library.netlify.app/java/java-logging/3a926210db/