←back to thread

Next.js is infuriating

(blog.meca.sh)
1033 points Bogdanp | 4 comments | | HN request time: 0.638s | source
1. quadhome ◴[] No.45101055[source]
AsyncLocalStorage.enterWith is the wrong method; .enterWith changes the logger for across the *synchronous* execution. This doesn't matter if there's only one request happening at time-- like when you're testing locally. But that's why it didn't work on the actual project.

Use .run.

  return LoggerStorage.run(requestLogger(), () => {
      logger()?.debug({ url: request.url }, "Started processing request!");
      return NextResponse.next();
  });
replies(3): >>45101118 #>>45108197 #>>45108244 #
2. dminik ◴[] No.45101118[source]
Nope, this doesn't work either.
3. ◴[] No.45108197[source]
4. huksley ◴[] No.45108244[source]
I have enterWith working perfectly with async/sync flow - all operations between request and response are logged with request id transparently. I am using custom server for both standalone build & dev server, nextjs 14, node 22.