Skip to content

Commit be7546a

Browse files
committed
Just bundle @sentry/server-utils
1 parent 2234f2d commit be7546a

17 files changed

Lines changed: 132 additions & 345 deletions

File tree

packages/nextjs/src/config/diagnosticsChannelInjection.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,17 @@ import { resolveOrchestrionRuntimeRequest } from '@sentry/server-utils/orchestri
99
export const BUNDLE_SAFE_INSTRUMENTED_PACKAGES = ['ioredis'];
1010

1111
/**
12-
* The orchestrion runtime machinery must stay external — its parser breaks when bundled, which
13-
* silently disables the runtime module hook.
12+
* `@sentry/server-utils` (where `register.ts` and the bundled orchestrion runtime ship) must stay
13+
* external: `register.ts` passes its own `__filename`/`import.meta.url` as the `parentURL` for
14+
* `Module.register('@sentry/server-utils/orchestrion/hook.mjs', …)`, so that self-reference only
15+
* resolves while the code still lives at its real `node_modules` location. Bundled into an app
16+
* server chunk instead, the specifier would have to resolve from the chunk's output location,
17+
* which fails under isolated installs (pnpm) where the package is a transitive dependency.
1418
*
15-
* `@sentry/server-utils` (the package `register.ts` — the code that actually calls into
16-
* `@apm-js-collab/tracing-hooks` — ships in) is included too: if it stays external, its own
17-
* `__filename`/`import.meta.url` keep pointing at their real `node_modules` location, so its
18-
* bare-specifier `require`/`import` of the (also-external) tracing-hooks packages resolve
19-
* correctly. If `@sentry/server-utils` were bundled into an app server chunk instead, its code
20-
* would be relocated away from `node_modules`, and those same specifiers would fail to resolve
21-
* under isolated installs (pnpm).
19+
* (The `@apm-js-collab/*` packages no longer appear here: they are bundled into
20+
* `@sentry/server-utils`' build, so no import of them exists at runtime.)
2221
*/
23-
export const ORCHESTRION_RUNTIME_EXTERNAL_PACKAGES = [
24-
'@apm-js-collab/tracing-hooks',
25-
'@apm-js-collab/code-transformer',
26-
'@sentry/server-utils',
27-
];
22+
export const ORCHESTRION_RUNTIME_EXTERNAL_PACKAGES = ['@sentry/server-utils'];
2823

2924
/** Remove the given packages from a `serverExternalPackages` list. */
3025
export function filterInstrumentedExternals(externals: string[], packagesToBundle: string[]): string[] {
@@ -41,12 +36,12 @@ export function filterInstrumentedExternals(externals: string[], packagesToBundl
4136
* package when its bare specifier also resolves from the project root (`resolveExternal`'s
4237
* base-resolve check in `next/dist/build/handle-externals.js`) — otherwise the
4338
* `require('<bare specifier>')` it emits into the chunk would dangle at runtime, so Next silently
44-
* bundles the package instead. Under isolated installs (pnpm) these packages are transitive
45-
* dependencies that never resolve from the project root, so the whole orchestrion runtime ended up
46-
* compiled into the server chunk, which breaks it twice over: the code-transformer parser doesn't
47-
* survive bundling, and the runtime hook's own bare specifiers can't resolve from the chunk's
48-
* output location. Absolute paths sidestep all of this — webpack emits `require('/abs/path/…')`,
49-
* which loads the real files from `node_modules` no matter where the chunk lives.
39+
* bundles the package instead. Under isolated installs (pnpm) the package is a transitive
40+
* dependency that never resolves from the project root, so the orchestrion runtime ended up
41+
* compiled into the server chunk — breaking the `Module.register` self-reference described on
42+
* {@link ORCHESTRION_RUNTIME_EXTERNAL_PACKAGES}. Absolute paths sidestep all of this — webpack
43+
* emits `require('/abs/path/…')`, which loads the real files from `node_modules` no matter where
44+
* the chunk lives.
5045
*
5146
* Must be placed *before* Next's own externals handler in the `externals` array: webpack calls
5247
* array entries in order and stops at the first one that returns a result.

packages/nextjs/test/config/diagnosticsChannelInjection.test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ describe('getServerExternalPackagesPatch (diagnostics-channel injection)', () =>
3636
expect(externals).toContain('pg');
3737
expect(externals).toContain('pg-pool');
3838
// The orchestrion machinery must be external for the runtime hook to work.
39-
expect(externals).toContain('@apm-js-collab/tracing-hooks');
40-
expect(externals).toContain('@apm-js-collab/code-transformer');
39+
expect(externals).toContain('@sentry/server-utils');
4140
});
4241

4342
it('respects user-provided externals even for bundle-safe packages', () => {
@@ -55,21 +54,22 @@ describe('getServerExternalPackagesPatch (diagnostics-channel injection)', () =>
5554
});
5655

5756
describe('externalizeOrchestrionRuntimePackages', () => {
58-
it.each([
59-
'@sentry/server-utils',
60-
'@sentry/server-utils/orchestrion',
61-
'@sentry/server-utils/orchestrion/register',
62-
'@apm-js-collab/tracing-hooks',
63-
'@apm-js-collab/tracing-hooks/hook-sync.mjs',
64-
'@apm-js-collab/tracing-hooks/lib/diagnostics.js',
65-
'@apm-js-collab/code-transformer',
66-
])('externalizes %s as an absolute-path commonjs require', async request => {
67-
const external = await externalizeOrchestrionRuntimePackages({ request });
68-
69-
expect(external).toMatch(/^commonjs /);
70-
const resolvedPath = external!.slice('commonjs '.length);
71-
expect(isAbsolute(resolvedPath)).toBe(true);
72-
expect(existsSync(resolvedPath)).toBe(true);
57+
it.each(['@sentry/server-utils', '@sentry/server-utils/orchestrion', '@sentry/server-utils/orchestrion/register'])(
58+
'externalizes %s as an absolute-path commonjs require',
59+
async request => {
60+
const external = await externalizeOrchestrionRuntimePackages({ request });
61+
62+
expect(external).toMatch(/^commonjs /);
63+
const resolvedPath = external!.slice('commonjs '.length);
64+
expect(isAbsolute(resolvedPath)).toBe(true);
65+
expect(existsSync(resolvedPath)).toBe(true);
66+
},
67+
);
68+
69+
it('ignores the bundled @apm-js-collab packages — no import of them exists in the dist anymore', async () => {
70+
await expect(
71+
externalizeOrchestrionRuntimePackages({ request: '@apm-js-collab/tracing-hooks' }),
72+
).resolves.toBeUndefined();
7373
});
7474

7575
it('resolves @sentry/server-utils subpaths to the CJS build, since the emitted external is a require()', async () => {

packages/nuxt/src/module.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import type { SentryNuxtModuleOptions } from './common/types';
1313
import { addDynamicImportEntryFileWrapper, addSentryTopImport, addServerConfigToBuild } from './vite/addServerConfig';
1414
import { addDatabaseInstrumentation } from './vite/databaseConfig';
1515
import { addMiddlewareImports, addMiddlewareInstrumentation } from './vite/middlewareConfig';
16-
import { setupModuleSyncTracing } from './vite/moduleSyncTracing';
1716
import { setupOrchestrion } from './vite/orchestrion';
1817
import { setupSourceMaps } from './vite/sourceMaps';
1918
import { addStorageInstrumentation } from './vite/storageConfig';
@@ -86,10 +85,6 @@ export default defineNuxtModule<ModuleOptions>({
8685
const isMinNuxtV4 = nuxtMajor >= 4;
8786

8887
if (serverConfigFile) {
89-
// Deliberately not gated on the orchestrion opt-in: the server SDK's dependency graph reaches
90-
// `module-sync` packages either way, so every traced server build needs this.
91-
setupModuleSyncTracing(nuxt, isNitroV3);
92-
9388
if (moduleOptions._experimental?.useDiagnosticsChannelInjection) {
9489
setupOrchestrion(nuxt);
9590
}

packages/nuxt/src/vite/moduleSyncTracing.ts

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

packages/nuxt/test/vite/moduleSyncTracing.test.ts

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

packages/server-utils/package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,20 @@
5252
"import": "./build/esm/orchestrion/bundler/webpack.js",
5353
"require": "./build/cjs/orchestrion/bundler/webpack.js"
5454
},
55+
"./orchestrion/webpack-loader": {
56+
"import": "./build/esm/orchestrion/bundler/webpack-loader.js",
57+
"require": "./build/cjs/orchestrion/bundler/webpack-loader.js"
58+
},
5559
"./orchestrion/esbuild": {
5660
"types": "./build/types/orchestrion/bundler/esbuild.d.ts",
5761
"import": "./build/esm/orchestrion/bundler/esbuild.js",
5862
"require": "./build/cjs/orchestrion/bundler/esbuild.js"
5963
},
6064
"./orchestrion/import-hook": {
6165
"import": "./build/orchestrion/import-hook.mjs"
66+
},
67+
"./orchestrion/hook": {
68+
"import": "./build/esm/orchestrion/runtime/hook.js"
6269
}
6370
},
6471
"typesVersions": {
@@ -90,14 +97,14 @@
9097
"access": "public"
9198
},
9299
"dependencies": {
93-
"@apm-js-collab/code-transformer-bundler-plugins": "^0.7.1",
94-
"@apm-js-collab/tracing-hooks": "^0.13.0",
95100
"@sentry/conventions": "^0.16.0",
96-
"@sentry/core": "10.67.0",
97-
"meriyah": "^6.1.4"
101+
"@sentry/core": "10.67.0"
98102
},
99103
"devDependencies": {
104+
"@apm-js-collab/code-transformer-bundler-plugins": "^0.7.1",
105+
"@apm-js-collab/tracing-hooks": "^0.13.0",
100106
"@types/node": "^18.19.1",
107+
"meriyah": "^6.1.4",
101108
"vite": "^6.4.3"
102109
},
103110
"scripts": {

0 commit comments

Comments
 (0)