Skip to content

Commit 34eb8bc

Browse files
authored
feat: Remove support for initialising via --require (#22513)
1 parent d177054 commit 34eb8bc

25 files changed

Lines changed: 226 additions & 73 deletions

File tree

MIGRATION.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,24 @@ Affected SDKs: `@sentry/node` and all dependents.
9797

9898
The new channel-based instrumentations (using `orchestrion` instead of `import-in-the-middle`) are now the default. They were available opt-in in v10. This unlocks instrumenting at run and build time, which enables instrumentation at deployment targets like Vercel and Netlify, as well as using instrumentations on non-Node runtimes like Cloudflare, Bun and Deno. For most users this requires no changes.
9999

100+
### Initializing via `--require` is no longer supported
101+
102+
Affected SDKs: `@sentry/node` and all dependents.
103+
104+
Node re-runs `--require` preloads on the internal module loader thread it spawns for `Module.register()` — which the SDK triggers itself when it installs its instrumentation hooks. A `--require`d instrument file therefore ran `Sentry.init()` a second time, on a thread that never executes any of your code. The SDK now skips initialization on that thread and warns when it detects that it was loaded through `--require`.
105+
106+
Use [`--import`](https://nodejs.org/api/cli.html#--importmodule) instead. It is not re-run on the loader thread, and it works for CommonJS apps too — the instrument file's extension (`.cjs`, or `.js` in a package without `"type": "module"`) is what decides that it loads as CommonJS:
107+
108+
```bash
109+
# Before
110+
node --require ./instrument.js app.js
111+
112+
# After
113+
node --import ./instrument.js app.js
114+
```
115+
116+
The same applies to the no-code entry points, e.g. `node --import=@sentry/node/init app.js` and `node --import @sentry/node/preload app.js`.
117+
100118
### Span streaming is now the default
101119

102120
Affected SDKs: All SDKs.

dev-packages/e2e-tests/test-applications/create-remix-app-v2-non-vite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"scripts": {
55
"build": "remix build",
66
"dev": "remix dev",
7-
"start": "NODE_OPTIONS='--require=./instrument.server.cjs' remix-serve build/index.js",
7+
"start": "NODE_OPTIONS='--import=./instrument.server.cjs' remix-serve build/index.js",
88
"typecheck": "tsc",
99
"clean": "npx rimraf node_modules pnpm-lock.yaml",
1010
"test:build": "pnpm install && npx playwright install && pnpm build",

dev-packages/e2e-tests/test-applications/create-remix-app-v2/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"build": "remix vite:build && pnpm typecheck",
77
"dev": "remix vite:dev",
8-
"start": "NODE_OPTIONS='--require=./instrument.server.cjs' remix-serve build/server/index.js",
8+
"start": "NODE_OPTIONS='--import=./instrument.server.cjs' remix-serve build/server/index.js",
99
"typecheck": "tsc",
1010
"clean": "npx rimraf node_modules pnpm-lock.yaml",
1111
"test:build": "pnpm install && pnpm build",

dev-packages/e2e-tests/test-applications/create-remix-app-v2/tests/build-injection.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { expect, test } from '@playwright/test';
44

55
// The `db.test.ts` runtime assertions prove orchestrion spans appear, but spans alone
66
// don't prove they came from the BUILD-time transform: if the Vite plugin silently
7-
// failed to load, the deps would stay external and the runtime `--require` hook would
7+
// failed to load, the deps would stay external and the runtime `--import` hook would
88
// inject the channels at runtime instead - the span tests would still pass. These
99
// assertions inspect the built server bundle directly so a broken plugin can't hide
1010
// behind that runtime fallback. Only relevant in the orchestrion variant.

dev-packages/e2e-tests/test-applications/node-express-cjs-preload/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"private": true,
55
"scripts": {
6-
"start": "node --require @sentry/node/preload src/app.js",
6+
"start": "node --import @sentry/node/preload src/app.js",
77
"clean": "npx rimraf node_modules pnpm-lock.yaml",
88
"test:build": "pnpm install",
99
"test:assert": "playwright test"

dev-packages/e2e-tests/test-applications/remix-server-timing/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"scripts": {
55
"build": "remix vite:build && pnpm typecheck",
66
"dev": "remix vite:dev",
7-
"start": "NODE_OPTIONS='--require=./instrument.server.cjs' remix-serve build/server/index.js",
7+
"start": "NODE_OPTIONS='--import=./instrument.server.cjs' remix-serve build/server/index.js",
88
"typecheck": "tsc",
99
"clean": "npx rimraf node_modules pnpm-lock.yaml",
1010
"test:build": "pnpm install && pnpm build",

dev-packages/node-integration-tests/suites/no-code/app.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

dev-packages/node-integration-tests/suites/no-code/test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ describe('no-code init', () => {
1717
cleanupChildProcesses();
1818
});
1919

20-
test('CJS', async () => {
21-
await createRunner(__dirname, 'app.js')
22-
.withFlags('--require=@sentry/node/init')
23-
.withMockSentryServer()
24-
.expect({ event: EVENT })
25-
.start()
26-
.completed();
27-
});
28-
2920
describe('--import', () => {
3021
test('ESM', async () => {
3122
await createRunner(__dirname, 'app.mjs')

dev-packages/node-integration-tests/suites/public-api/LocalVariables/local-variables-instrument.js renamed to dev-packages/node-integration-tests/suites/public-api/LocalVariables/local-variables-instrument.cjs

File renamed without changes.

dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ module.exports = { out_of_app_function };`,
9191
.completed();
9292
});
9393

94-
test('Should include local variables when instrumenting via --require', async () => {
95-
const requirePath = path.resolve(__dirname, 'local-variables-instrument.js');
94+
test('Should include local variables when instrumenting via --import', async () => {
95+
const instrumentPath = path.resolve(__dirname, 'local-variables-instrument.cjs');
9696

9797
await createRunner(__dirname, 'local-variables-no-sentry.js')
98-
.withFlags(`--require=${requirePath}`)
98+
.withFlags(`--import=${instrumentPath}`)
9999
.expect({ event: EXPECTED_LOCAL_VARIABLES_EVENT })
100100
.start()
101101
.completed();

0 commit comments

Comments
 (0)