Monkey-patching has long been the standard approach for instrumenting Node.js libraries in APM tools like Sentry and OpenTelemetry, but it breaks down with ES Modules. Node.js's built-in Diagnostics Channels and Tracing Channels offer a better alternative: libraries can proactively emit structured telemetry data themselves, eliminating the need for runtime patching. Tracing Channels provide a full operation lifecycle (start, end, error, asyncStart) with automatic async context propagation, near-zero overhead when unused, and no dependency on specific vendors. The post covers naming conventions, code examples for both library authors and SDK consumers, and highlights growing ecosystem adoption in libraries like undici, fastify, mysql2, ioredis, and node-redis.

7m read timeFrom sentry.engineering
Post cover image
Table of contents
What Is Instrumentation?How server-side JavaScript is instrumentedLibraries Should Emit Their Own TelemetryHow Libraries Can Implement Tracing ChannelsThe Ecosystem Is Already MovingThe Vision Ahead

Sort: