Loading…
Fixing JavaScript observability, one library at a time
SentryAbdelrahman Awad
Summary
JavaScript application performance monitoring tools rely on monkey-patching via require-in-the-middle and import-in-the-middle, which breaks with ECMAScript Modules, bundlers, and non-Node runtimes. To solve this, an initiative is replacing monkey-patching with Node's built-in diagnostics_channel TracingChannel API across server-side JavaScript libraries. Under this pattern, libraries publish structured events while monitoring vendors subscribe to them with zero overhead when unlistened. The author leveraged Claude Code workflows alongside direct maintainer communication to draft proposals, implement code, and manage reviews across 44 target packages. Ten libraries including mysql2, node-redis, ioredis, and unjs modules have merged support, while active efforts continue on shared OpenTelemetry mapper registries and remaining ecosystem packages.
Context
JavaScript APM tools rely on runtime monkey-patching via IITM and RITM, which causes fragility with ECMAScript Modules, strict initialization ordering, bundlers, and non-Node runtimes like Bun and Deno.
Approach / What changed
Migrating ecosystem libraries to emit native structured events via Node's diagnostics_channel TracingChannel API, using Claude Code to handle research, boilerplate implementation, and review triage across 44 libraries.
Takeaways
- TracingChannel operates with zero overhead when no subscribers are listening, works across Node, Bun, and Deno, and avoids loader hooks or bundler conflicts.
- Adoption is progressing across 44 tracked libraries, with 10 already merged, including mysql2, node-redis, ioredis, h3, srvx, and unstorage.
- A planned shared mapper registry will translate TracingChannel events into standardized OpenTelemetry semantic conventions so multiple APM vendors avoid duplicated consumer mapping.
Related reading
Sentry ·
When and what should I be logging?
Targeted structured logging provides a fast way to capture operational behavior in production without requiring new deployments for debugging. Developers benefit most from logging key runtime decisions, multi-step algorithm outcomes, mutating audit operations, and context around non-critical or retried errors. Rather than outputting plain text, applications should record structured key-value pairs that capture who performed an action, what occurred, and associated trace identifiers. Sensitive information such as secrets and personally identifiable data must be excluded or scrubbed, and large unparsed payloads should be avoided to prevent excessive costs. Managing log levels appropriately and treating logs as potentially temporary instrumentation helps maintain actionable telemetry without generating unnecessary noise.
Ben CoeSentry ·
Errors, traces, logs, metrics: when to reach for what