·4 min read
Hooks vs events: shaping every request without touching every method
Adding a trace header to every outgoing request shouldn't mean editing forty methods. Hooks and events are the two different tools for two different jobs.
3 posts
Adding a trace header to every outgoing request shouldn't mean editing forty methods. Hooks and events are the two different tools for two different jobs.
Structured logging only pays off if the data field has a stable shape you can query on. Nothing enforces that by default. Here's how to catch drift with schema validation that never drops the log line, using the Standard Schema spec so it works with Zod, Valibot, or nothing at all.
AsyncLocalStorage lets you stamp a request ID onto every log line without passing it through every function. But it can fail without throwing a single error — so your logs just quietly lose the ID. Here are the three cases I reproduced, and the two-minute check that catches them.