From 4cb35127e5c3d4bf2863f65351b27635ba9daaf9 Mon Sep 17 00:00:00 2001 From: JPeer264 Date: Tue, 27 Oct 2026 10:34:22 -0600 Subject: [PATCH 1/2] fix(server-utils): Fix orchestrion source maps of instrumented modules `@apm-js-collab/code-transformer-bundler-plugins` 0.7.4 gave the combined input source map to the code transformer once `outputOptions` had run, and Rolldown calls `outputOptions` before the transforms. The transformer then added a second source `/` (for example `ioredis/built/Redis.js`) without `sourcesContent`. That file does not exist, so source map flattening (for example in `@sentry/sveltekit`) failed for the whole chunk. 0.7.5 gives the real file path to the transformer (code-transformer 0.19.0) and no longer gives it the input map, so the map of an instrumented module only names its file in `node_modules`. This also fixes the source name of instrumented modules in webpack. Co-Authored-By: Claude Opus 5.5 --- packages/server-utils/package.json | 2 +- .../src/orchestrion/bundler/webpack.ts | 7 ++- .../test/orchestrion/config.test.ts | 2 +- .../test/orchestrion/sourcemap.test.ts | 59 +++++++++++++++++++ pnpm-lock.yaml | 25 ++++++-- 5 files changed, 85 insertions(+), 10 deletions(-) create mode 100644 packages/server-utils/test/orchestrion/sourcemap.test.ts diff --git a/packages/server-utils/package.json b/packages/server-utils/package.json index 64bca0f41e4d..0b0307509a36 100644 --- a/packages/server-utils/package.json +++ b/packages/server-utils/package.json @@ -101,7 +101,7 @@ "@sentry/core": "11.10.0" }, "devDependencies": { - "@apm-js-collab/code-transformer-bundler-plugins": "^0.7.4", + "@apm-js-collab/code-transformer-bundler-plugins": "^0.7.5", "@neondatabase/serverless": "1.2.0", "@sentry-internal/rollup-utils": "11.10.0", "@types/node": "^20.19.0", diff --git a/packages/server-utils/src/orchestrion/bundler/webpack.ts b/packages/server-utils/src/orchestrion/bundler/webpack.ts index 4aed6df60460..dec13a661026 100644 --- a/packages/server-utils/src/orchestrion/bundler/webpack.ts +++ b/packages/server-utils/src/orchestrion/bundler/webpack.ts @@ -16,8 +16,11 @@ import { externalEntryMatchesModule, externalizedModulesWarning, orchestrionTran // Explicitly annotated with the vendored types so the emitted declaration doesn't reference // `@apm-js-collab/code-transformer-bundler-plugins` — a bundled devDependency consumers don't have. -export const serializeInstrumentations: (configs: AnyInstrumentationConfig[]) => SerializableInstrumentationConfig[] = - serializeInstrumentationsImpl; +// Upstream also allows a function in `transform`. The vendored configs only allow a string there, +// and the serializer copies `transform` unchanged, so its output only contains strings too. +export const serializeInstrumentations = serializeInstrumentationsImpl as ( + configs: AnyInstrumentationConfig[], +) => SerializableInstrumentationConfig[]; export type { SerializableInstrumentationConfig } from '../apmTypes'; export { getOrchestrionLoaderPath, resolveOrchestrionRuntimeRequest }; diff --git a/packages/server-utils/test/orchestrion/config.test.ts b/packages/server-utils/test/orchestrion/config.test.ts index 3d9a76415b9c..0385405c1573 100644 --- a/packages/server-utils/test/orchestrion/config.test.ts +++ b/packages/server-utils/test/orchestrion/config.test.ts @@ -1,4 +1,4 @@ -import type { InstrumentationConfig } from '@apm-js-collab/code-transformer-bundler-plugins/core'; +import type { InstrumentationConfig } from '../../src/orchestrion/apmTypes'; import { describe, expect, it } from 'vitest'; import { getInstrumentedModuleNames, diff --git a/packages/server-utils/test/orchestrion/sourcemap.test.ts b/packages/server-utils/test/orchestrion/sourcemap.test.ts new file mode 100644 index 000000000000..6b9a2d738994 --- /dev/null +++ b/packages/server-utils/test/orchestrion/sourcemap.test.ts @@ -0,0 +1,59 @@ +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { build, type Plugin, type Rollup } from 'vite'; +import { afterAll, beforeAll, describe, expect, it } from 'vitest'; +import type { InstrumentationConfig } from '../../src/orchestrion/apmTypes'; +import { sentryOrchestrionPlugin as sentryOrchestrionRollupPlugin } from '../../src/orchestrion/bundler/rollup'; +import { sentryOrchestrionPlugin as sentryOrchestrionVitePlugin } from '../../src/orchestrion/bundler/vite'; + +const instrumentations: InstrumentationConfig[] = [ + { + channelName: 'query', + module: { name: 'fake-db', versionRange: '>=1.0.0', filePath: 'index.js' }, + functionQuery: { expressionName: 'query', kind: 'Sync' }, + }, +]; + +describe('orchestrion bundler plugins source maps', () => { + let root: string; + + beforeAll(() => { + root = mkdtempSync(join(tmpdir(), 'orchestrion-sourcemap-')); + const packageDir = join(root, 'node_modules', 'fake-db'); + mkdirSync(packageDir, { recursive: true }); + writeFileSync(join(packageDir, 'package.json'), JSON.stringify({ name: 'fake-db', version: '1.0.0' })); + writeFileSync(join(packageDir, 'index.js'), 'exports.query = function query(sql) {\n return sql;\n};\n'); + writeFileSync( + join(root, 'server.js'), + "import { query } from 'fake-db';\nexport const run = () => query('SELECT 1');\n", + ); + }); + + afterAll(() => rmSync(root, { recursive: true, force: true })); + + // https://github.com/getsentry/sentry-javascript/issues/25329 + it.each([ + ['vite', () => sentryOrchestrionVitePlugin({ instrumentations })], + ['rollup', () => sentryOrchestrionRollupPlugin({ instrumentations }) as Plugin], + ])('maps the transformed module only to its file in node_modules (%s plugin)', async (_name, createPlugin) => { + const output = (await build({ + root, + configFile: false, + logLevel: 'silent', + plugins: [createPlugin()], + ssr: { noExternal: ['fake-db'] }, + build: { + ssr: 'server.js', + sourcemap: true, + write: false, + rollupOptions: { external: ['@sentry/server-utils'] }, + }, + })) as Rollup.RollupOutput; + + const chunk = output.output[0]; + + expect(chunk.code).toContain('orchestrion:fake-db:query'); + expect(chunk.map?.sources).toEqual(['../node_modules/fake-db/index.js', '../server.js']); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d8ed6712cf3a..b3d0dc17d1e4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2210,8 +2210,8 @@ importers: version: link:../core devDependencies: '@apm-js-collab/code-transformer-bundler-plugins': - specifier: ^0.7.4 - version: 0.7.4(esbuild@0.28.1)(rollup@4.62.3)(vite@8.3.1(@types/node@20.19.43)(esbuild@0.28.1)(jiti@2.7.0)(less@4.2.0(supports-color@10.0.0))(sass@1.72.0)(stylus@0.59.0(supports-color@10.0.0))(terser@5.51.2)(tsx@4.23.0)(yaml@2.9.0))(webpack@5.112.2(clean-css@5.2.2)(cssnano@7.1.9(postcss@8.5.31))(csso@5.0.5)(esbuild@0.28.1)(html-minifier-terser@6.1.0)(lightningcss@1.33.0)(postcss@8.5.31)(sharp@0.35.5(@types/node@20.19.43))(svgo@4.1.0)(uglify-js@3.13.3)) + specifier: ^0.7.5 + version: 0.7.5(esbuild@0.28.1)(rollup@4.62.3)(vite@8.3.1(@types/node@20.19.43)(esbuild@0.28.1)(jiti@2.7.0)(less@4.2.0(supports-color@10.0.0))(sass@1.72.0)(stylus@0.59.0(supports-color@10.0.0))(terser@5.51.2)(tsx@4.23.0)(yaml@2.9.0))(webpack@5.112.2(clean-css@5.2.2)(cssnano@7.1.9(postcss@8.5.31))(csso@5.0.5)(esbuild@0.28.1)(html-minifier-terser@6.1.0)(lightningcss@1.33.0)(postcss@8.5.31)(sharp@0.35.5(@types/node@20.19.43))(svgo@4.1.0)(uglify-js@3.13.3)) '@neondatabase/serverless': specifier: 1.2.0 version: 1.2.0 @@ -2788,8 +2788,8 @@ packages: zod: optional: true - '@apm-js-collab/code-transformer-bundler-plugins@0.7.4': - resolution: {integrity: sha512-nAfOeZPSUAQvJa1iFT/5oCrTm5YQhMMrfCNthNnaXHZiOQhu1KGuLoIx7HtbAi3wfwaBYLaICPIeenIaEwcXIg==} + '@apm-js-collab/code-transformer-bundler-plugins@0.7.5': + resolution: {integrity: sha512-/nmTAee5mBly9QiIQSGIKITv9TcEyLTQJFbYjfyWCEfYofxQgurMrT5fLDIRneSPqICucRTxgPMHmc6/q7cgfw==} engines: {node: '>=18.0.0'} peerDependencies: esbuild: '*' @@ -2810,6 +2810,10 @@ packages: resolution: {integrity: sha512-u1Hb6bHjWtkSpiprwVP6YaHC1DTN4RAU3zYkUDUe7WMnJwdyU1pwTL9dFKiSJB9IiLue/EQovmyx6xhU7FFtAQ==} hasBin: true + '@apm-js-collab/code-transformer@0.19.0': + resolution: {integrity: sha512-KGR8dyF4L5dIbnfW2a7n3WQiUxIvR+Zs5IPVXJKNL6XVR9oWR9lm6N/AQXtnimiUDiURlwrZOIlpbGgQ3hU6yQ==} + hasBin: true + '@apm-js-collab/tracing-hooks@0.13.3': resolution: {integrity: sha512-l/ScKzA7sg1hZKc3QMtbnA3blVkTteN3Yq97AejfFrEiR0S0lay3KmyJJ44p45EEVIGP85fLfki4a6OD/7Jb8w==} @@ -20027,9 +20031,9 @@ snapshots: optionalDependencies: zod: 4.6.7 - '@apm-js-collab/code-transformer-bundler-plugins@0.7.4(esbuild@0.28.1)(rollup@4.62.3)(vite@8.3.1(@types/node@20.19.43)(esbuild@0.28.1)(jiti@2.7.0)(less@4.2.0(supports-color@10.0.0))(sass@1.72.0)(stylus@0.59.0(supports-color@10.0.0))(terser@5.51.2)(tsx@4.23.0)(yaml@2.9.0))(webpack@5.112.2(clean-css@5.2.2)(cssnano@7.1.9(postcss@8.5.31))(csso@5.0.5)(esbuild@0.28.1)(html-minifier-terser@6.1.0)(lightningcss@1.33.0)(postcss@8.5.31)(sharp@0.35.5(@types/node@20.19.43))(svgo@4.1.0)(uglify-js@3.13.3))': + '@apm-js-collab/code-transformer-bundler-plugins@0.7.5(esbuild@0.28.1)(rollup@4.62.3)(vite@8.3.1(@types/node@20.19.43)(esbuild@0.28.1)(jiti@2.7.0)(less@4.2.0(supports-color@10.0.0))(sass@1.72.0)(stylus@0.59.0(supports-color@10.0.0))(terser@5.51.2)(tsx@4.23.0)(yaml@2.9.0))(webpack@5.112.2(clean-css@5.2.2)(cssnano@7.1.9(postcss@8.5.31))(csso@5.0.5)(esbuild@0.28.1)(html-minifier-terser@6.1.0)(lightningcss@1.33.0)(postcss@8.5.31)(sharp@0.35.5(@types/node@20.19.43))(svgo@4.1.0)(uglify-js@3.13.3))': dependencies: - '@apm-js-collab/code-transformer': 0.18.1 + '@apm-js-collab/code-transformer': 0.19.0 es-module-lexer: 2.1.0 magic-string: 0.30.21 module-details-from-path: 1.0.4 @@ -20048,6 +20052,15 @@ snapshots: semifies: 1.0.0 source-map: 0.6.1 + '@apm-js-collab/code-transformer@0.19.0': + dependencies: + '@types/estree': 1.0.9 + astring: 1.9.0 + esquery: 1.7.0 + meriyah: 6.1.4 + semifies: 1.0.0 + source-map: 0.6.1 + '@apm-js-collab/tracing-hooks@0.13.3(supports-color@7.2.0)': dependencies: '@apm-js-collab/code-transformer': 0.18.1 From 01cce50922d4e91005c24869e2082928513eb45b Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Thu, 29 Oct 2026 16:54:13 +0100 Subject: [PATCH 2/2] chore(server-runtime-injection): Bump @apm-js-collab/code-transformer and tracing-hooks Aligns @apm-js-collab/code-transformer on 0.19.0 so only one version is installed. Co-Authored-By: Claude Opus 5.5 --- .../server-runtime-injection/package.json | 4 +-- pnpm-lock.yaml | 29 +++++-------------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/packages/server-runtime-injection/package.json b/packages/server-runtime-injection/package.json index b6285ac2060a..7fbbce3d0db6 100644 --- a/packages/server-runtime-injection/package.json +++ b/packages/server-runtime-injection/package.json @@ -49,8 +49,8 @@ "@sentry/server-utils": "11.10.0" }, "devDependencies": { - "@apm-js-collab/code-transformer": "^0.18.1", - "@apm-js-collab/tracing-hooks": "^0.13.3", + "@apm-js-collab/code-transformer": "^0.19.0", + "@apm-js-collab/tracing-hooks": "^0.14.0", "@sentry-internal/rollup-utils": "11.10.0", "@types/node": "^20.19.0", "@vercel/nft": "^1.11.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b3d0dc17d1e4..e197899faf36 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2176,11 +2176,11 @@ importers: version: link:../server-utils devDependencies: '@apm-js-collab/code-transformer': - specifier: ^0.18.1 - version: 0.18.1 + specifier: ^0.19.0 + version: 0.19.0 '@apm-js-collab/tracing-hooks': - specifier: ^0.13.3 - version: 0.13.3(supports-color@7.2.0) + specifier: ^0.14.0 + version: 0.14.0(supports-color@7.2.0) '@sentry-internal/rollup-utils': specifier: 11.10.0 version: link:../../dev-packages/rollup-utils @@ -2806,16 +2806,12 @@ packages: webpack: optional: true - '@apm-js-collab/code-transformer@0.18.1': - resolution: {integrity: sha512-u1Hb6bHjWtkSpiprwVP6YaHC1DTN4RAU3zYkUDUe7WMnJwdyU1pwTL9dFKiSJB9IiLue/EQovmyx6xhU7FFtAQ==} - hasBin: true - '@apm-js-collab/code-transformer@0.19.0': resolution: {integrity: sha512-KGR8dyF4L5dIbnfW2a7n3WQiUxIvR+Zs5IPVXJKNL6XVR9oWR9lm6N/AQXtnimiUDiURlwrZOIlpbGgQ3hU6yQ==} hasBin: true - '@apm-js-collab/tracing-hooks@0.13.3': - resolution: {integrity: sha512-l/ScKzA7sg1hZKc3QMtbnA3blVkTteN3Yq97AejfFrEiR0S0lay3KmyJJ44p45EEVIGP85fLfki4a6OD/7Jb8w==} + '@apm-js-collab/tracing-hooks@0.14.0': + resolution: {integrity: sha512-6QM7NohS/sfIsPDjK/0BlJ00I90VZrGUEA+bhEL3Ul/BoUWCBLfr9oCEcQYPhVZBDPfno5sSjMK8pFpno5gddQ==} '@apollo/cache-control-types@1.0.3': resolution: {integrity: sha512-F17/vCp7QVwom9eG7ToauIKdAxpSoadsJnqIfyryLFSkLSOEqu+eC5Z3N8OXcUVStuOMcNHlyraRsA6rRICu4g==} @@ -20043,15 +20039,6 @@ snapshots: vite: 8.3.1(@types/node@20.19.43)(esbuild@0.28.1)(jiti@2.7.0)(less@4.2.0(supports-color@10.0.0))(sass@1.72.0)(stylus@0.59.0(supports-color@10.0.0))(terser@5.51.2)(tsx@4.23.0)(yaml@2.9.0) webpack: 5.112.2(clean-css@5.2.2)(cssnano@7.1.9(postcss@8.5.31))(csso@5.0.5)(esbuild@0.28.1)(html-minifier-terser@6.1.0)(lightningcss@1.33.0)(postcss@8.5.31)(sharp@0.35.5(@types/node@20.19.43))(svgo@4.1.0)(uglify-js@3.13.3) - '@apm-js-collab/code-transformer@0.18.1': - dependencies: - '@types/estree': 1.0.9 - astring: 1.9.0 - esquery: 1.7.0 - meriyah: 6.1.4 - semifies: 1.0.0 - source-map: 0.6.1 - '@apm-js-collab/code-transformer@0.19.0': dependencies: '@types/estree': 1.0.9 @@ -20061,9 +20048,9 @@ snapshots: semifies: 1.0.0 source-map: 0.6.1 - '@apm-js-collab/tracing-hooks@0.13.3(supports-color@7.2.0)': + '@apm-js-collab/tracing-hooks@0.14.0(supports-color@7.2.0)': dependencies: - '@apm-js-collab/code-transformer': 0.18.1 + '@apm-js-collab/code-transformer': 0.19.0 debug: 4.4.3(supports-color@7.2.0) module-details-from-path: 1.0.4 transitivePeerDependencies: