Skip to content

Middleware wrapping call with AsyncLocalStorage.run() #1650

Answered by RobinTail
crummy asked this question in Q&A
Discussion options

You must be logged in to vote

Hello, @crummy

There is a dedicated article on that topic:
https://github.com/RobinTail/express-zod-api?tab=readme-ov-file#child-logger

Implying that your logger has a .child() method:

import { createConfig } from "express-zod-api";
import { randomUUID } from "node:crypto";

const config = createConfig({
  // logger: ...,
  childLoggerProvider: ({ parent, request }) =>
    parent.child({ requestId: randomUUID() }),
});

Basically you simply create another instance of the logger inside that function, that somehow displays the request ID.
So that you don't even need the storage — this approach enables a dedicated instance of the logger for the individual request.
I hope it helps.

Replies: 2 comments 12 replies

Comment options

You must be logged in to vote
3 replies
@crummy
Comment options

@RobinTail
Comment options

@crummy
Comment options

Comment options

You must be logged in to vote
9 replies
@crummy
Comment options

@RobinTail
Comment options

@crummy
Comment options

@RobinTail
Comment options

@RobinTail
Comment options

Answer selected by RobinTail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants