Repository navigation
fix(next): bundle the instrumentation factory and stop capturing evlog's own output - #816
Merged
Merged
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
Thank you for following the naming conventions! 🙏 |
Contributor
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (8)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@evlog/cli
evlog
@evlog/nuxthub
@evlog/signals
@evlog/telemetry
commit: |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
No issue. Reported by a user deploying
defineNodeInstrumentationto Vercel.📚 Description
Two bugs in
evlog/next/instrumentation, both hit withdefineNodeInstrumentation({ ..., captureOutput: true }).Every route returns 500 once deployed. The gate loaded
evlog/next/instrumentation/createthrough a computedimport(/* webpackIgnore: true */ ...). Turbopack keeps it as a bare runtime import and the output file trace does not include evlog, soregister()throwsCannot find package 'evlog'on Vercel or a copiedstandalonebuild, and Next.js fails every request. With webpack the trace includes evlog, but the factory loads unbundled fromnode_modules, whereNEXT_RUNTIMEis not inlined, so itsNEXT_RUNTIME === 'nodejs'check seesundefinedandcaptureOutputnever applies.The gate now runs
if (process.env.NEXT_RUNTIME === 'nodejs') await import('./instrumentation-create'). Both bundlers inlineNEXT_RUNTIME: the Node.js build bundles the factory and the logger intoinstrumentation.js, and the Edge build drops the branch. No change toexports.Drains receive every event twice. In JSON mode,
outputWideEventwrites throughconsole.log/console.error, and the patchedprocess.stdout.write/process.stderr.writecaptured that line again aslog.info/log.error. Pretty output already bypassed the patch through a global slot holding the native write. That slot is replaced by a__evlogOwnOutputflag set around every write evlog makes itself, and both patches pass flagged writes through.Verification
Next.js 16.4.0,
output: 'standalone', with the standalone output copied to a directory that has no parentnode_modules, as on Vercel. Routes:POST /api/webhook(withEvlog),GET /api/hello(plainconsole.log),GET /api/edge(Edge runtime).console.logcapturedregister()throwsOn this branch,
evlogis absent from the deployednode_modulesand no Edge output file contains the logger, on either bundler. Server output after the fix (Turbopack), with the wide event printed once and the route'sconsole.logcaptured:Tests:
test/next/instrumentation-bundle.test.tsbundles a rootinstrumentation.tsfromdistwith esbuild (NEXT_RUNTIMEdefined,nextexternal), runsregister()in a temp directory with nonode_modules, and checks the Edge bundle leaves the logger out. The Node.js case failed onmainwithERR_MODULE_NOT_FOUND.captureOutputtests intest/next/instrumentation.test.tsassert the drain receives one event for JSON output and nothing extra for pretty and tagged output. Onmainthe drain received 4 events.pnpm run lint,pnpm run typecheck(includingevlog-telemetry),pnpm run test,pnpm test:coverageandpnpm api:snapshot(no diff) pass locally.📝 Checklist
Summary by CodeRabbit
node_modulesand works with both Turbopack and webpack.silentis disabled; withsilentenabled, original output remains available alongside drain delivery.