Scrivio Interview library
ScenarioAdvanced7 min read · updated 12 November 2026

Logs across your services are flooded with 300-line stack traces from framework layers, cost is high, and on-call engineers still cannot find root causes quickly. What would you change?

Most of the flood comes from logging the same exception at every layer that catches and rethrows it, so the first change is to log each exception exactly once, at the boundary where it is finally handled. Then we make each error easy to search and group: structured logs with the exception class, root cause and error code as fields and the full trace in one field, traces shortened with root-cause-first output and framework package filtering, and errors grouped by fingerprint in an error tracker linked by trace id. Finally we sample repetitive known errors and alert on new fingerprints rather than raw volume.

Why this question is asked

Logging cost is easy to ignore until the bill arrives. A busy platform that prints 300-line stack traces several times per failure can spend more on log storage than on compute, and the irony is that the noise makes incidents slower to resolve, not faster. Interviewers ask this scenario to see whether we can fix a cross-team practice rather than tune a single setting. In this answer, we will find out where the volume really comes from, change where exceptions are logged, make each log entry structured, shorten traces without losing them, group errors so engineers see causes rather than lines, and change alerting so it reacts to what is new.

1Where the Volume Really Comes From

Before changing anything, we measure. We take a day of logs and group them by exception class and logger. Typically two patterns dominate. The first is log-and-rethrow: a repository logs the exception and rethrows it, the service logs it again and wraps it, the controller logs it a third time, and a filter logs it once more. One failure becomes four full traces. The second is a handful of known, repetitive errors, such as a client sending bad tokens or one flaky downstream service, that produce the same trace thousands of times an hour.

Each trace is long because most of its frames belong to the framework: servlet filters, Spring's proxies and interceptors, Tomcat, reflection. Our own code is often 10 of 300 lines.

Java
// The anti-pattern, repeated in every layer
try {
return repository.load(id);
} catch (DataAccessException e) {
log.error("load failed", e); // trace #1
throw new ServiceException("Failed to load order " + id, e); // the controller will log trace #2
}

2Log Each Exception Once, at the Boundary

The rule is simple: a layer either handles an exception or passes it on, and only the layer that handles it logs it. Intermediate layers that need to add context do so by wrapping with a cause and a good message, not by logging. The handling boundary is usually a @RestControllerAdvice for HTTP, an error handler for Kafka listeners, or the top of a scheduled job.

Java
// Service layer: add context, do not log
catch (DataAccessException e) {
throw new ServiceException(ErrorCode.ORDER_LOAD_FAILED, "Failed to load order " + id, e);
}
// The one place that logs
@RestControllerAdvice
class ErrorHandler {
@ExceptionHandler(ServiceException.class)
ProblemDetail handle(ServiceException e) {
log.error("request failed code={}", e.code(), e); // one trace per failure
return ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR, e.code().value());
}
}
Step throughOne failure, before and after
RepositoryServiceController adviceLog store
before: full trace #1
before: full trace #2
before: full trace #3
after: throws with cause, no log
after: wraps with code and context, no log
after: one structured entry with the full chain

6 messages in order. Play them, or step through them one at a time.

This change alone often cuts trace volume by half or more, and it costs nothing at run time. We enforce it with code review guidelines and, where possible, a static analysis rule that flags catch blocks which both log and rethrow.

3Structured Logs With the Fields Engineers Search For

A trace printed as 300 separate text lines is hard to search and can be split into 300 log records by the shipper. Structured logging writes each event as one JSON object. We put the fields an on-call engineer filters on into their own keys: exception class, root cause class and message, error code, service, and the trace id that links the event to a distributed trace. The full stack trace goes into a single field of the same record.

Spring Boot 3.4 and later can write structured logs natively, for example with logging.structured.format.console=ecs or logstash; older setups use the logstash-logback-encoder. Either way, the query becomes errorCode:ORDER_LOAD_FAILED AND rootCause:PSQLException instead of a regular expression over raw text.

JSON
{"@timestamp":"2026-11-04T09:12:44Z","level":"ERROR","service":"orders",
"traceId":"4bf92f3577b34da6","errorCode":"ORDER_LOAD_FAILED",
"exception.class":"com.acme.ServiceException",
"rootCause.class":"org.postgresql.util.PSQLException",
"rootCause.message":"column o.status_code does not exist",
"stack_trace":"... one field, shortened ..."}

4Shorten Traces Without Losing Them

Next we make the trace itself shorter and more useful. Logback can print the root cause first with the %rootException conversion word (%rEx), so the line that matters is at the top. The logstash-logback-encoder's ShortenedThrowableConverter goes further: it can put the root cause first, limit the depth per exception, truncate after a set length, and drop frames from packages we list, such as org.apache.catalina, jdk.internal.reflect and the Spring AOP and CGLIB proxy frames, while keeping a count of what it omitted. Check your encoder version for the exact option names.

Shortening the logged copy is fine as long as the full trace stays retrievable. The error tracker described next keeps full traces for each group, and for rare cases we can keep a debug-level full trace that is only enabled when needed. A 300-line trace usually shrinks to 30 to 40 lines this way, with every frame from our own code still present.

5Group Errors by Fingerprint

Engineers do not need ten thousand copies of the same failure; they need to know there is one problem, how often it happens, since when, and in which release. Error trackers such as Sentry group events by a fingerprint, normally derived from the exception type and the frames of our own code, and show one issue with a count, first-seen time and a sample full trace. We link each issue to the trace id, so one click opens the distributed trace across services and the matching logs.

On-call engineers then ask which issues are new or growing since the last deploy, instead of searching for the last error.

Step throughFrom a thrown exception to an actionable signal
  1. Exception handled at the boundarylogged once
  2. Structured eventclass, root cause, code, trace id
  3. Error tracker fingerprints itexception type + own frames
  4. Known fingerprint?
    YesIncrement count, apply samplingNoCreate a new issue
  5. Alert on new or fast-growing issuesnot on raw log volume

5 steps in order. Play them, or step through them one at a time.

6Sample the Known, Alert on the New

Repetitive, understood errors, such as a client that keeps sending expired tokens, do not need a full trace every time. We log them at a lower level, without the trace, or sample them, for example the first event per minute with a full trace and the rest as counters. Metrics carry the true volume, so we lose no information about how often they happen.

Alerting changes in the same direction. Alerting on error log volume pages people for the same noisy known errors every night. Alerting on new fingerprints, on a known fingerprint's rate jumping well above its baseline, or on error rates from the service's own metrics points them at the change that actually matters. Together with the other changes, this cuts log cost and gets an engineer from page to root cause in minutes.

7Follow-up questions

Is it ever right to log at a lower layer?

Yes, when that layer handles the exception and does not rethrow it, for example a retry loop that logs a warning for each failed attempt and then succeeds. The rule is one log per handled exception, not one log only at the top.

Will shortening traces hide the real cause?

Not if we filter only framework packages and keep the root cause first. Our own frames and every Caused by header remain. For the rare case where a framework frame matters, the error tracker still holds a complete trace for each issue.

How do we roll this out across many teams?

Through the shared platform: a common logging configuration in the organisation's Spring starter with the structured format and throwable converter, a shared exception handler, and a dashboard showing log volume per service. Teams adopt the defaults by upgrading the starter, and the dashboard shows who still logs and rethrows.

8Conclusion

In this answer, we found that most stack trace volume comes from logging the same exception at every layer and from a few repetitive known errors. We logged each exception once at its handling boundary, wrote structured events with exception class, root cause, error code and trace id as fields, and shortened traces with root-cause-first output and framework package filtering while keeping full traces retrievable. We grouped errors by fingerprint in an error tracker linked to traces, sampled known repetitive errors, and alerted on new fingerprints and rate changes instead of raw volume.

What to say in the interviewAbout 90 seconds aloud

Open with

First I would measure where the volume comes from, and it is almost always the same two things: exceptions logged and rethrown at every layer, so one failure prints three or four full traces, and a few known errors repeated thousands of times.

Then, if they want more

So the first rule is log once, at the boundary where the exception is actually handled, like the controller advice or the listener's error handler. Lower layers add context by wrapping with a cause and an error code, but they do not log.

Second, structured logging: each event is one JSON record with the exception class, root cause class and message, error code and trace id as fields, and the full trace in a single field, so on-call can filter by root cause instead of grepping text.

Third, shorter traces: logback's root-cause-first output and the logstash encoder's throwable converter can filter framework packages like Tomcat, reflection and proxies, which takes 300 lines down to maybe 30 while keeping our own frames, and full traces remain retrievable in the error tracker.

Fourth, group errors by fingerprint in a tool like Sentry, linked by trace id, so engineers see one issue with a count and first-seen release. And finally I would sample known repetitive errors, keep their volume in metrics, and alert on new fingerprints or rate jumps rather than on log volume.

About this answer

Last updated
12 November 2026
Versions it names
Spring Boot 3.4
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.
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 across your services are flooded with 300-line stack traces from framework layers...": https://scrivio-interview-library.netlify.app/java/exceptions/5620956e37/