HeadlinesBriefing favicon HeadlinesBriefing.com

AsyncLocalStorage Boosts DrizzleORM Logging

Hacker News: Front Page •
×

Numeric’s engineering team hit a snag after swapping its legacy Postgres client for DrizzleORM. The new query builder offered type‑safe SQL generation but exposed only a pre‑execution logger, leaving out execution time, row count, and result data that their Datadog dashboards relied on and hindered their ability to trace slow queries.

The fix arrived via Node.js’s AsyncLocalStorage, a context‑propagation API that threads data through asynchronous call stacks. By creating a store at the start of each query, Numeric captured the query key and timestamp, let Drizzle’s logger inject SQL and parameters, then completed the log with duration and row count once the promise resolved.

With the three‑step wrapper—context setup, logger hook, and final emission—every database call now produces a structured line suitable for Datadog alerts and performance audits. Because the approach avoids prototype hacks, it scales cleanly across services. Watch for similar AsyncLocalStorage patterns in tracing tools like OpenTelemetry and error platforms such as Sentry.