Skip to content

Commit b395b6f

Browse files
JPeer264claude
andcommitted
fix(server-runtime-injection): Patch _compile on the sync hooks path
From Node 24.13 on, injection registers `Module.registerHooks` instead of `Module.register`, and that branch had no `Module.prototype._compile` patch. A runner that compiles CommonJS itself takes over `require`, so the files it pulls in never reach the sync load hook. Under `tsx` the sync hook saw 2 of the 32 express files a plain `node` run delivers, and `express/lib/router/index.js` was not among them, so no express span was recorded and `http.server` segments kept the bare `GET` name. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 00507f8 commit b395b6f

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

packages/server-runtime-injection/src/register.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ export function registerDiagnosticsChannelInjection(): void {
166166
if (typeof mod.registerHooks === 'function' && stableSyncHooks) {
167167
initialize({ instrumentations: SENTRY_RUNTIME_INSTRUMENTATIONS });
168168
mod.registerHooks({ resolve, load });
169+
// ALSO patch `Module.prototype._compile`, as the `Module.register` branch below does. A
170+
// runner that compiles CommonJS itself (`tsx`, `ts-node`) takes over `require`, so the files
171+
// it pulls in never reach the sync load hook and load untransformed; `_compile` still sees
172+
// them. A file both of them see is transformed twice, and the second pass finds the call
173+
// shapes it matches already wrapped, so no channel ends up published twice.
174+
new ModulePatch({ instrumentations: SENTRY_RUNTIME_INSTRUMENTATIONS }).patch();
169175
debug.log('Registered diagnostics-channel injection via Module.registerHooks()');
170176
} else if (typeof mod.register === 'function' && !globalAny.Bun && !globalAny.Deno) {
171177
// `Module.register` + the `_compile` patch is Node 18.19–24.12 / 25.0

0 commit comments

Comments
 (0)