Skip to content

chore: Remove lazy loading for hook registration#22443

Open
timfish wants to merge 17 commits into
developfrom
timfish/chore/cleanup-hook-register
Open

chore: Remove lazy loading for hook registration#22443
timfish wants to merge 17 commits into
developfrom
timfish/chore/cleanup-hook-register

Conversation

@timfish

@timfish timfish commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

This PR simplifies the register.ts hook registration to remove all the lazy loading. The clankers seem to always resort to lazy loading but pushed hard enough they will find better alternatives 🤣

Once the lazy loading was removed there were a number of other things required to get this actually passing all the e2e tests:

  • Bundle the whole orchestrion runtime chain (@apm-js-collab/*, meriyah, esquery, …) into @sentry/server-utils' build (all now devDependencies). The dist only has relative requires, which removes two classes of breakage:
  • The Module.register async hook is now a self-referenced entrypoint of our own ESM build (@sentry/server-utils/orchestrion/hook), sharing the vendored chunks
  • The webpack/Turbopack loader ships as a bundled entrypoint (./orchestrion/webpack-loader), resolved by self-reference since the @apm-js-collab packages are no longer installed
  • Fix build-time Rollup ESM interop issues (Node builtins need default interop; default-only ESM deps need requireReturnsDefault: 'auto')
  • NextJS: force @sentry/server-utils external via absolute-path externals so register.ts stays in node_modules and its Module.register self-reference resolves under pnpm — also removes the tracingHooksPath workaround
  • Bumps the @sentry/node size limit by ~40kb — the lazy loading previously hid this code from the size report
  • feat: Remove support for initialising via --require #22513

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 27.79 kB - -
@sentry/browser - with treeshaking flags 26.23 kB - -
@sentry/browser (incl. Tracing) 46.31 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.06 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.12 kB - -
@sentry/browser (incl. Tracing, Replay) 85.59 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.23 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 90.29 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.97 kB - -
@sentry/browser (incl. Feedback) 44.96 kB - -
@sentry/browser (incl. sendFeedback) 32.59 kB - -
@sentry/browser (incl. FeedbackAsync) 37.64 kB - -
@sentry/browser (incl. Metrics) 28.88 kB - -
@sentry/browser (incl. Logs) 29.11 kB - -
@sentry/browser (incl. Metrics & Logs) 29.8 kB - -
@sentry/react 29.59 kB - -
@sentry/react (incl. Tracing) 48.6 kB - -
@sentry/vue 33.22 kB - -
@sentry/vue (incl. Tracing) 48.28 kB - -
@sentry/svelte 27.81 kB - -
CDN Bundle 30.11 kB - -
CDN Bundle (incl. Tracing) 48.14 kB - -
CDN Bundle (incl. Logs, Metrics) 31.69 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.47 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.95 kB - -
CDN Bundle (incl. Tracing, Replay) 85.72 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.01 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.49 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.78 kB - -
CDN Bundle - uncompressed 89.77 kB - -
CDN Bundle (incl. Tracing) - uncompressed 144.84 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.48 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 148.82 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 219.24 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.08 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.04 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 277.78 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 281.74 kB - -
@sentry/nextjs (client) 51.13 kB - -
@sentry/sveltekit (client) 46.75 kB - -
@sentry/core/server 80.07 kB - -
@sentry/core/browser 51.9 kB - -
@sentry/node 124.57 kB - -
@sentry/node (incl. diagnostics channel injection) 168.57 kB +12.41% +18.6 kB 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 166 B -99.77% -69.86 kB 🔽
@sentry/node - without tracing 74.66 kB - -
@sentry/aws-serverless 84.13 kB -0.01% -1 B 🔽
@sentry/cloudflare (withSentry) - minified 196.61 kB - -
@sentry/cloudflare (withSentry) 483.83 kB - -

View base workflow run

@timfish timfish changed the title chore: Cleanup hook registration chore: Remove lazy loading for hook registration Jul 21, 2026
@timfish
timfish marked this pull request as ready for review July 23, 2026 15:56
@timfish
timfish requested review from a team as code owners July 23, 2026 15:56
@timfish
timfish requested review from JPeer264, chargome, isaacs, mydea and nicohrubec and removed request for a team July 23, 2026 15:56

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 2705b96. Configure here.

};
import ModulePatch from '@apm-js-collab/tracing-hooks';
import { initialize, load, resolve, createDiagnosticsPort } from '@apm-js-collab/tracing-hooks/hook-sync.mjs';
import { setDiagnosticsHook } from '@apm-js-collab/tracing-hooks/lib/diagnostics.js';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eager orchestrion load on import

High Severity

register.ts now statically imports the full @apm-js-collab/tracing-hooks / transform chain. That module is pulled in by experimentalUseDiagnosticsChannelInjection, which @sentry/node re-exports statically, so any unbundled import/require of @sentry/node eagerly parses the vendored orchestrion runtime even when the experimental API is never called. Previously those deps stayed behind a runtime require() inside register().

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 2705b96. Configure here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not be experimental soon!

Comment thread .size-limit.js
Comment thread packages/server-utils/src/orchestrion/bundler/webpack.ts
Comment thread packages/server-utils/src/orchestrion/runtime/register.ts
Comment thread packages/server-utils/src/orchestrion/runtime/register.ts

@isaacs isaacs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing I'd gate on is the license banner preservation, to stay on the right side of the MIT/ISC/Apache/BSD code this bundles.

But, I think it's absolutely the right way to go, and overall works as expected.

(denoVersion[0] ?? 0) > 2 ||
(denoVersion[0] === 2 && (denoVersion[1] ?? 0) >= 8)
);
if (denoVersionString) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the deno test is still necessary, since our minimum Deno version is going to be 2.8.2 in v11?

Comment on lines +59 to +61
const sanitizedFileNames = info =>
`${info.name.replace(/^packages\/server-utils\/src\//, '').replace(/node_modules/g, 'vendored')}.js`;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're vendoring these, we're going to need to ensure that the license headers don't get dropped. Checking that now locally...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, looks like our build strips those headers, which is a compliance gap. So, we're going to need to fold those up into either an inline banner in the bundled code, or a notice in our license that we're shipping MIT, BSD, Apache 2, and ISC code, along with the relevant copyright headers.

I think there's a plugin that does this? rollup-plugin-license maybe?

Comment on lines +31 to +36
// `strictRequires: false`: the default `'auto'` wraps conditionally-required modules (e.g.
// `debug`'s browser/node split) in lazy initializers exported as `__require` — an export name that
// downstream re-bundlers mishandle (Turbopack renames it, producing `.require is not a function`
// crashes in Next.js on Cloudflare). Hoisting is safe here: the vendored graph is closed (nothing
// optional/missing) and has no require cycles that depend on lazy evaluation.
const commonJSOptions = { transformMixedEsModules: true, requireReturnsDefault: 'auto', strictRequires: false };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(low/safety) It'd be good to have a smoke test that verifies this, if only to prevent us from upgrading and breaking something down the road, if meriyah or apm-js-collab stuff ever violates that assumption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants