« All posts

Fixing JavaScript Observability Without Monkey-Patching

Sentry engineers are pushing Node's TracingChannel API into pg, mysql2, and redis to replace fragile JavaScript APM monkey-patching.

An engineer at Sentry is leading a cross-ecosystem push to eliminate the monkey-patching (import-in-the-middle/require-in-the-middle) that server-side JavaScript APM tools rely on today. That approach breaks under ESM, conflicts with bundlers, and depends on internal library details no vendor controls. The proposed fix is Node's built-in TracingChannel API from diagnostics_channel: libraries emit structured events without any patching, and APM tools subscribe to build spans from them.

The team first proved the pattern by hand-adding TracingChannel support across the unjs ecosystem (h3, srvx, unstorage, db0, Nitro), then opened discussions with the OpenTelemetry JS community and brought in Stephen Belanger, creator of diagnostics_channel, to help push adoption. They approached pg, mysql2, and redis — top database drivers accounting for over 60 million weekly downloads combined — offering to fully own the implementation and support, and all three agreed.

Recognizing that one person can't manually instrument dozens of libraries, the engineer built an AI-assisted workflow using Claude Code to handle research, implementation, PR feedback triage, and tracker updates, while keeping architecture decisions, maintainer communication, and final code review strictly human-led, with AI contributions disclosed transparently in every commit.

» SourceSentry Blog