Logging in NestJS, for Spring Developers: Four Lines, Two Ids

1 October 2026 nestjstypescriptnodejsjavaspring-bootlogging
PDF The design sheet The full architecture and the verified references. Free, no email.
Thumbnail for Logging in NestJS, for Spring Developers: Four Lines, Two Ids 3:52
Watch on YouTube, or read on below.
Run this yourself → Clone the repo, docker compose up, and watch it happen

One payment request logs from four places: the controller, a service, and two places that run later. Search the logs for its request id. Measured on 1 October 2026: structured logs tell you what happened, request context tells you which execution it belonged to.

JSON is one switch on both

Spring Boot: logging.structured.format.console=ecs. Nest: new ConsoleLogger({ json: true }). Both produced clean JSON. Neither switch invents a request id.

The request id

On Spring, a filter put it in the MDC. The default text pattern does not print the MDC at all. In ECS JSON the controller and service lines carried it; a CompletableFuture and an @Async method did not, because the MDC is thread local by default. A TaskDecorator fixed @Async; the common pool still had nothing.

On Nest, the built in logger carried it nowhere. With nestjs-pino taking it from the header, all four lines carried it, including after an await and inside a setTimeout callback: AsyncLocalStorage.

The full code for every measurement is in the repository, and the free design sheet above has the checklist on one page.


Watch next

New videos land on Code with Sam - subscribe there if this was useful.

Get the interview pack

A free, practical pack for engineers preparing for senior backend interviews - the questions that actually get asked, and how to answer them like someone who has done the work.

New articles and videos when they land. No spam, and one click to leave.